polfan-server-js-client 0.2.68 → 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.
- package/.idea/workspace.xml +20 -13
- package/build/index.cjs.js +16 -15
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/WebSocketChatClient.d.ts +2 -2
- package/package.json +1 -1
- package/src/WebSocketChatClient.ts +16 -15
|
@@ -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
|
|
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
|
@@ -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
|
|
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.
|
|
181
|
-
if (!this.isReady || this.
|
|
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
|
-
|
|
190
|
-
this.
|
|
191
|
-
this.ws.close(
|
|
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.
|
|
198
|
-
clearTimeout(
|
|
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.
|
|
205
|
-
|
|
206
|
-
this.
|
|
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
|
}
|