@hmcts/ccd-case-ui-toolkit 7.3.53-exui-2906-activity-tracker-13 → 7.3.53-exui-2906-activity-tracker-14

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.
@@ -2264,7 +2264,8 @@ class ActivityComponent {
2264
2264
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(ActivityComponent, { className: "ActivityComponent", filePath: "lib/shared/components/activity/activity.component.ts", lineNumber: 12 }); })();
2265
2265
 
2266
2266
  const ACTIVITY_SOCKET_SHARED_STATE_KEY = '__ccdActivitySocketSharedState__';
2267
- const ACTIVITY_SOCKET_RECONNECT_DELAY_MS = 1000 * 2;
2267
+ const ACTIVITY_SOCKET_RECONNECT_DELAY_MIN_MS = 1000;
2268
+ const ACTIVITY_SOCKET_RECONNECT_DELAY_MAX_MS = 20000;
2268
2269
  class ActivitySocketService {
2269
2270
  sessionStorageService;
2270
2271
  activityService;
@@ -2549,11 +2550,24 @@ class ActivitySocketService {
2549
2550
  if (socket === state.socket && state.owners.size > 0 && !ActivitySocketService.isSocketActive(socket)) {
2550
2551
  socket.connect();
2551
2552
  }
2552
- }, ACTIVITY_SOCKET_RECONNECT_DELAY_MS);
2553
+ }, ActivitySocketService.getReconnectDelayMs());
2553
2554
  if (ActivitySocketService.isSocketActive(socket)) {
2554
2555
  socket.disconnect();
2555
2556
  }
2556
2557
  }
2558
+ static getReconnectDelayMs() {
2559
+ const delayRange = ACTIVITY_SOCKET_RECONNECT_DELAY_MAX_MS - ACTIVITY_SOCKET_RECONNECT_DELAY_MIN_MS + 1;
2560
+ return ActivitySocketService.getCryptoRandomInt(delayRange) + ACTIVITY_SOCKET_RECONNECT_DELAY_MIN_MS;
2561
+ }
2562
+ // Returns an unbiased crypto-random integer from 0 inclusive to exclusiveMax exclusive.
2563
+ static getCryptoRandomInt(exclusiveMax) {
2564
+ const randomValue = new Uint32Array(1);
2565
+ const maxUnbiasedValue = Math.floor(0x100000000 / exclusiveMax) * exclusiveMax;
2566
+ do {
2567
+ globalThis.crypto.getRandomValues(randomValue);
2568
+ } while (randomValue[0] >= maxUnbiasedValue);
2569
+ return randomValue[0] % exclusiveMax;
2570
+ }
2557
2571
  // Treats connected, connecting, opening, and open sockets as active.
2558
2572
  static isSocketActive(socket) {
2559
2573
  if (!socket) {