@ray-js/ipc-player-integration 0.0.53-beta.13 → 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
|
});
|
package/lib/utils/ttt.js
CHANGED
|
@@ -136,7 +136,10 @@ export function notifyOfflineShown(deviceId) {
|
|
|
136
136
|
}
|
|
137
137
|
try {
|
|
138
138
|
console.warn('res===notifyOfflineShown', deviceId);
|
|
139
|
-
method(
|
|
139
|
+
method({
|
|
140
|
+
deviceId,
|
|
141
|
+
scene: 'preview_mini'
|
|
142
|
+
});
|
|
140
143
|
return true;
|
|
141
144
|
} catch (error) {
|
|
142
145
|
return false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { notifyOfflineShown } from './ttt';
|
|
2
|
+
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
|
|
3
|
+
ClarityType: {}
|
|
4
|
+
}));
|
|
5
|
+
describe('notifyOfflineShown', () => {
|
|
6
|
+
const originalTy = globalThis.ty;
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
globalThis.ty = originalTy;
|
|
9
|
+
});
|
|
10
|
+
it('passes the device ID and scene as one object to the TTT method', () => {
|
|
11
|
+
const nativeNotify = jest.fn();
|
|
12
|
+
globalThis.ty = {
|
|
13
|
+
ipc: {
|
|
14
|
+
notifyOfflineShown: nativeNotify
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
expect(notifyOfflineShown('camera-1')).toBe(true);
|
|
18
|
+
expect(nativeNotify).toHaveBeenCalledTimes(1);
|
|
19
|
+
expect(nativeNotify).toHaveBeenCalledWith({
|
|
20
|
+
deviceId: 'camera-1',
|
|
21
|
+
scene: 'preview_mini'
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('skips hosts without the TTT method', () => {
|
|
25
|
+
globalThis.ty = {
|
|
26
|
+
ipc: {}
|
|
27
|
+
};
|
|
28
|
+
expect(notifyOfflineShown('camera-1')).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
});
|