polfan-server-js-client 0.2.69 → 0.2.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,9 +40,9 @@ export declare class WebSocketChatClient extends AbstractChatClient implements O
40
40
  protected connectingTimeoutId: any;
41
41
  protected authenticated: boolean;
42
42
  protected authenticatedResolvers: [() => void, (error: Error) => void];
43
- protected pingIntervalId?: NodeJS.Timeout;
43
+ protected pingMonitorInterval?: NodeJS.Timeout;
44
+ protected inFlightPingTimeout: NodeJS.Timeout;
44
45
  protected lastReceivedMessageAt?: number;
45
- protected pingInFlight: boolean;
46
46
  constructor(options: WebSocketClientOptions);
47
47
  connect(): Promise<void>;
48
48
  disconnect(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.69",
3
+ "version": "0.2.71",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
@@ -42,9 +42,9 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
42
42
  protected connectingTimeoutId: any;
43
43
  protected authenticated: boolean;
44
44
  protected authenticatedResolvers: [() => void, (error: Error) => void];
45
- protected pingIntervalId?: NodeJS.Timeout;
45
+ protected pingMonitorInterval?: NodeJS.Timeout;
46
+ protected inFlightPingTimeout: NodeJS.Timeout;
46
47
  protected lastReceivedMessageAt?: number;
47
- protected pingInFlight: boolean;
48
48
 
49
49
  public constructor(private readonly options: WebSocketClientOptions) {
50
50
  super();
@@ -177,8 +177,8 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
177
177
 
178
178
  this.lastReceivedMessageAt = Date.now();
179
179
 
180
- this.pingIntervalId = setInterval(async () => {
181
- if (!this.isReady || this.pingInFlight) {
180
+ this.pingMonitorInterval = setInterval(async () => {
181
+ if (!this.isReady || this.inFlightPingTimeout) {
182
182
  return;
183
183
  }
184
184
 
@@ -186,25 +186,26 @@ export class WebSocketChatClient extends AbstractChatClient implements Observabl
186
186
  return;
187
187
  }
188
188
 
189
- const timeout = setTimeout(() => {
190
- this.pingInFlight = false;
191
- this.ws.close(1008); // Service Restart (reconnect)
189
+ this.inFlightPingTimeout = setTimeout(() => {
190
+ this.inFlightPingTimeout = undefined;
191
+ this.ws.close(3000); // Service Restart (reconnect)
192
192
  }, this.options.ping.pongBackTimeoutMs);
193
193
 
194
- this.pingInFlight = true;
195
-
196
194
  this.send('Ping', {}).then(() => {
197
- this.pingInFlight = false;
198
- clearTimeout(timeout);
195
+ this.inFlightPingTimeout = undefined;
196
+ clearTimeout(this.inFlightPingTimeout);
199
197
  });
200
198
  }, 1000);
201
199
  }
202
200
 
203
201
  private stopConnectionMonitor(): void {
204
- if (this.pingIntervalId) {
205
- clearInterval(this.pingIntervalId);
206
- this.pingIntervalId = undefined;
202
+ if (this.inFlightPingTimeout) {
203
+ clearTimeout(this.inFlightPingTimeout);
204
+ this.inFlightPingTimeout = undefined;
205
+ }
206
+ if (this.pingMonitorInterval) {
207
+ clearInterval(this.pingMonitorInterval);
208
+ this.pingMonitorInterval = undefined;
207
209
  }
208
- this.pingInFlight = false;
209
210
  }
210
211
  }