@ray-js/ipc-player-integration 0.0.65-beta.1 → 0.0.65-beta.3
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/ctx/multiCameraCtx.d.ts +2 -0
- package/lib/ctx/multiCameraCtx.js +17 -1
- package/lib/ctx/multiCameraCtx.test.d.ts +1 -0
- package/lib/ctx/multiCameraCtx.test.js +65 -0
- package/lib/ui/ui.js +17 -3
- package/lib/widgets/multiCamera/multiPtz.js +1 -1
- package/lib/widgets/multiCamera/tileMultiPtz.js +1 -1
- package/package.json +1 -1
|
@@ -92,6 +92,8 @@ export declare const useMultiCameraCtx: (props: Props) => {
|
|
|
92
92
|
* 设置ptz状态
|
|
93
93
|
*/
|
|
94
94
|
setPtzStatus: (value: boolean | ((prevValue: boolean) => boolean)) => void;
|
|
95
|
+
togglePtz: (this: unknown) => void;
|
|
96
|
+
openDefaultPtz: (this: unknown) => void;
|
|
95
97
|
/**
|
|
96
98
|
* 显示/隐藏镜头名称
|
|
97
99
|
*/
|
|
@@ -6,7 +6,10 @@ import { MultiCameraLayoutStyle, MultiCameraScreenMode } from '../interface';
|
|
|
6
6
|
import { useDpSupport } from '../hooks';
|
|
7
7
|
import { GUN_BALL, MULTI_GUN_BALL, MULTI_PTZ_CONTROL, MULTI_ZOOM_CONTROL, PTZ_CONTROL, ZOOM_CONTROL } from '../utils/content/dpCode';
|
|
8
8
|
import { getLensSupportDirections, isSwipeDirectionSupported } from '../utils';
|
|
9
|
-
import { useAtom } from './store';
|
|
9
|
+
import { getDefaultStore, useAtom } from './store';
|
|
10
|
+
|
|
11
|
+
// Keep the opt-out across player remounts, only for this miniapp runtime.
|
|
12
|
+
let ptzManuallyClosed = false;
|
|
10
13
|
const DEFAULT_VIDEO_SPLIT_PROTOCOL = {
|
|
11
14
|
total_split_num: 1,
|
|
12
15
|
split_info: [],
|
|
@@ -56,6 +59,17 @@ export const useMultiCameraCtx = props => {
|
|
|
56
59
|
const [selectedLenInfoAtom, setSelectedLenInfo] = useAtom(DEFAULT_SELECTED_LEN_INFO);
|
|
57
60
|
const [nextLayoutStyleAtom, setNextLayoutStyle] = useAtom(MultiCameraLayoutStyle.invalid);
|
|
58
61
|
const [ptzStatusAtom, setPtzStatus] = useAtom(false);
|
|
62
|
+
const togglePtz = useMemoizedFn(() => {
|
|
63
|
+
const store = getDefaultStore();
|
|
64
|
+
const nextStatus = !store.get(ptzStatusAtom);
|
|
65
|
+
if (!nextStatus && store.get(screenModeAtom) === MultiCameraScreenMode.full) {
|
|
66
|
+
ptzManuallyClosed = true;
|
|
67
|
+
}
|
|
68
|
+
setPtzStatus(nextStatus);
|
|
69
|
+
});
|
|
70
|
+
const openDefaultPtz = useMemoizedFn(() => {
|
|
71
|
+
if (!ptzManuallyClosed) setPtzStatus(true);
|
|
72
|
+
});
|
|
59
73
|
const selectVideoFiredRef = useRef(false);
|
|
60
74
|
const selectedLenInfoRef = useRef(DEFAULT_SELECTED_LEN_INFO);
|
|
61
75
|
const handleSelectVideoIndex = useMemoizedFn(event => {
|
|
@@ -310,6 +324,8 @@ export const useMultiCameraCtx = props => {
|
|
|
310
324
|
* 设置ptz状态
|
|
311
325
|
*/
|
|
312
326
|
setPtzStatus,
|
|
327
|
+
togglePtz,
|
|
328
|
+
openDefaultPtz,
|
|
313
329
|
/**
|
|
314
330
|
* 显示/隐藏镜头名称
|
|
315
331
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
jest.mock('@ray-js/ray-ipc-utils', () => ({}));
|
|
3
|
+
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({}));
|
|
4
|
+
jest.mock('../hooks', () => ({
|
|
5
|
+
useDpSupport: () => ({})
|
|
6
|
+
}));
|
|
7
|
+
jest.mock('../utils', () => ({}));
|
|
8
|
+
const {
|
|
9
|
+
useMultiCameraCtx
|
|
10
|
+
} = require('./multiCameraCtx');
|
|
11
|
+
const {
|
|
12
|
+
getDefaultStore,
|
|
13
|
+
updateAtom
|
|
14
|
+
} = require('./store');
|
|
15
|
+
const {
|
|
16
|
+
MultiCameraScreenMode
|
|
17
|
+
} = require('../interface');
|
|
18
|
+
it('keeps the portrait PTZ opt-out across player remounts until the miniapp restarts', () => {
|
|
19
|
+
const props = {
|
|
20
|
+
devId: 'test-device',
|
|
21
|
+
IPCPlayerInstance: {
|
|
22
|
+
switchLayoutStyle: () => undefined
|
|
23
|
+
},
|
|
24
|
+
videoSplitProtocol: {
|
|
25
|
+
total_split_num: 2,
|
|
26
|
+
p_v: 3,
|
|
27
|
+
split_info: []
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const store = getDefaultStore();
|
|
31
|
+
const player = renderHook(() => useMultiCameraCtx(props));
|
|
32
|
+
const isOpen = () => store.get(player.result.current.ptzStatus);
|
|
33
|
+
act(() => player.result.current.openDefaultPtz());
|
|
34
|
+
expect(isOpen()).toBe(true);
|
|
35
|
+
|
|
36
|
+
// Programmatic collapse must not disable the next automatic expansion.
|
|
37
|
+
act(() => player.result.current.setPtzStatus(false));
|
|
38
|
+
act(() => player.result.current.openDefaultPtz());
|
|
39
|
+
expect(isOpen()).toBe(true);
|
|
40
|
+
|
|
41
|
+
// Landscape interaction must not opt out of the portrait-only policy.
|
|
42
|
+
act(() => updateAtom(player.result.current.screenMode, MultiCameraScreenMode.landscape));
|
|
43
|
+
act(() => player.result.current.togglePtz());
|
|
44
|
+
expect(isOpen()).toBe(false);
|
|
45
|
+
act(() => updateAtom(player.result.current.screenMode, MultiCameraScreenMode.full));
|
|
46
|
+
act(() => player.result.current.openDefaultPtz());
|
|
47
|
+
expect(isOpen()).toBe(true);
|
|
48
|
+
act(() => player.result.current.togglePtz());
|
|
49
|
+
act(() => player.result.current.openDefaultPtz());
|
|
50
|
+
expect(isOpen()).toBe(false);
|
|
51
|
+
|
|
52
|
+
// Explicit reopening remains available without clearing the opt-out.
|
|
53
|
+
act(() => player.result.current.togglePtz());
|
|
54
|
+
expect(isOpen()).toBe(true);
|
|
55
|
+
act(() => player.result.current.setPtzStatus(false));
|
|
56
|
+
act(() => player.result.current.openDefaultPtz());
|
|
57
|
+
expect(isOpen()).toBe(false);
|
|
58
|
+
player.unmount();
|
|
59
|
+
const remounted = renderHook(() => useMultiCameraCtx(props));
|
|
60
|
+
act(() => remounted.result.current.openDefaultPtz());
|
|
61
|
+
expect(store.get(remounted.result.current.ptzStatus)).toBe(false);
|
|
62
|
+
act(() => remounted.result.current.togglePtz());
|
|
63
|
+
expect(store.get(remounted.result.current.ptzStatus)).toBe(true);
|
|
64
|
+
remounted.unmount();
|
|
65
|
+
});
|
package/lib/ui/ui.js
CHANGED
|
@@ -334,6 +334,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
334
334
|
const hasVisibleGuideTip = absoluteContent === null || absoluteContent === void 0 ? void 0 : absoluteContent.some(item => [tileTipId, landscapeTipId, ptzMoveableTipId, ptzControlTipId, zoomTurntableTipId].includes(item.id) && playState === PlayState.PLAYING && shouldRenderContent(item, {
|
|
335
335
|
playState
|
|
336
336
|
}));
|
|
337
|
+
const hasPendingLayoutGuide = (absoluteContent === null || absoluteContent === void 0 ? void 0 : absoluteContent.some(item => item.id === tileTipId)) && !new Storage(devId).getSync(tileTipId);
|
|
337
338
|
|
|
338
339
|
// 默认最大缩放倍数下发给播放器;多镜头设备的上限要按当前镜头换算,交给 zoomTurntable 下发
|
|
339
340
|
useEffect(() => {
|
|
@@ -452,6 +453,19 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
452
453
|
multiCameraCtx.setPtzStatus(false);
|
|
453
454
|
}, null);
|
|
454
455
|
}, [screenMode, instance]);
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
const {
|
|
458
|
+
multiCameraCtx
|
|
459
|
+
} = instance;
|
|
460
|
+
if (!multiCameraCtx.isSupport || screenMode !== MultiCameraScreenMode.full || hasPendingLayoutGuide) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (selectedLenInfo.supportPTZ) {
|
|
464
|
+
multiCameraCtx.openDefaultPtz();
|
|
465
|
+
} else if (!selectedLenInfo.supportZoom) {
|
|
466
|
+
multiCameraCtx.setPtzStatus(false);
|
|
467
|
+
}
|
|
468
|
+
}, [instance, screenMode, selectedLenInfo.index, selectedLenInfo.supportPTZ, selectedLenInfo.supportZoom, hasPendingLayoutGuide]);
|
|
455
469
|
useEffect(() => {
|
|
456
470
|
if (!instance.multiCameraCtx.isSupport) return;
|
|
457
471
|
|
|
@@ -479,7 +493,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
479
493
|
}, [instance, ptzStatus]);
|
|
480
494
|
useEffect(() => {
|
|
481
495
|
if (!instance.multiCameraCtx.isSupport) return;
|
|
482
|
-
if (!ptzStatus || screenMode !== MultiCameraScreenMode.full || componentHideState) {
|
|
496
|
+
if (!ptzStatus || screenMode !== MultiCameraScreenMode.full || componentHideState || hasPendingLayoutGuide) {
|
|
483
497
|
instance.hideContent('absolute', ptzMoveableTipId);
|
|
484
498
|
}
|
|
485
499
|
|
|
@@ -493,11 +507,11 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
493
507
|
|
|
494
508
|
// ptz 提示
|
|
495
509
|
const storage = new Storage(devId);
|
|
496
|
-
if (!storage.getSync(ptzMoveableTipId) && !componentHideState && selectedLenInfo.supportPTZ && screenMode === MultiCameraScreenMode.full) {
|
|
510
|
+
if (!storage.getSync(ptzMoveableTipId) && !hasPendingLayoutGuide && !componentHideState && selectedLenInfo.supportPTZ && screenMode === MultiCameraScreenMode.full) {
|
|
497
511
|
instance.showContent('absolute', ptzMoveableTipId);
|
|
498
512
|
}
|
|
499
513
|
}
|
|
500
|
-
}, [instance, ptzStatus, selectedLenInfo, componentHideState, screenMode]);
|
|
514
|
+
}, [instance, ptzStatus, selectedLenInfo, componentHideState, screenMode, hasPendingLayoutGuide]);
|
|
501
515
|
|
|
502
516
|
// 适配横屏进入面板的情况
|
|
503
517
|
useEffect(() => {
|
|
@@ -26,7 +26,7 @@ export const MultiPtz = props => {
|
|
|
26
26
|
selectedLenInfo: multiCameraCtx.selectedLenInfo
|
|
27
27
|
});
|
|
28
28
|
const onPtz = useMemoizedFn(() => {
|
|
29
|
-
multiCameraCtx.
|
|
29
|
+
multiCameraCtx.togglePtz();
|
|
30
30
|
});
|
|
31
31
|
if (!selectedLenInfo.supportPTZ && !selectedLenInfo.supportZoom) {
|
|
32
32
|
return null;
|
|
@@ -27,7 +27,7 @@ export const TileMultiPtz = props => {
|
|
|
27
27
|
});
|
|
28
28
|
const lighterBrandColor = new Color(brandColor).alpha(0.2).hexa();
|
|
29
29
|
const onPtz = useMemoizedFn(() => {
|
|
30
|
-
multiCameraCtx.
|
|
30
|
+
multiCameraCtx.togglePtz();
|
|
31
31
|
});
|
|
32
32
|
if (!selectedLenInfo.supportPTZ && !selectedLenInfo.supportZoom) {
|
|
33
33
|
return null;
|