@brggroup/share-lib 0.0.86 → 0.0.88

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.
@@ -560,6 +560,11 @@ class SessionManagerService {
560
560
  LEADER_KEY = 'APP_SESSION_LEADER';
561
561
  HEARTBEAT_KEY = 'APP_SESSION_HEARTBEAT';
562
562
  ACTIVITY_KEY = 'APP_LAST_ACTIVITY';
563
+ SESSION_EVENT = 'APP_SESSION_EVENT';
564
+ LOGIN_EVENT = 'APP_LOGIN_EVENT';
565
+ LOGOUT_EVENT = 'APP_LOGOUT_EVENT';
566
+ ACTIVITY_EVENT = 'APP_ACTIVITY_EVENT';
567
+ TOKEN_REFRESH_EVENT = 'APP_TOKEN_REFRESH_EVENT';
563
568
  tabId = crypto.randomUUID();
564
569
  isLeader = false;
565
570
  isRunning = false;
@@ -580,14 +585,14 @@ class SessionManagerService {
580
585
  this.resetIdle();
581
586
  this.electLeader();
582
587
  }
583
- stop() {
584
- this.isRunning = false;
585
- clearTimeout(this.idleTimer);
586
- clearTimeout(this.refreshTimer);
587
- clearInterval(this.heartbeatTimer);
588
- this.channel?.close();
589
- this.channel = null;
590
- }
588
+ // stop() {
589
+ // this.isRunning = false;
590
+ // clearTimeout(this.idleTimer);
591
+ // clearTimeout(this.refreshTimer);
592
+ // clearInterval(this.heartbeatTimer);
593
+ // this.channel?.close();
594
+ // this.channel = null;
595
+ // }
591
596
  /* -------------------------------- ACTIVITY -------------------------------- */
592
597
  listenActivity() {
593
598
  const events = ['mousemove', 'keydown', 'click', 'scroll'];
@@ -600,7 +605,7 @@ class SessionManagerService {
600
605
  return;
601
606
  this.updateActivity();
602
607
  this.resetIdle();
603
- this.broadcast('activity');
608
+ this.broadcast(this.ACTIVITY_EVENT);
604
609
  }, 1000);
605
610
  updateActivity() {
606
611
  localStorage.setItem(this.ACTIVITY_KEY, Date.now().toString());
@@ -675,7 +680,7 @@ class SessionManagerService {
675
680
  try {
676
681
  const res = await this.handlers.refreshToken();
677
682
  if (res?.IsSuccess) {
678
- this.broadcast('token-refresh');
683
+ this.broadcast(this.TOKEN_REFRESH_EVENT);
679
684
  this.scheduleRefresh();
680
685
  }
681
686
  else {
@@ -697,13 +702,19 @@ class SessionManagerService {
697
702
  if (!this.isRunning)
698
703
  return;
699
704
  const type = msg.data?.type;
700
- if (type === 'activity') {
705
+ if (type === this.ACTIVITY_EVENT) {
701
706
  this.resetIdle();
702
707
  }
703
- if (type === 'logout') {
708
+ if (type === this.LOGOUT_EVENT) {
709
+ console.log('APP_SESSION CHANNEL: ', this.LOGOUT_EVENT);
704
710
  this.handlers.logout();
705
711
  }
706
- if (type === 'token-refresh') {
712
+ if (type === this.LOGIN_EVENT) {
713
+ console.log('APP_SESSION CHANNEL: ', this.LOGIN_EVENT);
714
+ location.reload();
715
+ }
716
+ if (type === this.TOKEN_REFRESH_EVENT) {
717
+ console.log('APP_SESSION CHANNEL: ', this.TOKEN_REFRESH_EVENT);
707
718
  this.scheduleRefresh();
708
719
  }
709
720
  };
@@ -715,15 +726,21 @@ class SessionManagerService {
715
726
  this.channel.postMessage({ type });
716
727
  }
717
728
  else {
718
- localStorage.setItem('APP_SESSION_EVENT', JSON.stringify({ type, t: Date.now() }));
729
+ localStorage.setItem(this.SESSION_EVENT, JSON.stringify({ type, t: Date.now() }));
719
730
  }
720
731
  }
732
+ broadcastLogin() {
733
+ this.broadcast(this.LOGIN_EVENT);
734
+ }
735
+ broadcastLogout() {
736
+ this.broadcast(this.LOGOUT_EVENT);
737
+ }
721
738
  /* -------------------------------- LOGOUT -------------------------------- */
722
739
  logout() {
723
740
  if (!this.isRunning)
724
741
  return;
725
- this.broadcast('logout');
726
742
  this.handlers.logout();
743
+ this.broadcast(this.LOGOUT_EVENT);
727
744
  }
728
745
  /* -------------------------------- UTILS -------------------------------- */
729
746
  debounce(fn, delay) {
@@ -812,6 +829,7 @@ class AuthService extends HTTPService {
812
829
  logout: () => this.signOut(),
813
830
  getToken: () => this.getToken(),
814
831
  });
832
+ this.sessionManager.broadcastLogin();
815
833
  if (returnUrl) {
816
834
  this.router.navigateByUrl(returnUrl);
817
835
  }
@@ -845,7 +863,8 @@ class AuthService extends HTTPService {
845
863
  ---------------------------------------- */
846
864
  signOut() {
847
865
  TokenStorage.clearToken();
848
- this.sessionManager.stop();
866
+ this.sessionManager.broadcastLogout();
867
+ // this.sessionManager.stop();
849
868
  const currentUrl = this.router.routerState.snapshot.url;
850
869
  this.router.navigate(['/login'], {
851
870
  queryParams: { returnUrl: currentUrl || '/' },