@@ -5,8 +5,14 @@ import {
55 SourceLocation ,
66} from 'graphql' ;
77import WebSocket , { CloseEvent } from 'isomorphic-ws' ;
8- import { Observable , Observer , startWith , Subject } from 'rxjs' ;
9- import { distinctUntilChanged , shareReplay } from 'rxjs/operators' ;
8+ import {
9+ BehaviorSubject ,
10+ distinctUntilChanged ,
11+ Observable ,
12+ Observer ,
13+ shareReplay ,
14+ } from 'rxjs' ;
15+
1016import { ConnectionStatus } from '../../model/connection-status.js' ;
1117import { calculateRandomizedExponentialBackoffTime } from '../../util/randomized-exponential-backoff/randomized-exponential-backoff.js' ;
1218import { sleepMs } from '../../util/sleep-ms/sleep-ms.js' ;
@@ -85,25 +91,32 @@ const CLIENT_SIDE_CLOSE_EVENT = 1000;
8591 * trying to import GraphQLService.
8692 */
8793export class GraphqlService {
88- private logger = new Logger ( 'GraphQL' ) ;
94+ private readonly logger = new Logger ( 'GraphQL' ) ;
8995 private apiServer : string ;
9096
9197 private socket : WebSocket = null ;
9298
9399 private connectionStatus : ConnectionStatus ;
94- private connectionStatus$ = new Subject < ConnectionStatus > ( ) ;
95100
96- private nextSubscriptionId : number = 1 ;
101+ private readonly connectionStatus$ = new BehaviorSubject < ConnectionStatus > (
102+ ConnectionStatus . DISCONNECTED ,
103+ ) ;
104+
105+ private nextSubscriptionId = 1 ;
97106
98107 private subscriptions : Subscription [ ] = [ ] ;
99- private subscriptionObserverMap : { [ id : string ] : Observer < object > } = { } ;
100- private subscriptionConnection$ : Observable < ConnectionStatus > ;
108+
109+ private readonly subscriptionObserverMap : { [ id : string ] : Observer < object > } =
110+ { } ;
111+
112+ private readonly subscriptionConnection$ : Observable < ConnectionStatus > ;
101113 private temporaryApiKeyService : TemporaryApiKeyService | undefined ;
102114
103115 private pongTimeout : any ;
104116 private pingPongInterval : any ;
105- private sendPingWithThisBound = this . sendPing . bind ( this ) ;
106- private handleConnectionDropWithThisBound =
117+ private readonly sendPingWithThisBound = this . sendPing . bind ( this ) ;
118+
119+ private readonly handleConnectionDropWithThisBound =
107120 this . handleConnectionDrop . bind ( this ) ;
108121
109122 private connectionAttemptsCount = 0 ;
@@ -112,7 +125,6 @@ export class GraphqlService {
112125 this . setServer ( 'api.qminder.com' ) ;
113126
114127 this . subscriptionConnection$ = this . connectionStatus$ . pipe (
115- startWith ( ConnectionStatus . CONNECTING ) ,
116128 distinctUntilChanged ( ) ,
117129 shareReplay ( 1 ) ,
118130 ) ;
0 commit comments