@resolveio/client-lib-core 15.1.0 → 15.1.1
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/esm2020/lib/socket.service.mjs +20 -6
- package/fesm2015/resolveio-client-lib-core.mjs +19 -5
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +19 -5
- package/fesm2020/resolveio-client-lib-core.mjs.map +1 -1
- package/lib/socket.service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -232,6 +232,7 @@ class SocketService {
|
|
|
232
232
|
this.onconnecting = function () { };
|
|
233
233
|
this.onmessage = function (event) { };
|
|
234
234
|
this.onerror = function (event) { };
|
|
235
|
+
document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
|
|
235
236
|
}
|
|
236
237
|
openSocket(environment, protocols) {
|
|
237
238
|
this.url = environment.WS_URL;
|
|
@@ -316,13 +317,16 @@ class SocketService {
|
|
|
316
317
|
}
|
|
317
318
|
startPinging() {
|
|
318
319
|
this.pingInterval = setInterval(() => {
|
|
319
|
-
if (this.
|
|
320
|
+
if (this.isWebSocketActive()) {
|
|
320
321
|
this.send('ping');
|
|
321
322
|
this.pongTimeout = setTimeout(() => {
|
|
322
323
|
this.log(new Date(), 'WS', 'pong not received, closing connection');
|
|
323
324
|
this.close();
|
|
324
325
|
}, this.pongTimeoutTime);
|
|
325
326
|
}
|
|
327
|
+
else {
|
|
328
|
+
this.reconnect();
|
|
329
|
+
}
|
|
326
330
|
}, this.pingIntervalTime);
|
|
327
331
|
}
|
|
328
332
|
stopPinging() {
|
|
@@ -371,12 +375,12 @@ class SocketService {
|
|
|
371
375
|
}
|
|
372
376
|
reconnect() {
|
|
373
377
|
this.log(new Date(), 'WS', 'reconnect', this.readyState);
|
|
374
|
-
if (this.readyState === WebSocket.
|
|
375
|
-
this.close();
|
|
376
|
-
}
|
|
377
|
-
else if (this.readyState === WebSocket.CLOSING || this.readyState === WebSocket.CLOSED) {
|
|
378
|
+
if (this.readyState === WebSocket.CLOSED) {
|
|
378
379
|
this.connect();
|
|
379
380
|
}
|
|
381
|
+
else if (this.readyState !== WebSocket.CONNECTING) {
|
|
382
|
+
this.close();
|
|
383
|
+
}
|
|
380
384
|
}
|
|
381
385
|
getBufferAmount() {
|
|
382
386
|
if (this.ws) {
|
|
@@ -391,6 +395,16 @@ class SocketService {
|
|
|
391
395
|
console.log(...args);
|
|
392
396
|
}
|
|
393
397
|
}
|
|
398
|
+
handleVisibilityChange() {
|
|
399
|
+
if (document.visibilityState === 'visible') {
|
|
400
|
+
if (!this.isWebSocketActive()) {
|
|
401
|
+
this.reconnect();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
isWebSocketActive() {
|
|
406
|
+
return this.ws && this.ws.readyState === WebSocket.OPEN;
|
|
407
|
+
}
|
|
394
408
|
}
|
|
395
409
|
SocketService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketService, deps: [{ token: i1$2.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
396
410
|
SocketService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketService });
|