@ray-js/ipc-player-integration 0.0.53-beta.9 → 0.0.54

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.
Files changed (36) hide show
  1. package/lib/ctx/ctx.composition.js +3 -13
  2. package/lib/ctx/ctx.js +67 -71
  3. package/lib/i18n/index.d.ts +0 -12
  4. package/lib/i18n/strings.d.ts +0 -6
  5. package/lib/i18n/strings.js +0 -6
  6. package/lib/interface.d.ts +3 -16
  7. package/lib/ui/ui.js +25 -34
  8. package/lib/ui/useOfflineShownNotification.d.ts +1 -0
  9. package/lib/ui/useOfflineShownNotification.js +32 -0
  10. package/lib/ui/useOfflineShownNotification.test.js +98 -0
  11. package/lib/utils/ttt.js +5 -2
  12. package/lib/utils/ttt.notifyOfflineShown.test.js +30 -0
  13. package/lib/widgets/index.d.ts +0 -1
  14. package/lib/widgets/index.js +1 -2
  15. package/lib/widgets/recordVideo/recordVideo.js +36 -50
  16. package/lib/widgets/recordVideo/recordVideo.less +74 -17
  17. package/lib/widgets/screenshot/screenshot.js +66 -68
  18. package/lib/widgets/screenshot/screenshot.less +40 -1
  19. package/lib/widgets/videoBitKBP/videoBitKBP.js +29 -28
  20. package/lib/widgets/videoBitKBP/videoBitKBP.less +17 -14
  21. package/lib/widgets/videoBitKBP/videoBitKBP.test.js +76 -1
  22. package/lib/widgets/zoomTurntable/lensSkill.js +1 -4
  23. package/package.json +2 -2
  24. package/lib/ui/absoluteContent.d.ts +0 -2
  25. package/lib/ui/absoluteContent.js +0 -3
  26. package/lib/utils/captureResult.d.ts +0 -14
  27. package/lib/utils/captureResult.js +0 -70
  28. package/lib/utils/captureResult.test.js +0 -117
  29. package/lib/widgets/captureResult/captureResult.d.ts +0 -16
  30. package/lib/widgets/captureResult/captureResult.js +0 -85
  31. package/lib/widgets/captureResult/captureResult.less +0 -144
  32. package/lib/widgets/captureResult/captureResult.test.js +0 -80
  33. package/lib/widgets/captureResult/index.d.ts +0 -2
  34. package/lib/widgets/captureResult/index.js +0 -2
  35. /package/lib/{utils/captureResult.test.d.ts → ui/useOfflineShownNotification.test.d.ts} +0 -0
  36. /package/lib/{widgets/captureResult/captureResult.test.d.ts → utils/ttt.notifyOfflineShown.test.d.ts} +0 -0
@@ -6,7 +6,6 @@ import { IntercomMode, MuteMode, ClarityType } from '@ray-js/ray-ipc-utils/lib/i
6
6
  import { createUseCtx } from './ctx';
7
7
  import { FullSmallIntercom, VerticalSmallIntercom, BatteryFull, Battery, Screenshot, TempHumidity, Signal4G, RecordVideo, FullScreen, VideoBitKBP, Muted, Floodlight, Siren, TryExperience, Resolution, Ptz, MultiPtz, TileTip, PtzMoveableTip, LandscapeTip, TileActions, MoveablePtzControl, SwitchLayout, ToggleVerticalFull, RealTimeMagnification, ZoomTurntableEntry } from '../widgets';
8
8
  import { authorizeStatus } from '../utils/authorize';
9
- import { PlayState } from '../interface';
10
9
  import { landscapeTipId, moveablePtzControlId, multiPtzId, ptzMoveableTipId, tileActionsId, tileTipId } from '../ui/constant';
11
10
  import { multiPrefix } from '../widgets/multiCamera/constants';
12
11
  const createPlayContext = ty.createIpcPlayerContext;
@@ -88,29 +87,20 @@ export const defaultBottomRightContent = [{
88
87
  content: FullScreen
89
88
  }];
90
89
  const absoluteContent = [];
91
- const renderWhenPlaying = _ref => {
92
- let {
93
- playState
94
- } = _ref;
95
- return playState === PlayState.PLAYING;
96
- };
97
90
  export const multiCameraAbsoluteContent = [{
98
91
  id: tileTipId,
99
92
  content: TileTip,
100
93
  absoluteContentClassName: `${multiPrefix}-tile-tip-wrap`,
101
- renderWhen: renderWhenPlaying,
102
94
  hidden: true
103
95
  }, {
104
96
  id: ptzMoveableTipId,
105
97
  content: PtzMoveableTip,
106
98
  absoluteContentClassName: `${multiPrefix}-tile-tip-wrap`,
107
- renderWhen: renderWhenPlaying,
108
99
  hidden: true
109
100
  }, {
110
101
  id: landscapeTipId,
111
102
  content: LandscapeTip,
112
103
  absoluteContentClassName: `${multiPrefix}-tile-tip-wrap`,
113
- renderWhen: renderWhenPlaying,
114
104
  hidden: true
115
105
  }, {
116
106
  id: tileActionsId,
@@ -122,12 +112,12 @@ export const multiCameraAbsoluteContent = [{
122
112
  absoluteNoCoverView: true,
123
113
  hidden: true
124
114
  }];
125
- const toast = _ref2 => {
115
+ const toast = _ref => {
126
116
  let {
127
117
  title,
128
118
  duration
129
- } = _ref2,
130
- config = _objectWithoutProperties(_ref2, _excluded);
119
+ } = _ref,
120
+ config = _objectWithoutProperties(_ref, _excluded);
131
121
  ty.showToast(_objectSpread({
132
122
  title,
133
123
  duration,
package/lib/ctx/ctx.js CHANGED
@@ -37,7 +37,6 @@ export const createUseCtx = _ref => {
37
37
  initBottomRightContent,
38
38
  initAbsoluteContent,
39
39
  saveToAlbum = SAVE_TO_ALBUM,
40
- multiLens = false,
41
40
  showPtzControlTip = false,
42
41
  videoSplitProtocol
43
42
  } = _ref2;
@@ -57,7 +56,6 @@ export const createUseCtx = _ref => {
57
56
 
58
57
  // 录像中
59
58
  const [recording] = useAtom(false);
60
- const recordingMultiLensRef = useRef(false);
61
59
 
62
60
  // 录像是否不可点击
63
61
  const [recordingDisabled, setRecordingDisabled] = useAtom(false);
@@ -339,30 +337,6 @@ export const createUseCtx = _ref => {
339
337
  });
340
338
  });
341
339
  };
342
- const stopRecording = showError => {
343
- return new Promise((resolve, reject) => {
344
- IPCPlayerInstance.current.stopRecord({
345
- saveToAlbum,
346
- success: res => {
347
- recordingMultiLensRef.current = false;
348
- updateAtom(recording, false);
349
- resolve(res);
350
- },
351
- fail: err => {
352
- recordingMultiLensRef.current = false;
353
- updateAtom(recording, false);
354
- reject(err);
355
- if (showError) {
356
- const errObj = err.innerError || err || {};
357
- const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_stop_recording_err');
358
- toast({
359
- title: errMsg
360
- });
361
- }
362
- }
363
- });
364
- });
365
- };
366
340
  const multiCameraCtx = useMultiCameraCtx({
367
341
  devId,
368
342
  IPCPlayerInstance: IPCPlayerInstance.current,
@@ -373,7 +347,6 @@ export const createUseCtx = _ref => {
373
347
  brandColor,
374
348
  verticalMic,
375
349
  saveToAlbum,
376
- multiLens,
377
350
  screenType,
378
351
  isVerticalFullLayout,
379
352
  setIsVerticalFullLayout,
@@ -518,59 +491,82 @@ export const createUseCtx = _ref => {
518
491
  eventRef.current.emit(changeIgnoreHideStopPreview, false);
519
492
  return false;
520
493
  }
521
- if (!target) return stopRecording(true);
522
494
  return new Promise((resolve, reject) => {
523
- const startRecord = () => {
524
- IPCPlayerInstance.current.startRecord({
525
- saveToAlbum,
495
+ if (target) {
496
+ // 写入相册
497
+ ty.authorizeStatus({
498
+ scope: 'scope.writePhotosAlbum',
526
499
  success: () => {
527
- updateAtom(recording, true);
528
- resolve(true);
500
+ eventRef.current.emit(changeIgnoreHideStopPreview, false);
501
+ IPCPlayerInstance.current.startRecord({
502
+ saveToAlbum,
503
+ success: () => {
504
+ updateAtom(recording, true);
505
+ resolve(true);
506
+ },
507
+ fail: err => {
508
+ eventRef.current.emit(changeIgnoreHideStopPreview, false);
509
+ reject(err);
510
+ }
511
+ });
512
+ },
513
+ fail: () => {
514
+ ty.authorize({
515
+ scope: 'scope.writePhotosAlbum',
516
+ success: () => {
517
+ IPCPlayerInstance.current.startRecord({
518
+ saveToAlbum,
519
+ success: () => {
520
+ updateAtom(recording, true);
521
+ resolve(true);
522
+ },
523
+ fail: err => {
524
+ reject(err);
525
+ }
526
+ });
527
+ },
528
+ fail: () => {
529
+ showModal({
530
+ title: '',
531
+ content: Strings.getLang('ipc_player_no_album_permission'),
532
+ cancelText: Strings.getLang('ipc_player_authorize_cancel_text'),
533
+ confirmText: Strings.getLang('ipc_player_authorize_confirm_text'),
534
+ isShowGlobal: true,
535
+ success: res => {
536
+ if (res.confirm) {
537
+ openAppSystemSettingPage({
538
+ scope: 'App-Settings',
539
+ success: () => {
540
+ console.log('跳转成功');
541
+ }
542
+ });
543
+ }
544
+ }
545
+ });
546
+ }
547
+ });
548
+ }
549
+ });
550
+ } else {
551
+ IPCPlayerInstance.current.stopRecord({
552
+ saveToAlbum,
553
+ success: res => {
554
+ updateAtom(recording, false);
555
+ resolve(res);
529
556
  },
530
557
  fail: err => {
531
- eventRef.current.emit(changeIgnoreHideStopPreview, false);
558
+ updateAtom(recording, false);
532
559
  reject(err);
560
+ const errObj = err.innerError || err || {};
561
+ const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_stop_recording_err');
562
+ toast({
563
+ title: errMsg
564
+ });
533
565
  }
534
566
  });
535
- };
536
- // 写入相册
537
- ty.authorizeStatus({
538
- scope: 'scope.writePhotosAlbum',
539
- success: () => {
540
- eventRef.current.emit(changeIgnoreHideStopPreview, false);
541
- startRecord();
542
- },
543
- fail: () => {
544
- ty.authorize({
545
- scope: 'scope.writePhotosAlbum',
546
- success: () => {
547
- startRecord();
548
- },
549
- fail: () => {
550
- showModal({
551
- title: '',
552
- content: Strings.getLang('ipc_player_no_album_permission'),
553
- cancelText: Strings.getLang('ipc_player_authorize_cancel_text'),
554
- confirmText: Strings.getLang('ipc_player_authorize_confirm_text'),
555
- isShowGlobal: true,
556
- success: res => {
557
- if (res.confirm) {
558
- openAppSystemSettingPage({
559
- scope: 'App-Settings',
560
- success: () => {
561
- console.log('跳转成功');
562
- }
563
- });
564
- }
565
- }
566
- });
567
- }
568
- });
569
- }
570
- });
567
+ }
571
568
  });
572
569
  },
573
- stopRecordingOnUnload: () => stopRecording(false),
574
570
  setRecordingDisabled,
575
571
  setScreenType,
576
572
  topLeftContent,
@@ -10,11 +10,8 @@ declare const Strings: kit.I18N<{
10
10
  ipc_player_resolution_AUDIO: string;
11
11
  ipc_player_current_resolution_is_equal: string;
12
12
  ipc_player_screenshot_success_tip: string;
13
- ipc_player_screenshot_multi_success_tip: string;
14
13
  ipc_player_error_screenshot_error_tip: string;
15
14
  ipc_player_record_success_tip: string;
16
- ipc_player_record_multi_success_tip: string;
17
- ipc_player_multi_capture_success_count: string;
18
15
  ipc_player_shot_success_check: string;
19
16
  ipc_player_record_success_check: string;
20
17
  ipc_player_recording_now_tip: string;
@@ -55,11 +52,8 @@ declare const Strings: kit.I18N<{
55
52
  ipc_player_resolution_AUDIO: string;
56
53
  ipc_player_current_resolution_is_equal: string;
57
54
  ipc_player_screenshot_success_tip: string;
58
- ipc_player_screenshot_multi_success_tip: string;
59
55
  ipc_player_error_screenshot_error_tip: string;
60
56
  ipc_player_record_success_tip: string;
61
- ipc_player_record_multi_success_tip: string;
62
- ipc_player_multi_capture_success_count: string;
63
57
  ipc_player_shot_success_check: string;
64
58
  ipc_player_record_success_check: string;
65
59
  ipc_player_recording_now_tip: string;
@@ -100,11 +94,8 @@ declare const Strings: kit.I18N<{
100
94
  ipc_player_resolution_AUDIO: string;
101
95
  ipc_player_current_resolution_is_equal: string;
102
96
  ipc_player_screenshot_success_tip: string;
103
- ipc_player_screenshot_multi_success_tip: string;
104
97
  ipc_player_error_screenshot_error_tip: string;
105
98
  ipc_player_record_success_tip: string;
106
- ipc_player_record_multi_success_tip: string;
107
- ipc_player_multi_capture_success_count: string;
108
99
  ipc_player_shot_success_check: string;
109
100
  ipc_player_record_success_check: string;
110
101
  ipc_player_recording_now_tip: string;
@@ -144,11 +135,8 @@ declare const Strings: kit.I18N<{
144
135
  ipc_player_resolution_AUDIO: string;
145
136
  ipc_player_current_resolution_is_equal: string;
146
137
  ipc_player_screenshot_success_tip: string;
147
- ipc_player_screenshot_multi_success_tip: string;
148
138
  ipc_player_error_screenshot_error_tip: string;
149
139
  ipc_player_record_success_tip: string;
150
- ipc_player_record_multi_success_tip: string;
151
- ipc_player_multi_capture_success_count: string;
152
140
  ipc_player_shot_success_check: string;
153
141
  ipc_player_record_success_check: string;
154
142
  ipc_player_recording_now_tip: string;
@@ -9,11 +9,8 @@ declare const _default: {
9
9
  ipc_player_resolution_AUDIO: string;
10
10
  ipc_player_current_resolution_is_equal: string;
11
11
  ipc_player_screenshot_success_tip: string;
12
- ipc_player_screenshot_multi_success_tip: string;
13
12
  ipc_player_error_screenshot_error_tip: string;
14
13
  ipc_player_record_success_tip: string;
15
- ipc_player_record_multi_success_tip: string;
16
- ipc_player_multi_capture_success_count: string;
17
14
  ipc_player_shot_success_check: string;
18
15
  ipc_player_record_success_check: string;
19
16
  ipc_player_recording_now_tip: string;
@@ -54,11 +51,8 @@ declare const _default: {
54
51
  ipc_player_resolution_AUDIO: string;
55
52
  ipc_player_current_resolution_is_equal: string;
56
53
  ipc_player_screenshot_success_tip: string;
57
- ipc_player_screenshot_multi_success_tip: string;
58
54
  ipc_player_error_screenshot_error_tip: string;
59
55
  ipc_player_record_success_tip: string;
60
- ipc_player_record_multi_success_tip: string;
61
- ipc_player_multi_capture_success_count: string;
62
56
  ipc_player_shot_success_check: string;
63
57
  ipc_player_record_success_check: string;
64
58
  ipc_player_recording_now_tip: string;
@@ -9,11 +9,8 @@ export default {
9
9
  ipc_player_resolution_AUDIO: 'Audio Mode',
10
10
  ipc_player_current_resolution_is_equal: 'Already at current clarity',
11
11
  ipc_player_screenshot_success_tip: 'Screenshot saved to album',
12
- ipc_player_screenshot_multi_success_tip: 'Screenshots saved to album',
13
12
  ipc_player_error_screenshot_error_tip: 'Screenshot failed. Please try again later.',
14
13
  ipc_player_record_success_tip: 'Recording saved to album',
15
- ipc_player_record_multi_success_tip: 'Recordings saved to album',
16
- ipc_player_multi_capture_success_count: '{0} items',
17
14
  ipc_player_shot_success_check: 'View',
18
15
  ipc_player_record_success_check: 'View',
19
16
  ipc_player_recording_now_tip: 'Recording in progress...',
@@ -54,11 +51,8 @@ export default {
54
51
  ipc_player_resolution_AUDIO: '音频模式',
55
52
  ipc_player_current_resolution_is_equal: '已是当前清晰度',
56
53
  ipc_player_screenshot_success_tip: '截图已保存在APP相册',
57
- ipc_player_screenshot_multi_success_tip: '图片已保存至相册',
58
54
  ipc_player_error_screenshot_error_tip: '截图失败了,请稍后再试',
59
55
  ipc_player_record_success_tip: '录像已保存在APP相册',
60
- ipc_player_record_multi_success_tip: '视频已保存至相册',
61
- ipc_player_multi_capture_success_count: '共{0}个',
62
56
  ipc_player_shot_success_check: '查看',
63
57
  ipc_player_record_success_check: '查看',
64
58
  ipc_player_recording_now_tip: '正在录像中...',
@@ -47,7 +47,6 @@ export type UseCtx = (options: {
47
47
  initBottomRightContent?: ComponentConfig[];
48
48
  initAbsoluteContent?: ComponentConfig[];
49
49
  saveToAlbum?: 0 | 1;
50
- multiLens?: boolean;
51
50
  showPtzControlTip?: boolean;
52
51
  videoSplitProtocol?: VideoSplitProtocol;
53
52
  }) => {
@@ -55,7 +54,6 @@ export type UseCtx = (options: {
55
54
  brandColor: RetAtom<string>;
56
55
  verticalMic: RetAtom<boolean>;
57
56
  saveToAlbum: 0 | 1;
58
- multiLens: boolean;
59
57
  showPtzControlTip: boolean;
60
58
  screenType: RetAtom<ScreenType>;
61
59
  isVerticalFullLayout: RetAtom<boolean>;
@@ -91,8 +89,7 @@ export type UseCtx = (options: {
91
89
  setRecordingDisabled: (type: boolean) => void;
92
90
  setResolution: (type: string) => Promise<boolean>;
93
91
  setResolutionList: (type: string[]) => void;
94
- setRecording: (value: boolean, onlyUpdateAtom?: boolean) => Promise<CaptureResult>;
95
- stopRecordingOnUnload: () => Promise<CaptureResult>;
92
+ setRecording: (value: boolean, onlyUpdateAtom?: boolean) => Promise<RecordInfoData>;
96
93
  setIntercom: (value: boolean, onlyUpdateAtom?: boolean) => Promise<boolean>;
97
94
  setMute: (value: boolean) => Promise<boolean>;
98
95
  changeStreamStatus: (value: PlayerStreamStatus) => void;
@@ -123,12 +120,8 @@ export type ComponentConfig<T = ReturnType<UseCtx> & Record<string, any>> = {
123
120
  absoluteContentClassName?: string;
124
121
  absoluteContentStyle?: React.CSSProperties;
125
122
  absoluteNoCoverView?: boolean;
126
- renderWhen?: (state: ComponentRenderState) => boolean;
127
123
  hidden?: boolean;
128
124
  };
129
- export type ComponentRenderState = {
130
- playState: PlayState;
131
- };
132
125
  export type ComponentConfigProps = {
133
126
  IPCPlayerContext: IpcContext;
134
127
  } & ReturnType<UseCtx>;
@@ -136,17 +129,11 @@ export type PlayStatusData = {
136
129
  playState: PlayState;
137
130
  playCode: number;
138
131
  };
139
- export type CaptureFileInfo = {
140
- index?: number;
132
+ export type RecordInfoData = boolean | {
141
133
  tempImagePath: string;
142
134
  filePath: string;
143
- thumbPath?: string;
144
- width?: number;
145
- height?: number;
146
- data?: string;
135
+ thumbPath: string;
147
136
  };
148
- export type CaptureResult = boolean | CaptureFileInfo;
149
- export type RecordInfoData = CaptureResult;
150
137
  /**
151
138
  * 多目屏幕模式
152
139
  */
package/lib/ui/ui.js CHANGED
@@ -21,15 +21,14 @@ 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, notifyOfflineShown } from '../utils/ttt';
30
- import { getCaptureResultSummary } from '../utils/captureResult';
30
+ import { getNgRawData, getSmartImageQualityState, isLowPhone } from '../utils/ttt';
31
31
  import { lensCount } from '../widgets/zoomTurntable/lensSkill';
32
- import { shouldRenderContent } from './absoluteContent';
33
32
  const AutoClarityOnly = _ref => {
34
33
  let {
35
34
  instance
@@ -185,13 +184,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
185
184
  isLowPhoneRef.current = !!res;
186
185
  });
187
186
  }, []);
188
-
189
- // 监听设备在线状态,离线提示展示时通知宿主;notifyOfflineShown 内部兼容没有该 TTT 方法的宿主。
190
- useEffect(() => {
191
- if (!deviceOnline) {
192
- notifyOfflineShown(devId);
193
- }
194
- }, [deviceOnline, devId]);
187
+ useOfflineShownNotification(devId, deviceOnline);
195
188
 
196
189
  // 展示顶部内容
197
190
  const [showTopContent, setShowTopContent] = useState(true);
@@ -693,16 +686,14 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
693
686
  ipcTTTOperatorLog('hide: 调用停止录制方法');
694
687
  setRecording(false, true);
695
688
  setIntercom(false, true);
696
- instance === null || instance === void 0 || instance.stopRecordingOnUnload().then(async result => {
697
- var _instance$multiLens, _instance$multiCamera;
698
- const summary = await getCaptureResultSummary(result, {
699
- multiLens: (_instance$multiLens = instance === null || instance === void 0 ? void 0 : instance.multiLens) !== null && _instance$multiLens !== void 0 ? _instance$multiLens : false,
700
- protocolCount: instance === null || instance === void 0 || (_instance$multiCamera = instance.multiCameraCtx) === null || _instance$multiCamera === void 0 || (_instance$multiCamera = _instance$multiCamera.protocol) === null || _instance$multiCamera === void 0 ? void 0 : _instance$multiCamera.total_split_num,
701
- devId
702
- });
703
- ipcTTTOperatorLog(summary !== null && summary !== void 0 && summary.isMultiLens ? `hide: stop recording succeeded with ${summary.count} files` : 'hide: 调用停止录制方法成功');
704
- }).catch(() => {
705
- ipcTTTOperatorLog('hide: 调用停止录制方法失败');
689
+ instance === null || instance === void 0 || instance.IPCPlayerInstance.stopRecord({
690
+ saveToAlbum: 1,
691
+ success: () => {
692
+ ipcTTTOperatorLog('hide: 调用停止录制方法成功');
693
+ },
694
+ fail: () => {
695
+ ipcTTTOperatorLog('hide: 调用停止录制方法失败');
696
+ }
706
697
  });
707
698
  ipcTTTOperatorLog('hide: 调用停止对讲方法');
708
699
  instance === null || instance === void 0 || instance.IPCPlayerInstance.stopTalk({
@@ -1164,17 +1155,17 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1164
1155
  // 这一下起,自动隐藏倒计时才开始生效
1165
1156
  hasUserTappedPlayerRef.current = true;
1166
1157
  if (instance.multiCameraCtx.isSupport) {
1167
- var _instance$multiCamera2, _instance$multiCamera3;
1168
- const preTapIndex = (_instance$multiCamera2 = (_instance$multiCamera3 = instance.multiCameraCtx.selectedLenInfoRef.current) === null || _instance$multiCamera3 === void 0 ? void 0 : _instance$multiCamera3.index) !== null && _instance$multiCamera2 !== void 0 ? _instance$multiCamera2 : prevSelectedIndexRef.current;
1158
+ var _instance$multiCamera, _instance$multiCamera2;
1159
+ const preTapIndex = (_instance$multiCamera = (_instance$multiCamera2 = instance.multiCameraCtx.selectedLenInfoRef.current) === null || _instance$multiCamera2 === void 0 ? void 0 : _instance$multiCamera2.index) !== null && _instance$multiCamera !== void 0 ? _instance$multiCamera : prevSelectedIndexRef.current;
1169
1160
  const wasHidden = componentHideState;
1170
1161
  instance.multiCameraCtx.selectVideoFiredRef.current = false;
1171
1162
  if (multiTapTimerRef.current) {
1172
1163
  clearTimeout(multiTapTimerRef.current);
1173
1164
  }
1174
1165
  multiTapTimerRef.current = setTimeout(() => {
1175
- var _instance$multiCamera4, _instance$multiCamera5;
1166
+ var _instance$multiCamera3, _instance$multiCamera4;
1176
1167
  const selectFired = !!instance.multiCameraCtx.selectVideoFiredRef.current;
1177
- const currentIndex = (_instance$multiCamera4 = (_instance$multiCamera5 = instance.multiCameraCtx.selectedLenInfoRef.current) === null || _instance$multiCamera5 === void 0 ? void 0 : _instance$multiCamera5.index) !== null && _instance$multiCamera4 !== void 0 ? _instance$multiCamera4 : preTapIndex;
1168
+ const currentIndex = (_instance$multiCamera3 = (_instance$multiCamera4 = instance.multiCameraCtx.selectedLenInfoRef.current) === null || _instance$multiCamera4 === void 0 ? void 0 : _instance$multiCamera4.index) !== null && _instance$multiCamera3 !== void 0 ? _instance$multiCamera3 : preTapIndex;
1178
1169
  if (selectFired && currentIndex === preTapIndex) {
1179
1170
  if (wasHidden) {
1180
1171
  showComponents();
@@ -1264,16 +1255,13 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1264
1255
  }, renderBottomRightContent))), (() => {
1265
1256
  if (!absoluteContent || !(absoluteContent !== null && absoluteContent !== void 0 && absoluteContent.length)) return null;
1266
1257
  return absoluteContent.map(item => {
1267
- if (!shouldRenderContent(item, {
1268
- playState
1269
- })) return null;
1270
- const contentProps = _objectSpread(_objectSpread(_objectSpread({
1271
- key: item.id
1272
- }, item.initProps), instance), {}, {
1273
- IPCPlayerContext: instance.IPCPlayerInstance
1274
- });
1258
+ if (item.hidden) return null;
1275
1259
  if (item.absoluteNoCoverView) {
1276
- return /*#__PURE__*/React.createElement(item.content, contentProps);
1260
+ return /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({
1261
+ key: item.id
1262
+ }, item.initProps), instance), {}, {
1263
+ IPCPlayerContext: instance.IPCPlayerInstance
1264
+ }));
1277
1265
  }
1278
1266
  return /*#__PURE__*/React.createElement(CoverView, {
1279
1267
  key: item.id,
@@ -1281,7 +1269,10 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1281
1269
  position: 'absolute'
1282
1270
  }, item.absolutePosition),
1283
1271
  className: item.absoluteContentClassName
1284
- }, /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread({}, contentProps), {}, {
1272
+ }, /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread(_objectSpread({
1273
+ key: item.id
1274
+ }, item.initProps), instance), {}, {
1275
+ IPCPlayerContext: instance.IPCPlayerInstance,
1285
1276
  // 添加通用变量单独组件类名
1286
1277
  className: clsx('absolute-item-container')
1287
1278
  })));
@@ -0,0 +1 @@
1
+ export declare function useOfflineShownNotification(deviceId: string, deviceOnline: boolean): void;
@@ -0,0 +1,32 @@
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 pageHiddenRef = useRef(false);
14
+ useEffect(() => {
15
+ if (!pageHiddenRef.current && !deviceOnline) {
16
+ notifyOfflineShown(deviceId);
17
+ }
18
+ }, [deviceId, deviceOnline]);
19
+ usePageEvent('onHide', () => {
20
+ pageHiddenRef.current = true;
21
+ });
22
+ usePageEvent('onShow', () => {
23
+ pageHiddenRef.current = false;
24
+ const {
25
+ deviceId: currentDeviceId,
26
+ deviceOnline: isOnline
27
+ } = latestDeviceRef.current;
28
+ if (!isOnline) {
29
+ notifyOfflineShown(currentDeviceId);
30
+ }
31
+ });
32
+ }
@@ -0,0 +1,98 @@
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 on initial offline state and on every onShow while offline', () => {
22
+ renderHook(() => useOfflineShownNotification('camera-1', false));
23
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
24
+ act(() => mockPageEventHandlers.onShow());
25
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
26
+ act(() => mockPageEventHandlers.onShow());
27
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
28
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-1');
29
+ });
30
+ it('uses the latest online state and device id on every onShow', () => {
31
+ const {
32
+ rerender
33
+ } = renderHook(_ref => {
34
+ let {
35
+ deviceId,
36
+ deviceOnline
37
+ } = _ref;
38
+ return useOfflineShownNotification(deviceId, deviceOnline);
39
+ }, {
40
+ initialProps: {
41
+ deviceId: 'camera-1',
42
+ deviceOnline: false
43
+ }
44
+ });
45
+ rerender({
46
+ deviceId: 'camera-2',
47
+ deviceOnline: true
48
+ });
49
+ act(() => mockPageEventHandlers.onShow());
50
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
51
+ rerender({
52
+ deviceId: 'camera-2',
53
+ deviceOnline: false
54
+ });
55
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
56
+ act(() => mockPageEventHandlers.onShow());
57
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
58
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
59
+ });
60
+ it('does not notify for offline updates while the page is hidden', () => {
61
+ const {
62
+ rerender
63
+ } = renderHook(_ref2 => {
64
+ let {
65
+ deviceId,
66
+ deviceOnline
67
+ } = _ref2;
68
+ return useOfflineShownNotification(deviceId, deviceOnline);
69
+ }, {
70
+ initialProps: {
71
+ deviceId: 'camera-1',
72
+ deviceOnline: true
73
+ }
74
+ });
75
+ act(() => mockPageEventHandlers.onHide());
76
+ rerender({
77
+ deviceId: 'camera-1',
78
+ deviceOnline: false
79
+ });
80
+ rerender({
81
+ deviceId: 'camera-2',
82
+ deviceOnline: false
83
+ });
84
+ expect(notifyOfflineShown).not.toHaveBeenCalled();
85
+ act(() => mockPageEventHandlers.onShow());
86
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
87
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
88
+ rerender({
89
+ deviceId: 'camera-2',
90
+ deviceOnline: true
91
+ });
92
+ rerender({
93
+ deviceId: 'camera-2',
94
+ deviceOnline: false
95
+ });
96
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
97
+ });
98
+ });
package/lib/utils/ttt.js CHANGED
@@ -135,8 +135,11 @@ export function notifyOfflineShown(deviceId) {
135
135
  return false;
136
136
  }
137
137
  try {
138
- console.warn('res===notifyOfflineShown');
139
- method(deviceId, 'preview_mini');
138
+ console.warn('res===notifyOfflineShown', deviceId);
139
+ method({
140
+ deviceId,
141
+ scene: 'preview_mini'
142
+ });
140
143
  return true;
141
144
  } catch (error) {
142
145
  return false;