@brggroup/share-lib 0.0.84 → 0.0.85
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.
|
@@ -545,6 +545,7 @@ class TokenStorage {
|
|
|
545
545
|
|
|
546
546
|
class SessionManagerService {
|
|
547
547
|
zone = inject(NgZone);
|
|
548
|
+
isRunning = false;
|
|
548
549
|
idleTimer;
|
|
549
550
|
refreshTimer;
|
|
550
551
|
heartbeatTimer;
|
|
@@ -561,7 +562,7 @@ class SessionManagerService {
|
|
|
561
562
|
handlers;
|
|
562
563
|
/* ---------------- START ---------------- */
|
|
563
564
|
start(handlers) {
|
|
564
|
-
if (this.IDLE_TIME <= 0)
|
|
565
|
+
if (this.IDLE_TIME <= 0 || this.isRunning)
|
|
565
566
|
return;
|
|
566
567
|
this.handlers = handlers;
|
|
567
568
|
this.listenActivity();
|
|
@@ -571,10 +572,13 @@ class SessionManagerService {
|
|
|
571
572
|
this.electLeader();
|
|
572
573
|
}
|
|
573
574
|
stop() {
|
|
575
|
+
this.isRunning = false;
|
|
574
576
|
clearTimeout(this.idleTimer);
|
|
575
577
|
clearTimeout(this.refreshTimer);
|
|
576
578
|
clearInterval(this.heartbeatTimer);
|
|
577
|
-
this.channel
|
|
579
|
+
if (this.channel) {
|
|
580
|
+
this.channel.close();
|
|
581
|
+
}
|
|
578
582
|
}
|
|
579
583
|
/* ---------------- ACTIVITY ---------------- */
|
|
580
584
|
listenActivity() {
|
|
@@ -586,11 +590,16 @@ class SessionManagerService {
|
|
|
586
590
|
onActivity = this.debounce(() => {
|
|
587
591
|
this.updateActivity();
|
|
588
592
|
this.resetIdle();
|
|
589
|
-
this.
|
|
593
|
+
this.broadcast('activity');
|
|
590
594
|
}, 1000);
|
|
591
595
|
updateActivity() {
|
|
592
596
|
localStorage.setItem('APP_LAST_ACTIVITY', Date.now().toString());
|
|
593
597
|
}
|
|
598
|
+
broadcast(type) {
|
|
599
|
+
if (!this.isRunning)
|
|
600
|
+
return;
|
|
601
|
+
this.channel?.postMessage({ type });
|
|
602
|
+
}
|
|
594
603
|
/* ---------------- IDLE ---------------- */
|
|
595
604
|
resetIdle() {
|
|
596
605
|
clearTimeout(this.idleTimer);
|
|
@@ -659,7 +668,7 @@ class SessionManagerService {
|
|
|
659
668
|
try {
|
|
660
669
|
const res = await this.handlers.refreshToken();
|
|
661
670
|
if (res?.IsSuccess) {
|
|
662
|
-
this.
|
|
671
|
+
this.broadcast('token-refresh');
|
|
663
672
|
this.scheduleRefresh();
|
|
664
673
|
}
|
|
665
674
|
else {
|
|
@@ -687,7 +696,7 @@ class SessionManagerService {
|
|
|
687
696
|
}
|
|
688
697
|
/* ---------------- LOGOUT ---------------- */
|
|
689
698
|
logout() {
|
|
690
|
-
this.
|
|
699
|
+
this.broadcast('logout');
|
|
691
700
|
this.handlers.logout();
|
|
692
701
|
}
|
|
693
702
|
/* ---------------- UTILS ---------------- */
|