@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.
- package/esm2020/lib/account-manager.service.mjs +2 -2
- package/esm2020/lib/socket-manager.service.mjs +8 -4
- package/esm2020/lib/socket.service.mjs +20 -6
- package/esm2020/lib/token-manager.service.mjs +4 -2
- package/fesm2015/resolveio-client-lib-core.mjs +47 -29
- package/fesm2015/resolveio-client-lib-core.mjs.map +1 -1
- package/fesm2020/resolveio-client-lib-core.mjs +47 -29
- package/fesm2020/resolveio-client-lib-core.mjs.map +1 -1
- package/lib/socket-manager.service.d.ts +3 -1
- package/lib/socket.service.d.ts +2 -0
- package/package.json +1 -1
|
@@ -299,6 +299,7 @@ class SocketService {
|
|
|
299
299
|
this.onconnecting = function () { };
|
|
300
300
|
this.onmessage = function (event) { };
|
|
301
301
|
this.onerror = function (event) { };
|
|
302
|
+
document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
|
|
302
303
|
}
|
|
303
304
|
openSocket(environment, protocols) {
|
|
304
305
|
this.url = environment.WS_URL;
|
|
@@ -383,13 +384,16 @@ class SocketService {
|
|
|
383
384
|
}
|
|
384
385
|
startPinging() {
|
|
385
386
|
this.pingInterval = setInterval(() => {
|
|
386
|
-
if (this.
|
|
387
|
+
if (this.isWebSocketActive()) {
|
|
387
388
|
this.send('ping');
|
|
388
389
|
this.pongTimeout = setTimeout(() => {
|
|
389
390
|
this.log(new Date(), 'WS', 'pong not received, closing connection');
|
|
390
391
|
this.close();
|
|
391
392
|
}, this.pongTimeoutTime);
|
|
392
393
|
}
|
|
394
|
+
else {
|
|
395
|
+
this.reconnect();
|
|
396
|
+
}
|
|
393
397
|
}, this.pingIntervalTime);
|
|
394
398
|
}
|
|
395
399
|
stopPinging() {
|
|
@@ -438,12 +442,12 @@ class SocketService {
|
|
|
438
442
|
}
|
|
439
443
|
reconnect() {
|
|
440
444
|
this.log(new Date(), 'WS', 'reconnect', this.readyState);
|
|
441
|
-
if (this.readyState === WebSocket.
|
|
442
|
-
this.close();
|
|
443
|
-
}
|
|
444
|
-
else if (this.readyState === WebSocket.CLOSING || this.readyState === WebSocket.CLOSED) {
|
|
445
|
+
if (this.readyState === WebSocket.CLOSED) {
|
|
445
446
|
this.connect();
|
|
446
447
|
}
|
|
448
|
+
else if (this.readyState !== WebSocket.CONNECTING) {
|
|
449
|
+
this.close();
|
|
450
|
+
}
|
|
447
451
|
}
|
|
448
452
|
getBufferAmount() {
|
|
449
453
|
if (this.ws) {
|
|
@@ -458,6 +462,16 @@ class SocketService {
|
|
|
458
462
|
console.log(...args);
|
|
459
463
|
}
|
|
460
464
|
}
|
|
465
|
+
handleVisibilityChange() {
|
|
466
|
+
if (document.visibilityState === 'visible') {
|
|
467
|
+
if (!this.isWebSocketActive()) {
|
|
468
|
+
this.reconnect();
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
isWebSocketActive() {
|
|
473
|
+
return this.ws && this.ws.readyState === WebSocket.OPEN;
|
|
474
|
+
}
|
|
461
475
|
}
|
|
462
476
|
SocketService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketService, deps: [{ token: i1.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
463
477
|
SocketService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketService });
|
|
@@ -1158,12 +1172,35 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
|
|
|
1158
1172
|
type: Injectable
|
|
1159
1173
|
}], ctorParameters: function () { return [{ type: i1$1.ToastrService }]; } });
|
|
1160
1174
|
|
|
1175
|
+
class TokenManagerService {
|
|
1176
|
+
constructor(_storage) {
|
|
1177
|
+
this._storage = _storage;
|
|
1178
|
+
}
|
|
1179
|
+
getToken(tokenKey) {
|
|
1180
|
+
return this._storage.get(tokenKey);
|
|
1181
|
+
}
|
|
1182
|
+
setToken(tokenKey, tokenValue) {
|
|
1183
|
+
this._storage.set(tokenKey, tokenValue);
|
|
1184
|
+
}
|
|
1185
|
+
removeToken(tokenKey) {
|
|
1186
|
+
if (this.getToken(tokenKey) !== null) {
|
|
1187
|
+
this._storage.remove(tokenKey);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
TokenManagerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, deps: [{ token: i1.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1192
|
+
TokenManagerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService });
|
|
1193
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, decorators: [{
|
|
1194
|
+
type: Injectable
|
|
1195
|
+
}], ctorParameters: function () { return [{ type: i1.LocalStorageService }]; } });
|
|
1196
|
+
|
|
1161
1197
|
class SocketManagerService {
|
|
1162
|
-
constructor(_socket, _offline, _alert, _router) {
|
|
1198
|
+
constructor(_socket, _offline, _alert, _router, _token) {
|
|
1163
1199
|
this._socket = _socket;
|
|
1164
1200
|
this._offline = _offline;
|
|
1165
1201
|
this._alert = _alert;
|
|
1166
1202
|
this._router = _router;
|
|
1203
|
+
this._token = _token;
|
|
1167
1204
|
this.messageId = 0;
|
|
1168
1205
|
this._cbArray = [];
|
|
1169
1206
|
this._subArray = [];
|
|
@@ -1295,6 +1332,7 @@ class SocketManagerService {
|
|
|
1295
1332
|
this._socket.openSocket(environment, protocols);
|
|
1296
1333
|
}
|
|
1297
1334
|
closeSocket() {
|
|
1335
|
+
this._token.removeToken('accessToken');
|
|
1298
1336
|
this._socket.close();
|
|
1299
1337
|
}
|
|
1300
1338
|
call(method, ...parameters) {
|
|
@@ -1474,31 +1512,11 @@ class SocketManagerService {
|
|
|
1474
1512
|
return this._socket.readyState$;
|
|
1475
1513
|
}
|
|
1476
1514
|
}
|
|
1477
|
-
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$2.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1515
|
+
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$2.Router }, { token: TokenManagerService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1478
1516
|
SocketManagerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketManagerService });
|
|
1479
1517
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SocketManagerService, decorators: [{
|
|
1480
1518
|
type: Injectable
|
|
1481
|
-
}], ctorParameters: function () { return [{ type: SocketService }, { type: OfflineManagerService }, { type: AlertService }, { type: i1$2.Router }]; } });
|
|
1482
|
-
|
|
1483
|
-
class TokenManagerService {
|
|
1484
|
-
constructor(_storage) {
|
|
1485
|
-
this._storage = _storage;
|
|
1486
|
-
}
|
|
1487
|
-
getToken(tokenKey) {
|
|
1488
|
-
return this._storage.get(tokenKey);
|
|
1489
|
-
}
|
|
1490
|
-
setToken(tokenKey, tokenValue) {
|
|
1491
|
-
this._storage.set(tokenKey, tokenValue);
|
|
1492
|
-
}
|
|
1493
|
-
removeToken(tokenKey) {
|
|
1494
|
-
this._storage.remove(tokenKey);
|
|
1495
|
-
}
|
|
1496
|
-
}
|
|
1497
|
-
TokenManagerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, deps: [{ token: i1.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1498
|
-
TokenManagerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService });
|
|
1499
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TokenManagerService, decorators: [{
|
|
1500
|
-
type: Injectable
|
|
1501
|
-
}], ctorParameters: function () { return [{ type: i1.LocalStorageService }]; } });
|
|
1519
|
+
}], ctorParameters: function () { return [{ type: SocketService }, { type: OfflineManagerService }, { type: AlertService }, { type: i1$2.Router }, { type: TokenManagerService }]; } });
|
|
1502
1520
|
|
|
1503
1521
|
class AccountManagerService {
|
|
1504
1522
|
constructor(_router, _socket, _token, _http, _alert, _offline) {
|
|
@@ -1520,6 +1538,7 @@ class AccountManagerService {
|
|
|
1520
1538
|
if (token) {
|
|
1521
1539
|
this.initLogin(token);
|
|
1522
1540
|
setInterval(() => {
|
|
1541
|
+
token = this._token.getToken('refreshToken');
|
|
1523
1542
|
this.initLogin(token);
|
|
1524
1543
|
}, 3000);
|
|
1525
1544
|
}
|
|
@@ -1623,7 +1642,6 @@ class AccountManagerService {
|
|
|
1623
1642
|
setTimeout(() => {
|
|
1624
1643
|
this.user.next(null);
|
|
1625
1644
|
this._token.removeToken('refreshToken');
|
|
1626
|
-
this._token.removeToken('accessToken');
|
|
1627
1645
|
this._offline.removeUser();
|
|
1628
1646
|
this.closeSocket();
|
|
1629
1647
|
resolve(true);
|