@ray-js/ipc-player-integration 0.0.65-beta.0 → 0.0.65-beta.2

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.
@@ -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
@@ -14,15 +14,15 @@ import { ipcTTTOperatorLog } from '@ray-js/ray-ipc-utils';
14
14
  import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
15
15
  import { PlayState, PlayerStreamStatus, MultiCameraScreenMode } from '../interface';
16
16
  import { useCtx } from '../ctx/ctx.composition';
17
- import { useStore, updateAtom, getDefaultStore } from '../ctx/store';
17
+ import { useStore, updateAtom } from '../ctx/store';
18
18
  import { UIEventContext } from './context';
19
- import { showAllComponent, hideAllComponent, playerTap, startTimeToHideAllComponent, pauseTimeToHideAllComponent, decodeClarityDic, changeIgnoreHideStopPreview, moveablePtzControlId, tileActionsId, tileTipId, landscapeTipId, multiPtzId, ptzMoveableTipId, showFlowLowTipId, zoomLevelChange, setScaleMultipleEvent, trialCountdownEnd, refreshSmartImageQualityEvent } from './constant';
19
+ import { showAllComponent, hideAllComponent, playerTap, startTimeToHideAllComponent, pauseTimeToHideAllComponent, decodeClarityDic, changeIgnoreHideStopPreview, moveablePtzControlId, tileActionsId, tileTipId, landscapeTipId, multiPtzId, ptzMoveableTipId, ptzControlTipId, showFlowLowTipId, zoomLevelChange, setScaleMultipleEvent, trialCountdownEnd, refreshSmartImageQualityEvent } from './constant';
20
20
  import BottomLeftContent from './bottomLeftContent';
21
21
  import BottomRightContent from './bottomRightContent';
22
22
  import TopLeftContent from './topLeftContent';
23
23
  import TopRightContent from './topRightContent';
24
24
  import { useOfflineShownNotification } from './useOfflineShownNotification';
25
- import { FlowLowTip, VideoBitKBP } from '../widgets';
25
+ import { FlowLowTip, VideoBitKBP, zoomTurntableTipId } from '../widgets';
26
26
  import { useMemoizedFn } from '../hooks';
27
27
  import { Storage } from '../utils/storage';
28
28
  import './ui.less';
@@ -331,6 +331,10 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
331
331
  maxZoomSettings: instance.maxZoomSettings,
332
332
  zoomSkill: instance.zoomSkill
333
333
  });
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
+ playState
336
+ }));
337
+ const hasPendingLayoutGuide = (absoluteContent === null || absoluteContent === void 0 ? void 0 : absoluteContent.some(item => item.id === tileTipId)) && !new Storage(devId).getSync(tileTipId);
334
338
 
335
339
  // 默认最大缩放倍数下发给播放器;多镜头设备的上限要按当前镜头换算,交给 zoomTurntable 下发
336
340
  useEffect(() => {
@@ -449,6 +453,19 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
449
453
  multiCameraCtx.setPtzStatus(false);
450
454
  }, null);
451
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]);
452
469
  useEffect(() => {
453
470
  if (!instance.multiCameraCtx.isSupport) return;
454
471
 
@@ -456,13 +473,16 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
456
473
  instance.multiCameraCtx.getNextLayoutStyle().then(res => {
457
474
  instance.multiCameraCtx.setNextLayoutStyle(res);
458
475
  });
476
+ if (isVerticalFullLayout && screenType === 'vertical') {
477
+ showComponents();
478
+ }
459
479
  }, [layoutStyle, screenMode, instance]);
460
480
  useEffect(() => {
461
481
  if (!instance.multiCameraCtx.isSupport) return;
462
482
 
463
483
  // 组件隐藏时也隐藏镜头名
464
484
  instance.multiCameraCtx.showLenNames(!componentHideState);
465
- }, [componentHideState, instance]);
485
+ }, [componentHideState, instance, layoutStyle, screenMode]);
466
486
  useEffect(() => {
467
487
  if (!instance.multiCameraCtx.isSupport) return;
468
488
  if (ptzStatus) {
@@ -473,7 +493,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
473
493
  }, [instance, ptzStatus]);
474
494
  useEffect(() => {
475
495
  if (!instance.multiCameraCtx.isSupport) return;
476
- if (!ptzStatus || screenMode !== MultiCameraScreenMode.full) {
496
+ if (!ptzStatus || screenMode !== MultiCameraScreenMode.full || componentHideState || hasPendingLayoutGuide) {
477
497
  instance.hideContent('absolute', ptzMoveableTipId);
478
498
  }
479
499
 
@@ -487,11 +507,11 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
487
507
 
488
508
  // ptz 提示
489
509
  const storage = new Storage(devId);
490
- if (!storage.getSync(ptzMoveableTipId) && selectedLenInfo.supportPTZ && screenMode === MultiCameraScreenMode.full) {
510
+ if (!storage.getSync(ptzMoveableTipId) && !hasPendingLayoutGuide && !componentHideState && selectedLenInfo.supportPTZ && screenMode === MultiCameraScreenMode.full) {
491
511
  instance.showContent('absolute', ptzMoveableTipId);
492
512
  }
493
513
  }
494
- }, [instance, ptzStatus, selectedLenInfo, componentHideState, screenMode]);
514
+ }, [instance, ptzStatus, selectedLenInfo, componentHideState, screenMode, hasPendingLayoutGuide]);
495
515
 
496
516
  // 适配横屏进入面板的情况
497
517
  useEffect(() => {
@@ -508,8 +528,6 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
508
528
  const handDisablePlayerTap = useMemoizedFn(value => {
509
529
  disablePlayerTap.current = !!value;
510
530
  });
511
-
512
- // 须在竖屏全屏 effect 之前注册,否则多目首帧 emit('disablePlayerTap') 时 listener 尚未挂载
513
531
  useEffect(() => {
514
532
  eventRef.current.on('disablePlayerTap', handDisablePlayerTap);
515
533
  return () => {
@@ -519,17 +537,10 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
519
537
 
520
538
  // 竖屏全屏副作用处理
521
539
  useEffect(() => {
540
+ eventRef.current.emit('disablePlayerTap', false);
541
+ showComponents();
522
542
  if (isVerticalFullLayout && screenType === 'vertical') {
523
- // 竖屏全屏时,控件常驻显示
524
- eventRef.current.emit(showAllComponent);
525
- eventRef.current.emit('disablePlayerTap', true);
526
- eventRef.current.emit(pauseTimeToHideAllComponent);
527
- // 按宽填充,保证播放流宽度为屏幕宽度,高度自适应设为1倍
528
543
  setScaleMultiple(1);
529
- } else {
530
- // 短屏或横屏时,恢复自动隐藏
531
- eventRef.current.emit('disablePlayerTap', false);
532
- showComponents();
533
544
  }
534
545
  }, [isVerticalFullLayout, screenType, playerFit]);
535
546
  useEffect(() => {
@@ -921,7 +932,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
921
932
  clearTimeout(timer.current);
922
933
  timer.current = null;
923
934
  }
924
- if (!hasUserTappedPlayerRef.current) return;
935
+ if (!hasUserTappedPlayerRef.current || hasVisibleGuideTip) return;
925
936
  timer.current = setTimeout(onTimeout, HIDE_COMPONENT_TIME);
926
937
  });
927
938
 
@@ -950,9 +961,6 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
950
961
  const listenStart = useMemoizedFn(() => {
951
962
  // 重新开始计时(用户还没点过画面时不启动,见 startHideTimer)
952
963
  startHideTimer(() => {
953
- // 定时器触发时从 store 读最新状态,避免启动时闭包拿到过期的 isVerticalFullLayout
954
- const store = getDefaultStore();
955
- if (store.get(instance.isVerticalFullLayout) && store.get(instance.screenType) === 'vertical') return;
956
964
  triggerEvent(hideAllComponent);
957
965
  });
958
966
  });
@@ -967,6 +975,13 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
967
975
  if (isHidingByTapRef.current) return;
968
976
  setComponentHideState(false);
969
977
  });
978
+ useEffect(() => {
979
+ if (hasVisibleGuideTip) {
980
+ showComponents();
981
+ } else {
982
+ listenStart();
983
+ }
984
+ }, [hasVisibleGuideTip]);
970
985
  const onChangeIgnoreHideStopPreview = state => {
971
986
  setIgnoreStopOnHide(state);
972
987
  };
@@ -1090,7 +1105,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1090
1105
  return false;
1091
1106
  });
1092
1107
  const playerContainerHeight = screenType === 'vertical' ? (style === null || style === void 0 ? void 0 : style.height) || '100%' : '100vh';
1093
- const isVerticalFullMode = isVerticalFullLayout && screenType === 'vertical';
1108
+ const bottomHideState = isVerticalFullLayout && screenType === 'vertical' ? false : componentHideState;
1094
1109
  return /*#__PURE__*/React.createElement(UIEventContext.Provider, {
1095
1110
  value: {
1096
1111
  event: eventRef.current,
@@ -1104,7 +1119,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1104
1119
  })
1105
1120
  }, /*#__PURE__*/React.createElement(View, {
1106
1121
  style: {
1107
- height: isVerticalFullMode ? `calc(${playerContainerHeight} - 48px)` : playerContainerHeight
1122
+ height: isVerticalFullLayout && screenType === 'vertical' ? `calc(${playerContainerHeight} - 48px)` : playerContainerHeight
1108
1123
  }
1109
1124
  }, /*#__PURE__*/React.createElement(IPCPlayer, {
1110
1125
  defaultMute: mute,
@@ -1118,6 +1133,9 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1118
1133
  onCtx: res => {
1119
1134
  if (res) {
1120
1135
  setCreateCtx(true);
1136
+ if (instance.multiCameraCtx.isSupport) {
1137
+ instance.multiCameraCtx.showLenNames(!componentHideState);
1138
+ }
1121
1139
  }
1122
1140
  }
1123
1141
  // onPlayerTap={handlePlayerClick}
@@ -1148,9 +1166,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1148
1166
  onPlayerTap: data => {
1149
1167
  console.log('playerTap event');
1150
1168
  if (disablePlayerTap.current) {
1151
- // 「禁用」只针对「点画面切换控件显隐」这件事(竖屏全屏下控件要常驻),
1152
- // 但用户确实点了画面这个事实仍要派发出去 —— 转盘、PTZ 这类浮层靠它收起。
1153
- // 不派发的话,竖屏全屏下点播放器关不掉转盘(普通竖屏可以,因为那时没禁用)。
1169
+ // Host overlays may disable toggling; popups still need the tap notification.
1154
1170
  console.log('playerTap 事件已禁止显隐切换,仅派发 tap 通知浮层');
1155
1171
  eventRef.current.emit(playerTap);
1156
1172
  return;
@@ -1242,14 +1258,20 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1242
1258
  show: !showTopContent || componentHideState || !playerReady
1243
1259
  }), /*#__PURE__*/React.createElement(View, {
1244
1260
  className: clsx('ipc-player-bottom-content', {
1245
- 'ipc-player-bottom-content-hide': componentHideState,
1246
- 'ipc-player-bottom-content-show': !componentHideState,
1247
- 'ipc-player-bottom-content-full': isVerticalFullMode
1261
+ 'ipc-player-bottom-content-hide': bottomHideState,
1262
+ 'ipc-player-bottom-content-show': !bottomHideState,
1263
+ 'ipc-player-bottom-content-full': isVerticalFullLayout && screenType === 'vertical'
1248
1264
  }),
1249
1265
  style: {
1250
1266
  height: screenType === 'vertical' ? '48px' : '72px'
1251
1267
  }
1252
- }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BottomLeftContent, {
1268
+ }, /*#__PURE__*/React.createElement(UIEventContext.Provider, {
1269
+ value: {
1270
+ event: eventRef.current,
1271
+ componentHideState: bottomHideState,
1272
+ refreshElement
1273
+ }
1274
+ }, /*#__PURE__*/React.createElement(BottomLeftContent, {
1253
1275
  ctx: instance,
1254
1276
  reservedRight: bottomRightReserved
1255
1277
  }, renderBottomLeftContent), /*#__PURE__*/React.createElement(BottomRightContent, {
@@ -1262,6 +1284,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1262
1284
  if (!shouldRenderContent(item, {
1263
1285
  playState
1264
1286
  })) return null;
1287
+ if (item.id === tileActionsId && isVerticalFullLayout && componentHideState) return null;
1265
1288
  const contentProps = _objectSpread(_objectSpread(_objectSpread({
1266
1289
  key: item.id
1267
1290
  }, item.initProps), instance), {}, {
@@ -390,7 +390,7 @@ export const MoveablePtzControlItem = props => {
390
390
  ptzData: selectedLenInfo.supportPTZ ? ptzData : [],
391
391
  onTouchPtzStart: onTouchPtzStart,
392
392
  onTouchPtzEnd: async () => {
393
- screenMode === MultiCameraScreenMode.landscape && event.emit(startTimeToHideAllComponent);
393
+ screenMode !== MultiCameraScreenMode.short && event.emit(startTimeToHideAllComponent);
394
394
  const stopConfig = dpSupportMap.ipc_multi_ptz_control ? {
395
395
  code: 'ipc_multi_ptz_stop',
396
396
  value: JSON.stringify({
@@ -415,7 +415,7 @@ export const MoveablePtzControlItem = props => {
415
415
  },
416
416
  onTouchZoomStart: onTouchZoomStart,
417
417
  onTouchZoomEnd: async () => {
418
- screenMode === MultiCameraScreenMode.landscape && event.emit(startTimeToHideAllComponent);
418
+ screenMode !== MultiCameraScreenMode.short && event.emit(startTimeToHideAllComponent);
419
419
  const stopConfig = dpSupportMap.ipc_multi_zoom_control ? {
420
420
  code: 'ipc_multi_zoom_stop',
421
421
  value: JSON.stringify({
@@ -464,10 +464,10 @@ export const MoveablePtzControl = props => {
464
464
  // 处理因为状态更新不同步导致的闪烁问题
465
465
  const activeViewRef = useRef(0);
466
466
  const onDragStart = () => {
467
- screenMode === MultiCameraScreenMode.landscape && event.emit(pauseTimeToHideAllComponent);
467
+ screenMode !== MultiCameraScreenMode.short && event.emit(pauseTimeToHideAllComponent);
468
468
  };
469
469
  const onDragEnd = data => {
470
- screenMode === MultiCameraScreenMode.landscape && event.emit(startTimeToHideAllComponent);
470
+ screenMode !== MultiCameraScreenMode.short && event.emit(startTimeToHideAllComponent);
471
471
  activeViewRef.current = activeViewRef.current === 0 ? 1 : 0;
472
472
  setStyle(prev => _objectSpread(_objectSpread({}, prev), {}, {
473
473
  positionLeft: data.positionLeft,
@@ -26,7 +26,7 @@ export const MultiPtz = props => {
26
26
  selectedLenInfo: multiCameraCtx.selectedLenInfo
27
27
  });
28
28
  const onPtz = useMemoizedFn(() => {
29
- multiCameraCtx.setPtzStatus(!ptzStatus);
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.setPtzStatus(!ptzStatus);
30
+ multiCameraCtx.togglePtz();
31
31
  });
32
32
  if (!selectedLenInfo.supportPTZ && !selectedLenInfo.supportZoom) {
33
33
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.65-beta.0",
3
+ "version": "0.0.65-beta.2",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [