From a969de2385dd264be2221f73802af406fb22492f Mon Sep 17 00:00:00 2001 From: Rando Luik Date: Tue, 23 Sep 2025 14:01:56 +0300 Subject: [PATCH 1/2] Remember connection status with no subscribers --- .../lib/services/graphql/graphql.service.ts | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/javascript-api/src/lib/services/graphql/graphql.service.ts b/packages/javascript-api/src/lib/services/graphql/graphql.service.ts index 9c6c541e..62052145 100644 --- a/packages/javascript-api/src/lib/services/graphql/graphql.service.ts +++ b/packages/javascript-api/src/lib/services/graphql/graphql.service.ts @@ -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'; @@ -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(); - private nextSubscriptionId: number = 1; + private readonly connectionStatus$ = new BehaviorSubject( + ConnectionStatus.DISCONNECTED, + ); + + private nextSubscriptionId = 1; private subscriptions: Subscription[] = []; - private subscriptionObserverMap: { [id: string]: Observer } = {}; - private subscriptionConnection$: Observable; + + private readonly subscriptionObserverMap: { [id: string]: Observer } = + {}; + + private readonly subscriptionConnection$: Observable; 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; @@ -112,7 +125,6 @@ export class GraphqlService { this.setServer('api.qminder.com'); this.subscriptionConnection$ = this.connectionStatus$.pipe( - startWith(ConnectionStatus.CONNECTING), distinctUntilChanged(), shareReplay(1), ); From f24da883ec65356245fb6199eea3a22119aa5c6a Mon Sep 17 00:00:00 2001 From: Rando Luik Date: Tue, 23 Sep 2025 14:03:34 +0300 Subject: [PATCH 2/2] Add nohup.out to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 427adcfe..45dc18ad 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ build !.yarn/sdks !.yarn/versions .pnp.* +nohup.out