@ray-js/ipc-player-integration 0.0.53-beta.11 → 0.0.53-beta.12
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.
package/lib/ui/ui.js
CHANGED
|
@@ -21,12 +21,13 @@ import BottomLeftContent from './bottomLeftContent';
|
|
|
21
21
|
import BottomRightContent from './bottomRightContent';
|
|
22
22
|
import TopLeftContent from './topLeftContent';
|
|
23
23
|
import TopRightContent from './topRightContent';
|
|
24
|
+
import { useOfflineShownNotification } from './useOfflineShownNotification';
|
|
24
25
|
import { FlowLowTip, VideoBitKBP } from '../widgets';
|
|
25
26
|
import { useMemoizedFn } from '../hooks';
|
|
26
27
|
import { Storage } from '../utils/storage';
|
|
27
28
|
import './ui.less';
|
|
28
29
|
import { updatePlayerWidgetProps } from '../features';
|
|
29
|
-
import { getNgRawData, getSmartImageQualityState, isLowPhone
|
|
30
|
+
import { getNgRawData, getSmartImageQualityState, isLowPhone } from '../utils/ttt';
|
|
30
31
|
import { getCaptureResultSummary } from '../utils/captureResult';
|
|
31
32
|
import { lensCount } from '../widgets/zoomTurntable/lensSkill';
|
|
32
33
|
import { shouldRenderContent } from './absoluteContent';
|
|
@@ -185,13 +186,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
185
186
|
isLowPhoneRef.current = !!res;
|
|
186
187
|
});
|
|
187
188
|
}, []);
|
|
188
|
-
|
|
189
|
-
// 监听设备在线状态,离线提示展示时通知宿主;notifyOfflineShown 内部兼容没有该 TTT 方法的宿主。
|
|
190
|
-
useEffect(() => {
|
|
191
|
-
if (!deviceOnline) {
|
|
192
|
-
notifyOfflineShown(devId);
|
|
193
|
-
}
|
|
194
|
-
}, [deviceOnline, devId]);
|
|
189
|
+
useOfflineShownNotification(devId, deviceOnline);
|
|
195
190
|
|
|
196
191
|
// 展示顶部内容
|
|
197
192
|
const [showTopContent, setShowTopContent] = useState(true);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useOfflineShownNotification(deviceId: string, deviceOnline: boolean): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { usePageEvent } from '@ray-js/ray';
|
|
3
|
+
import { notifyOfflineShown } from '../utils/ttt';
|
|
4
|
+
export function useOfflineShownNotification(deviceId, deviceOnline) {
|
|
5
|
+
const latestDeviceRef = useRef({
|
|
6
|
+
deviceId,
|
|
7
|
+
deviceOnline
|
|
8
|
+
});
|
|
9
|
+
latestDeviceRef.current = {
|
|
10
|
+
deviceId,
|
|
11
|
+
deviceOnline
|
|
12
|
+
};
|
|
13
|
+
const pageWasHiddenRef = useRef(false);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!deviceOnline) {
|
|
16
|
+
notifyOfflineShown(deviceId);
|
|
17
|
+
}
|
|
18
|
+
}, [deviceId, deviceOnline]);
|
|
19
|
+
usePageEvent('onHide', () => {
|
|
20
|
+
pageWasHiddenRef.current = true;
|
|
21
|
+
});
|
|
22
|
+
usePageEvent('onShow', () => {
|
|
23
|
+
if (!pageWasHiddenRef.current) return;
|
|
24
|
+
pageWasHiddenRef.current = false;
|
|
25
|
+
const {
|
|
26
|
+
deviceId: currentDeviceId,
|
|
27
|
+
deviceOnline: isOnline
|
|
28
|
+
} = latestDeviceRef.current;
|
|
29
|
+
if (!isOnline) {
|
|
30
|
+
notifyOfflineShown(currentDeviceId);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
import { act, renderHook } from '@testing-library/react-hooks';
|
|
4
|
+
import { notifyOfflineShown } from '../utils/ttt';
|
|
5
|
+
import { useOfflineShownNotification } from './useOfflineShownNotification';
|
|
6
|
+
const mockPageEventHandlers = {};
|
|
7
|
+
jest.mock('@ray-js/ray', () => ({
|
|
8
|
+
usePageEvent: (event, handler) => {
|
|
9
|
+
// Keep the first callback to also verify that it reads the latest props after rerenders.
|
|
10
|
+
if (!mockPageEventHandlers[event]) mockPageEventHandlers[event] = handler;
|
|
11
|
+
}
|
|
12
|
+
}));
|
|
13
|
+
jest.mock('../utils/ttt', () => ({
|
|
14
|
+
notifyOfflineShown: jest.fn()
|
|
15
|
+
}));
|
|
16
|
+
describe('useOfflineShownNotification', () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
Object.keys(mockPageEventHandlers).forEach(event => delete mockPageEventHandlers[event]);
|
|
19
|
+
notifyOfflineShown.mockClear();
|
|
20
|
+
});
|
|
21
|
+
it('notifies once on initial offline state and once per foreground return', () => {
|
|
22
|
+
renderHook(() => useOfflineShownNotification('camera-1', false));
|
|
23
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
|
|
24
|
+
act(() => mockPageEventHandlers.onShow());
|
|
25
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
|
|
26
|
+
act(() => {
|
|
27
|
+
mockPageEventHandlers.onHide();
|
|
28
|
+
mockPageEventHandlers.onShow();
|
|
29
|
+
});
|
|
30
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
|
|
31
|
+
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-1');
|
|
32
|
+
act(() => mockPageEventHandlers.onShow());
|
|
33
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
|
|
34
|
+
});
|
|
35
|
+
it('uses the latest online state and device id on foreground return', () => {
|
|
36
|
+
const {
|
|
37
|
+
rerender
|
|
38
|
+
} = renderHook(_ref => {
|
|
39
|
+
let {
|
|
40
|
+
deviceId,
|
|
41
|
+
deviceOnline
|
|
42
|
+
} = _ref;
|
|
43
|
+
return useOfflineShownNotification(deviceId, deviceOnline);
|
|
44
|
+
}, {
|
|
45
|
+
initialProps: {
|
|
46
|
+
deviceId: 'camera-1',
|
|
47
|
+
deviceOnline: false
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
rerender({
|
|
51
|
+
deviceId: 'camera-2',
|
|
52
|
+
deviceOnline: true
|
|
53
|
+
});
|
|
54
|
+
act(() => {
|
|
55
|
+
mockPageEventHandlers.onHide();
|
|
56
|
+
mockPageEventHandlers.onShow();
|
|
57
|
+
});
|
|
58
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
|
|
59
|
+
rerender({
|
|
60
|
+
deviceId: 'camera-2',
|
|
61
|
+
deviceOnline: false
|
|
62
|
+
});
|
|
63
|
+
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
|
|
64
|
+
act(() => {
|
|
65
|
+
mockPageEventHandlers.onHide();
|
|
66
|
+
mockPageEventHandlers.onShow();
|
|
67
|
+
});
|
|
68
|
+
expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
|
|
69
|
+
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
|
|
70
|
+
});
|
|
71
|
+
});
|