@ray-js/ipc-player-integration 0.0.53-beta.14 → 0.0.53-beta.15
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.
|
@@ -10,18 +10,12 @@ export function useOfflineShownNotification(deviceId, deviceOnline) {
|
|
|
10
10
|
deviceId,
|
|
11
11
|
deviceOnline
|
|
12
12
|
};
|
|
13
|
-
const pageWasHiddenRef = useRef(false);
|
|
14
13
|
useEffect(() => {
|
|
15
14
|
if (!deviceOnline) {
|
|
16
15
|
notifyOfflineShown(deviceId);
|
|
17
16
|
}
|
|
18
17
|
}, [deviceId, deviceOnline]);
|
|
19
|
-
usePageEvent('onHide', () => {
|
|
20
|
-
pageWasHiddenRef.current = true;
|
|
21
|
-
});
|
|
22
18
|
usePageEvent('onShow', () => {
|
|
23
|
-
if (!pageWasHiddenRef.current) return;
|
|
24
|
-
pageWasHiddenRef.current = false;
|
|
25
19
|
const {
|
|
26
20
|
deviceId: currentDeviceId,
|
|
27
21
|
deviceOnline: isOnline
|
|
@@ -18,21 +18,16 @@ describe('useOfflineShownNotification', () => {
|
|
|
18
18
|
Object.keys(mockPageEventHandlers).forEach(event => delete mockPageEventHandlers[event]);
|
|
19
19
|
notifyOfflineShown.mockClear();
|
|
20
20
|
});
|
|
21
|
-
it('notifies
|
|
21
|
+
it('notifies on initial offline state and on every onShow while offline', () => {
|
|
22
22
|
renderHook(() => useOfflineShownNotification('camera-1', false));
|
|
23
23
|
expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
|
|
24
24
|
act(() => mockPageEventHandlers.onShow());
|
|
25
|
-
expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
|
|
26
|
-
act(() => {
|
|
27
|
-
mockPageEventHandlers.onHide();
|
|
28
|
-
mockPageEventHandlers.onShow();
|
|
29
|
-
});
|
|
30
25
|
expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
|
|
31
|
-
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-1');
|
|
32
26
|
act(() => mockPageEventHandlers.onShow());
|
|
33
|
-
expect(notifyOfflineShown).toHaveBeenCalledTimes(
|
|
27
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
|
|
28
|
+
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-1');
|
|
34
29
|
});
|
|
35
|
-
it('uses the latest online state and device id on
|
|
30
|
+
it('uses the latest online state and device id on every onShow', () => {
|
|
36
31
|
const {
|
|
37
32
|
rerender
|
|
38
33
|
} = renderHook(_ref => {
|
|
@@ -51,20 +46,14 @@ describe('useOfflineShownNotification', () => {
|
|
|
51
46
|
deviceId: 'camera-2',
|
|
52
47
|
deviceOnline: true
|
|
53
48
|
});
|
|
54
|
-
act(() =>
|
|
55
|
-
mockPageEventHandlers.onHide();
|
|
56
|
-
mockPageEventHandlers.onShow();
|
|
57
|
-
});
|
|
49
|
+
act(() => mockPageEventHandlers.onShow());
|
|
58
50
|
expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
|
|
59
51
|
rerender({
|
|
60
52
|
deviceId: 'camera-2',
|
|
61
53
|
deviceOnline: false
|
|
62
54
|
});
|
|
63
55
|
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
|
|
64
|
-
act(() =>
|
|
65
|
-
mockPageEventHandlers.onHide();
|
|
66
|
-
mockPageEventHandlers.onShow();
|
|
67
|
-
});
|
|
56
|
+
act(() => mockPageEventHandlers.onShow());
|
|
68
57
|
expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
|
|
69
58
|
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
|
|
70
59
|
});
|