Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ build
!.yarn/sdks
!.yarn/versions
.pnp.*
nohup.out
32 changes: 22 additions & 10 deletions packages/javascript-api/src/lib/services/graphql/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import {
SourceLocation,
} from 'graphql';
import WebSocket, { CloseEvent } from 'isomorphic-ws';
import { Observable, Observer, startWith, Subject } from 'rxjs';
import { distinctUntilChanged, shareReplay } from 'rxjs/operators';
import {
BehaviorSubject,
distinctUntilChanged,
Observable,
Observer,
shareReplay,
} from 'rxjs';

import { ConnectionStatus } from '../../model/connection-status.js';
import { calculateRandomizedExponentialBackoffTime } from '../../util/randomized-exponential-backoff/randomized-exponential-backoff.js';
import { sleepMs } from '../../util/sleep-ms/sleep-ms.js';
Expand Down Expand Up @@ -85,25 +91,32 @@ const CLIENT_SIDE_CLOSE_EVENT = 1000;
* trying to import GraphQLService.
*/
export class GraphqlService {
private logger = new Logger('GraphQL');
private readonly logger = new Logger('GraphQL');
private apiServer: string;

private socket: WebSocket = null;

private connectionStatus: ConnectionStatus;
private connectionStatus$ = new Subject<ConnectionStatus>();

private nextSubscriptionId: number = 1;
private readonly connectionStatus$ = new BehaviorSubject<ConnectionStatus>(
ConnectionStatus.DISCONNECTED,
);

private nextSubscriptionId = 1;

private subscriptions: Subscription[] = [];
private subscriptionObserverMap: { [id: string]: Observer<object> } = {};
private subscriptionConnection$: Observable<ConnectionStatus>;

private readonly subscriptionObserverMap: { [id: string]: Observer<object> } =
{};

private readonly subscriptionConnection$: Observable<ConnectionStatus>;
private temporaryApiKeyService: TemporaryApiKeyService | undefined;

private pongTimeout: any;
private pingPongInterval: any;
private sendPingWithThisBound = this.sendPing.bind(this);
private handleConnectionDropWithThisBound =
private readonly sendPingWithThisBound = this.sendPing.bind(this);

private readonly handleConnectionDropWithThisBound =
this.handleConnectionDrop.bind(this);

private connectionAttemptsCount = 0;
Expand All @@ -112,7 +125,6 @@ export class GraphqlService {
this.setServer('api.qminder.com');

this.subscriptionConnection$ = this.connectionStatus$.pipe(
startWith(ConnectionStatus.CONNECTING),
distinctUntilChanged(),
shareReplay(1),
);
Expand Down
Loading