@hmcts/ccd-case-ui-toolkit 7.3.68-exui-2906-activity-tracker-18 → 7.3.68-exui-2906-activity-tracker-19

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.
@@ -2459,6 +2459,7 @@ class ActivitySocketService {
2459
2459
  socketConnectSubscription;
2460
2460
  socketConnectErrorSubscription;
2461
2461
  socketDisconnectSubscription;
2462
+ modeSubscription;
2462
2463
  socket;
2463
2464
  pUser;
2464
2465
  get user() {
@@ -2472,7 +2473,7 @@ class ActivitySocketService {
2472
2473
  this.sessionStorageService = sessionStorageService;
2473
2474
  this.activityService = activityService;
2474
2475
  this.activity = this.activitySubject.asObservable();
2475
- this.activityService.modeSubject
2476
+ this.modeSubscription = this.activityService.modeSubject
2476
2477
  .pipe(filter(mode => !!mode))
2477
2478
  .pipe(distinctUntilChanged())
2478
2479
  .subscribe(mode => {
@@ -2482,6 +2483,11 @@ class ActivitySocketService {
2482
2483
  }
2483
2484
  });
2484
2485
  }
2486
+ ngOnDestroy() {
2487
+ this.modeSubscription?.unsubscribe();
2488
+ this.modeSubscription = undefined;
2489
+ this.destroy();
2490
+ }
2485
2491
  // Subscribes the socket to activity updates for the supplied case IDs.
2486
2492
  watchCases(caseIds) {
2487
2493
  if (this.socket) {
@@ -2653,14 +2659,14 @@ class ActivitySocketService {
2653
2659
  this.socketDisconnectSubscription?.unsubscribe();
2654
2660
  this.socketDisconnectSubscription = undefined;
2655
2661
  }
2656
- // Reuses the active shared socket or creates a new socket when none is active.
2662
+ // Reuses the active or already-owned shared socket, otherwise creates a new one.
2657
2663
  static getSharedSocket(user, allowWebSockets) {
2658
2664
  const state = ActivitySocketService.sharedState;
2659
2665
  const userKey = JSON.stringify(user || {});
2660
2666
  if (state.socket &&
2661
2667
  state.userKey === userKey &&
2662
2668
  state.allowWebSockets === allowWebSockets &&
2663
- (ActivitySocketService.isSocketActive(state.socket) || !!state.reconnectTimer || !!state.connectRequested)) {
2669
+ ActivitySocketService.shouldReuseSharedSocket(state)) {
2664
2670
  return state.socket;
2665
2671
  }
2666
2672
  ActivitySocketService.closeSharedSocket(state.socket);
@@ -2669,6 +2675,13 @@ class ActivitySocketService {
2669
2675
  state.userKey = userKey;
2670
2676
  return state.socket;
2671
2677
  }
2678
+ static shouldReuseSharedSocket(state) {
2679
+ return ActivitySocketService.isSocketActive(state.socket) ||
2680
+ !!state.reconnectTimer ||
2681
+ !!state.connectRequested ||
2682
+ !!state.closeTimer ||
2683
+ state.owners.size > 0;
2684
+ }
2672
2685
  // Stores shared socket state on globalThis so multiple service instances use one socket.
2673
2686
  static get sharedState() {
2674
2687
  const globalScope = globalThis;