@resolveio/client-lib-core 15.0.11 → 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.
@@ -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.ws && this.ws.readyState === WebSocket.OPEN) {
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.OPEN) {
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 });
@@ -1176,12 +1190,35 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1176
1190
  type: Injectable
1177
1191
  }], ctorParameters: function () { return [{ type: i1$2.LocalStorageService }]; } });
1178
1192
 
1193
+ class TokenManagerService {
1194
+ constructor(_storage) {
1195
+ this._storage = _storage;
1196
+ }
1197
+ getToken(tokenKey) {
1198
+ return this._storage.get(tokenKey);
1199
+ }
1200
+ setToken(tokenKey, tokenValue) {
1201
+ this._storage.set(tokenKey, tokenValue);
1202
+ }
1203
+ removeToken(tokenKey) {
1204
+ if (this.getToken(tokenKey) !== null) {
1205
+ this._storage.remove(tokenKey);
1206
+ }
1207
+ }
1208
+ }
1209
+ TokenManagerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, deps: [{ token: i1$2.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
1210
+ TokenManagerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService });
1211
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, decorators: [{
1212
+ type: Injectable
1213
+ }], ctorParameters: function () { return [{ type: i1$2.LocalStorageService }]; } });
1214
+
1179
1215
  class SocketManagerService {
1180
- constructor(_socket, _offline, _alert, _router) {
1216
+ constructor(_socket, _offline, _alert, _router, _token) {
1181
1217
  this._socket = _socket;
1182
1218
  this._offline = _offline;
1183
1219
  this._alert = _alert;
1184
1220
  this._router = _router;
1221
+ this._token = _token;
1185
1222
  this.messageId = 0;
1186
1223
  this._cbArray = [];
1187
1224
  this._subArray = [];
@@ -1313,6 +1350,7 @@ class SocketManagerService {
1313
1350
  this._socket.openSocket(environment, protocols);
1314
1351
  }
1315
1352
  closeSocket() {
1353
+ this._token.removeToken('accessToken');
1316
1354
  this._socket.close();
1317
1355
  }
1318
1356
  call(method, ...parameters) {
@@ -1492,31 +1530,11 @@ class SocketManagerService {
1492
1530
  return this._socket.readyState$;
1493
1531
  }
1494
1532
  }
1495
- SocketManagerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketManagerService, deps: [{ token: SocketService }, { token: OfflineManagerService }, { token: AlertService }, { token: i1$3.Router }], target: i0.ɵɵFactoryTarget.Injectable });
1533
+ SocketManagerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketManagerService, deps: [{ token: SocketService }, { token: OfflineManagerService }, { token: AlertService }, { token: i1$3.Router }, { token: TokenManagerService }], target: i0.ɵɵFactoryTarget.Injectable });
1496
1534
  SocketManagerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketManagerService });
1497
1535
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketManagerService, decorators: [{
1498
1536
  type: Injectable
1499
- }], ctorParameters: function () { return [{ type: SocketService }, { type: OfflineManagerService }, { type: AlertService }, { type: i1$3.Router }]; } });
1500
-
1501
- class TokenManagerService {
1502
- constructor(_storage) {
1503
- this._storage = _storage;
1504
- }
1505
- getToken(tokenKey) {
1506
- return this._storage.get(tokenKey);
1507
- }
1508
- setToken(tokenKey, tokenValue) {
1509
- this._storage.set(tokenKey, tokenValue);
1510
- }
1511
- removeToken(tokenKey) {
1512
- this._storage.remove(tokenKey);
1513
- }
1514
- }
1515
- TokenManagerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, deps: [{ token: i1$2.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
1516
- TokenManagerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService });
1517
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, decorators: [{
1518
- type: Injectable
1519
- }], ctorParameters: function () { return [{ type: i1$2.LocalStorageService }]; } });
1537
+ }], ctorParameters: function () { return [{ type: SocketService }, { type: OfflineManagerService }, { type: AlertService }, { type: i1$3.Router }, { type: TokenManagerService }]; } });
1520
1538
 
1521
1539
  class AccountManagerService {
1522
1540
  constructor(_router, _socket, _token, _http, _alert, _offline) {
@@ -1538,6 +1556,7 @@ class AccountManagerService {
1538
1556
  if (token) {
1539
1557
  this.initLogin(token);
1540
1558
  setInterval(() => {
1559
+ token = this._token.getToken('refreshToken');
1541
1560
  this.initLogin(token);
1542
1561
  }, 3000);
1543
1562
  }
@@ -1641,7 +1660,6 @@ class AccountManagerService {
1641
1660
  setTimeout(() => {
1642
1661
  this.user.next(null);
1643
1662
  this._token.removeToken('refreshToken');
1644
- this._token.removeToken('accessToken');
1645
1663
  this._offline.removeUser();
1646
1664
  this.closeSocket();
1647
1665
  resolve(true);