@hmcts/ccd-case-ui-toolkit 7.3.69-exui-2906-activity-tracker-20 → 7.3.69-exui-2906-activity-tracker-22
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.
|
@@ -1872,9 +1872,11 @@ function isSolicitorUser(sessionStorageService) {
|
|
|
1872
1872
|
const BASE_CONFIGURATION = {
|
|
1873
1873
|
autoConnect: false, // (default is false)
|
|
1874
1874
|
reconnection: true,
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1875
|
+
reconnectionAttempts: Infinity,
|
|
1876
|
+
reconnectionDelay: 1000, // 1 second (default is 1s)
|
|
1877
|
+
reconnectionDelayMax: 1000 * 10, // 10 seconds (default is 5s)
|
|
1878
|
+
randomizationFactor: 0.5,
|
|
1879
|
+
timeout: 1000 * 20 // Connection attempt timeout, not an idle timeout.
|
|
1878
1880
|
};
|
|
1879
1881
|
const TRANSPORTS = {
|
|
1880
1882
|
allowWebSockets: ['websocket'], // No fallback to long polling allowed.
|
|
@@ -1904,8 +1906,7 @@ const UTILS = {
|
|
|
1904
1906
|
return {
|
|
1905
1907
|
...BASE_CONFIGURATION,
|
|
1906
1908
|
...UTILS.getTransports(allowWebSockets),
|
|
1907
|
-
|
|
1908
|
-
query: { user: JSON.stringify(user) }
|
|
1909
|
+
auth: { user }
|
|
1909
1910
|
};
|
|
1910
1911
|
},
|
|
1911
1912
|
getSocket: (user, allowWebSockets = false) => {
|
|
@@ -2439,8 +2440,6 @@ class ActivityComponent {
|
|
|
2439
2440
|
|
|
2440
2441
|
const ACTIVITY_SOCKET_SHARED_STATE_KEY = '__ccdActivitySocketSharedState__';
|
|
2441
2442
|
const ACTIVITY_SOCKET_CLOSE_GRACE_MS = 5000;
|
|
2442
|
-
const ACTIVITY_SOCKET_RECONNECT_DELAY_MIN_MS = 1000;
|
|
2443
|
-
const ACTIVITY_SOCKET_RECONNECT_DELAY_MAX_MS = 20000;
|
|
2444
2443
|
const ACTIVITY_SOCKET_ACTIVE_READY_STATES = new Set(['connecting', 'opening', 'open']);
|
|
2445
2444
|
class ActivitySocketService {
|
|
2446
2445
|
sessionStorageService;
|
|
@@ -2609,16 +2608,13 @@ class ActivitySocketService {
|
|
|
2609
2608
|
this.socketDisconnectSubscription = this.disconnect.subscribe(() => {
|
|
2610
2609
|
ActivitySocketService.clearSharedSocketConnectRequest(socket);
|
|
2611
2610
|
this.connected.next(false);
|
|
2612
|
-
ActivitySocketService.reconnectSharedSocketIfNeeded(socket);
|
|
2613
2611
|
});
|
|
2614
2612
|
this.socketConnectErrorSubscription = this.connect_error.subscribe(() => {
|
|
2615
2613
|
ActivitySocketService.clearSharedSocketConnectRequest(socket);
|
|
2616
2614
|
this.connected.next(false);
|
|
2617
|
-
ActivitySocketService.reconnectSharedSocketIfNeeded(socket);
|
|
2618
2615
|
});
|
|
2619
2616
|
this.socketConnectSubscription = this.connect.subscribe(() => {
|
|
2620
2617
|
ActivitySocketService.clearSharedSocketConnectRequest(socket);
|
|
2621
|
-
ActivitySocketService.clearSharedSocketReconnect(socket);
|
|
2622
2618
|
this.connected.next(true);
|
|
2623
2619
|
});
|
|
2624
2620
|
this.connected.next(socket.connected);
|
|
@@ -2677,7 +2673,6 @@ class ActivitySocketService {
|
|
|
2677
2673
|
}
|
|
2678
2674
|
static shouldReuseSharedSocket(state) {
|
|
2679
2675
|
return ActivitySocketService.isSocketActive(state.socket) ||
|
|
2680
|
-
!!state.reconnectTimer ||
|
|
2681
2676
|
!!state.connectRequested ||
|
|
2682
2677
|
!!state.closeTimer ||
|
|
2683
2678
|
state.owners.size > 0;
|
|
@@ -2731,7 +2726,6 @@ class ActivitySocketService {
|
|
|
2731
2726
|
}
|
|
2732
2727
|
if (socket === state.socket) {
|
|
2733
2728
|
ActivitySocketService.clearSharedSocketCloseTimer(socket);
|
|
2734
|
-
ActivitySocketService.clearSharedSocketReconnect(socket);
|
|
2735
2729
|
ActivitySocketService.clearSharedSocketConnectRequest(socket);
|
|
2736
2730
|
state.socket = undefined;
|
|
2737
2731
|
state.allowWebSockets = undefined;
|
|
@@ -2740,20 +2734,11 @@ class ActivitySocketService {
|
|
|
2740
2734
|
}
|
|
2741
2735
|
socket.close();
|
|
2742
2736
|
}
|
|
2743
|
-
// Cancels a pending reconnect timer for the active shared socket.
|
|
2744
|
-
static clearSharedSocketReconnect(socket) {
|
|
2745
|
-
const state = ActivitySocketService.sharedState;
|
|
2746
|
-
if (socket === state.socket && state.reconnectTimer) {
|
|
2747
|
-
clearTimeout(state.reconnectTimer);
|
|
2748
|
-
state.reconnectTimer = undefined;
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
2737
|
// Starts a shared socket connection only when one is not already active or pending.
|
|
2752
2738
|
static connectSharedSocketIfNeeded(socket) {
|
|
2753
2739
|
const state = ActivitySocketService.sharedState;
|
|
2754
2740
|
if (socket !== state.socket ||
|
|
2755
2741
|
ActivitySocketService.isSocketActive(socket) ||
|
|
2756
|
-
state.reconnectTimer ||
|
|
2757
2742
|
state.connectRequested) {
|
|
2758
2743
|
return;
|
|
2759
2744
|
}
|
|
@@ -2772,38 +2757,6 @@ class ActivitySocketService {
|
|
|
2772
2757
|
state.connectRequested = undefined;
|
|
2773
2758
|
}
|
|
2774
2759
|
}
|
|
2775
|
-
// Schedules one controlled reconnect for websocket mode after a failure event.
|
|
2776
|
-
static reconnectSharedSocketIfNeeded(socket) {
|
|
2777
|
-
const state = ActivitySocketService.sharedState;
|
|
2778
|
-
if (!state.allowWebSockets || socket !== state.socket || state.owners.size === 0 || state.reconnectTimer) {
|
|
2779
|
-
return;
|
|
2780
|
-
}
|
|
2781
|
-
console.warn('Activity socket connection lost, scheduling reconnect...');
|
|
2782
|
-
state.reconnectTimer = setTimeout(() => {
|
|
2783
|
-
state.reconnectTimer = undefined;
|
|
2784
|
-
if (socket === state.socket && state.owners.size > 0 && !ActivitySocketService.isSocketActive(socket)) {
|
|
2785
|
-
ActivitySocketService.connectSharedSocketIfNeeded(socket);
|
|
2786
|
-
}
|
|
2787
|
-
}, ActivitySocketService.getReconnectDelayMs());
|
|
2788
|
-
if (ActivitySocketService.isSocketActive(socket)) {
|
|
2789
|
-
socket.disconnect();
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
|
-
static getReconnectDelayMs() {
|
|
2793
|
-
const delayRange = ACTIVITY_SOCKET_RECONNECT_DELAY_MAX_MS - ACTIVITY_SOCKET_RECONNECT_DELAY_MIN_MS + 1;
|
|
2794
|
-
const randomDelay = ActivitySocketService.getCryptoRandomInt(delayRange) + ACTIVITY_SOCKET_RECONNECT_DELAY_MIN_MS;
|
|
2795
|
-
console.log(`Activity socket reconnect scheduled in ${randomDelay}ms`);
|
|
2796
|
-
return randomDelay;
|
|
2797
|
-
}
|
|
2798
|
-
// Returns an unbiased crypto-random integer from 0 inclusive to exclusiveMax exclusive.
|
|
2799
|
-
static getCryptoRandomInt(exclusiveMax) {
|
|
2800
|
-
const randomValue = new Uint32Array(1);
|
|
2801
|
-
const maxUnbiasedValue = Math.floor(0x100000000 / exclusiveMax) * exclusiveMax;
|
|
2802
|
-
do {
|
|
2803
|
-
globalThis.crypto.getRandomValues(randomValue);
|
|
2804
|
-
} while (randomValue[0] >= maxUnbiasedValue);
|
|
2805
|
-
return randomValue[0] % exclusiveMax;
|
|
2806
|
-
}
|
|
2807
2760
|
// Treats connected, connecting, opening, and open sockets as active.
|
|
2808
2761
|
static isSocketActive(socket) {
|
|
2809
2762
|
if (!socket) {
|