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

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/ctx.js CHANGED
@@ -10,9 +10,10 @@ import { ensureAlbumPermission } from '../utils/authorize/album';
10
10
  import { useAtom, updateAtom, getDefaultStore, useStore } from './store';
11
11
  import { PlayState, IntercomMode } from '../interface';
12
12
  import { changeIgnoreHideStopPreview } from '../ui/constant';
13
- import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
14
13
  import { getEventInstance } from './event';
15
14
  import { isMultiCameraTileSupported, useMultiCameraCtx } from './multiCameraCtx';
15
+ import { toNativeClarity, withAutoClarity } from './resolution';
16
+ import { useAutoClarity } from './useAutoClarity';
16
17
  const SAVE_TO_ALBUM = 1;
17
18
  export const createUseCtx = _ref => {
18
19
  let {
@@ -73,6 +74,8 @@ export const createUseCtx = _ref => {
73
74
  const [resolution] = useAtom('HD');
74
75
  // resolution 清晰度列表
75
76
  const [resolutionList, setResolutionList] = useAtom([]);
77
+ // 自动模式下宿主上报的实际清晰度,供横竖屏码率区域共用
78
+ const [autoClarity] = useAtom(null);
76
79
 
77
80
  // 单向对讲还是双向对讲
78
81
  const [intercomMode, setIntercomMode] = useAtom(IntercomMode.TwoWay);
@@ -100,9 +103,22 @@ export const createUseCtx = _ref => {
100
103
  const [bottomRightContent] = useAtom(initBottomRightContent || defaultBottomRightContent || []);
101
104
  const [absoluteContent] = useAtom(initAbsoluteContent || defaultAbsoluteContent || []);
102
105
  const {
103
- _playState
106
+ _playState,
107
+ currentResolution
104
108
  } = useStore({
105
- _playState: playState
109
+ _playState: playState,
110
+ currentResolution: resolution
111
+ });
112
+ const {
113
+ restoreResolution,
114
+ prepareResolutionSelection,
115
+ finishResolutionSelection,
116
+ refreshAfterPlayback
117
+ } = useAutoClarity({
118
+ devId,
119
+ autoClarity,
120
+ resolution,
121
+ playerRef: IPCPlayerInstance
106
122
  });
107
123
  const eventRef = useRef();
108
124
  if (!eventRef.current) {
@@ -116,8 +132,8 @@ export const createUseCtx = _ref => {
116
132
  try {
117
133
  var _res$maxZoomSettings;
118
134
  const res = await getMemoryState(devId);
119
- setResolutionList(res.resolutionList);
120
- _setResolution(res.resolution, true);
135
+ setResolutionList(withAutoClarity(res.resolutionList));
136
+ restoreResolution(res.resolution, res.resolutionList, _setResolution);
121
137
  _setMute(res.mute, true);
122
138
  setIntercomMode(res.intercomMode);
123
139
  setIntercomSupported(res.isIntercomSupported);
@@ -132,9 +148,9 @@ export const createUseCtx = _ref => {
132
148
  // 获取缓存的值且同步
133
149
  getMemoryState(devId).then(res => {
134
150
  var _res$maxZoomSettings2;
135
- setResolutionList(res.resolutionList);
151
+ setResolutionList(withAutoClarity(res.resolutionList));
136
152
  // 传true表示值即可,会取播放器的值
137
- _setResolution(res.resolution, true);
153
+ restoreResolution(res.resolution, res.resolutionList, _setResolution);
138
154
  _setMute(res.mute, true);
139
155
  setIntercomMode(res.intercomMode);
140
156
  setIntercomSupported(res.isIntercomSupported);
@@ -142,6 +158,9 @@ export const createUseCtx = _ref => {
142
158
  });
143
159
  }
144
160
  }, [devId, _playState]);
161
+ useEffect(() => {
162
+ refreshAfterPlayback(_playState, currentResolution);
163
+ }, [devId, _playState, currentResolution]);
145
164
  // 获取content数据
146
165
  const getContent = () => {
147
166
  const store = getDefaultStore();
@@ -236,15 +255,18 @@ export const createUseCtx = _ref => {
236
255
  updateAtom(resolution, target);
237
256
  return false;
238
257
  }
258
+ prepareResolutionSelection(target);
239
259
  return new Promise((resolve, reject) => {
240
260
  IPCPlayerInstance.current.setClarity({
241
- clarity: target === ClarityType.HD ? 'hd' : 'normal',
261
+ clarity: toNativeClarity(target),
242
262
  success: () => {
263
+ finishResolutionSelection();
243
264
  setResolutionMemoryState(devId, target);
244
265
  updateAtom(resolution, target);
245
266
  resolve(true);
246
267
  },
247
268
  fail: err => {
269
+ finishResolutionSelection();
248
270
  console.log(err, 'setClarity err');
249
271
  // updateAtom(mute, !target);
250
272
  reject(err);
@@ -271,6 +293,7 @@ export const createUseCtx = _ref => {
271
293
  mute,
272
294
  resolution,
273
295
  resolutionList,
296
+ autoClarity,
274
297
  intercom,
275
298
  intercomMode,
276
299
  intercomSupported,
@@ -0,0 +1,8 @@
1
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
2
+ type NativeClarity = Parameters<IpcContext['setClarity']>[0]['clarity'];
3
+ export declare const toNativeClarity: (clarity: ClarityType) => NativeClarity;
4
+ /** 宿主支持自动清晰度,且返回至少两个档位时才展示 AUTO。 */
5
+ export declare const canShowAutoClarity: (list?: ClarityType[]) => boolean;
6
+ export declare const withAutoClarity: (list?: ClarityType[]) => ClarityType[];
7
+ export declare const normalizeResolution: (resolution: ClarityType, list: ClarityType[]) => ClarityType;
8
+ export {};
@@ -0,0 +1,30 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.filter.js";
3
+ import "core-js/modules/esnext.iterator.find.js";
4
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
5
+ import { isClarityChangedSupported } from '../utils/ttt';
6
+ const clarityMap = {
7
+ [ClarityType.SS]: 'ss',
8
+ [ClarityType.SD]: 'normal',
9
+ [ClarityType.HD]: 'hd',
10
+ [ClarityType.UD]: 'ud',
11
+ [ClarityType.SSP]: 'ssp',
12
+ [ClarityType.AUTO]: 'auto',
13
+ [ClarityType.AUDIO]: 'audio'
14
+ };
15
+ export const toNativeClarity = clarity => clarityMap[clarity] || 'normal';
16
+
17
+ /** 宿主支持自动清晰度,且返回至少两个档位时才展示 AUTO。 */
18
+ export const canShowAutoClarity = function () {
19
+ let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
20
+ return isClarityChangedSupported() && list.length >= 2;
21
+ };
22
+ export const withAutoClarity = function () {
23
+ let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
24
+ const withoutAuto = list.filter(clarity => clarity !== ClarityType.AUTO);
25
+ return canShowAutoClarity(list) ? [...withoutAuto, ClarityType.AUTO] : withoutAuto;
26
+ };
27
+ export const normalizeResolution = (resolution, list) => {
28
+ if (resolution !== ClarityType.AUTO || canShowAutoClarity(list)) return resolution;
29
+ return list.find(clarity => clarity !== ClarityType.AUTO) || ClarityType.HD;
30
+ };
@@ -0,0 +1,19 @@
1
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
2
+ import { PlayState, RetAtom } from '../interface';
3
+ type Options = {
4
+ devId: string;
5
+ autoClarity: RetAtom<ClarityType | null>;
6
+ resolution: RetAtom<string>;
7
+ playerRef: {
8
+ current?: IpcContext;
9
+ };
10
+ };
11
+ type SetResolution = (target: ClarityType, onlyUpdateAtom: boolean) => Promise<boolean>;
12
+ type AutoClarityActions = {
13
+ restoreResolution: (cachedResolution: ClarityType, list: ClarityType[], setResolution: SetResolution) => void;
14
+ prepareResolutionSelection: (target: ClarityType) => void;
15
+ finishResolutionSelection: () => void;
16
+ refreshAfterPlayback: (playState: PlayState, currentResolution: string) => void;
17
+ };
18
+ export declare const useAutoClarity: ({ devId, autoClarity, resolution, playerRef, }: Options) => AutoClarityActions;
19
+ export {};
@@ -0,0 +1,73 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
3
+ import { getDefaultStore, updateAtom } from './store';
4
+ import { normalizeResolution } from './resolution';
5
+ import { PlayState } from '../interface';
6
+ import { getCachedAutoClarity, setCachedAutoClarity, subscribeClarityChanged } from '../utils/ttt';
7
+ export const useAutoClarity = _ref => {
8
+ let {
9
+ devId,
10
+ autoClarity,
11
+ resolution,
12
+ playerRef
13
+ } = _ref;
14
+ const restoredAutoRef = useRef(false);
15
+ const refreshedAutoRef = useRef(false);
16
+ const freshAutoClarityRef = useRef(false);
17
+ const pendingAutoSelectionRef = useRef(false);
18
+ const userSelectedResolutionRef = useRef(false);
19
+ useEffect(() => {
20
+ updateAtom(autoClarity, null);
21
+ restoredAutoRef.current = false;
22
+ refreshedAutoRef.current = false;
23
+ freshAutoClarityRef.current = false;
24
+ userSelectedResolutionRef.current = false;
25
+ if (!devId) return undefined;
26
+ return subscribeClarityChanged(devId, res => {
27
+ if (getDefaultStore().get(resolution) !== ClarityType.AUTO && !pendingAutoSelectionRef.current) {
28
+ return;
29
+ }
30
+ freshAutoClarityRef.current = true;
31
+ updateAtom(autoClarity, res.clarity);
32
+ setCachedAutoClarity(devId, res.clarity);
33
+ });
34
+ }, [autoClarity, devId, resolution]);
35
+ return {
36
+ restoreResolution: (cachedResolution, list, setResolution) => {
37
+ if (userSelectedResolutionRef.current) return;
38
+ const target = normalizeResolution(cachedResolution, list);
39
+ if (target === ClarityType.AUTO) {
40
+ restoredAutoRef.current = true;
41
+ const cachedClarity = getCachedAutoClarity(devId);
42
+ if (cachedClarity && list.includes(cachedClarity) && !getDefaultStore().get(autoClarity)) {
43
+ updateAtom(autoClarity, cachedClarity);
44
+ }
45
+ }
46
+ setResolution(target, true);
47
+ },
48
+ prepareResolutionSelection: target => {
49
+ userSelectedResolutionRef.current = true;
50
+ // 清晰度事件可能在 setClarity 的 success 回调前到达,进入自动前先清掉上次的值。
51
+ restoredAutoRef.current = false;
52
+ if (target === ClarityType.AUTO) {
53
+ pendingAutoSelectionRef.current = true;
54
+ updateAtom(autoClarity, null);
55
+ }
56
+ },
57
+ finishResolutionSelection: () => {
58
+ pendingAutoSelectionRef.current = false;
59
+ },
60
+ refreshAfterPlayback: (playState, currentResolution) => {
61
+ var _playerRef$current;
62
+ if (!devId || playState !== PlayState.PLAYING || currentResolution !== ClarityType.AUTO || !restoredAutoRef.current || freshAutoClarityRef.current || refreshedAutoRef.current) {
63
+ return;
64
+ }
65
+ refreshedAutoRef.current = true;
66
+ // 缓存只保证首屏有上次档位;出流后重申自动,让宿主回报本次实际档位。
67
+ (_playerRef$current = playerRef.current) === null || _playerRef$current === void 0 || _playerRef$current.setClarity({
68
+ clarity: 'auto',
69
+ fail: error => console.warn('res===restore auto clarity fail', error)
70
+ });
71
+ }
72
+ };
73
+ };
@@ -1,8 +1,13 @@
1
1
  import { kit } from '@ray-js/panel-sdk';
2
2
  declare const Strings: kit.I18N<{
3
3
  en: {
4
+ ipc_player_resolution_SS: string;
4
5
  ipc_player_resolution_HD: string;
5
6
  ipc_player_resolution_SD: string;
7
+ ipc_player_resolution_UD: string;
8
+ ipc_player_resolution_SSP: string;
9
+ ipc_player_resolution_AUTO: string;
10
+ ipc_player_resolution_AUDIO: string;
6
11
  ipc_player_current_resolution_is_equal: string;
7
12
  ipc_player_screenshot_success_tip: string;
8
13
  ipc_player_error_screenshot_error_tip: string;
@@ -38,8 +43,13 @@ declare const Strings: kit.I18N<{
38
43
  ipc_player_low_phone_not_support: string;
39
44
  };
40
45
  zh: {
46
+ ipc_player_resolution_SS: string;
41
47
  ipc_player_resolution_HD: string;
42
48
  ipc_player_resolution_SD: string;
49
+ ipc_player_resolution_UD: string;
50
+ ipc_player_resolution_SSP: string;
51
+ ipc_player_resolution_AUTO: string;
52
+ ipc_player_resolution_AUDIO: string;
43
53
  ipc_player_current_resolution_is_equal: string;
44
54
  ipc_player_screenshot_success_tip: string;
45
55
  ipc_player_error_screenshot_error_tip: string;
@@ -75,8 +85,13 @@ declare const Strings: kit.I18N<{
75
85
  ipc_player_low_phone_not_support: string;
76
86
  };
77
87
  }, {
88
+ ipc_player_resolution_SS: string;
78
89
  ipc_player_resolution_HD: string;
79
90
  ipc_player_resolution_SD: string;
91
+ ipc_player_resolution_UD: string;
92
+ ipc_player_resolution_SSP: string;
93
+ ipc_player_resolution_AUTO: string;
94
+ ipc_player_resolution_AUDIO: string;
80
95
  ipc_player_current_resolution_is_equal: string;
81
96
  ipc_player_screenshot_success_tip: string;
82
97
  ipc_player_error_screenshot_error_tip: string;
@@ -111,8 +126,13 @@ declare const Strings: kit.I18N<{
111
126
  ipc_player_fetch_error: string;
112
127
  ipc_player_low_phone_not_support: string;
113
128
  } | {
129
+ ipc_player_resolution_SS: string;
114
130
  ipc_player_resolution_HD: string;
115
131
  ipc_player_resolution_SD: string;
132
+ ipc_player_resolution_UD: string;
133
+ ipc_player_resolution_SSP: string;
134
+ ipc_player_resolution_AUTO: string;
135
+ ipc_player_resolution_AUDIO: string;
116
136
  ipc_player_current_resolution_is_equal: string;
117
137
  ipc_player_screenshot_success_tip: string;
118
138
  ipc_player_error_screenshot_error_tip: string;
@@ -1,7 +1,12 @@
1
1
  declare const _default: {
2
2
  en: {
3
+ ipc_player_resolution_SS: string;
3
4
  ipc_player_resolution_HD: string;
4
5
  ipc_player_resolution_SD: string;
6
+ ipc_player_resolution_UD: string;
7
+ ipc_player_resolution_SSP: string;
8
+ ipc_player_resolution_AUTO: string;
9
+ ipc_player_resolution_AUDIO: string;
5
10
  ipc_player_current_resolution_is_equal: string;
6
11
  ipc_player_screenshot_success_tip: string;
7
12
  ipc_player_error_screenshot_error_tip: string;
@@ -37,8 +42,13 @@ declare const _default: {
37
42
  ipc_player_low_phone_not_support: string;
38
43
  };
39
44
  zh: {
45
+ ipc_player_resolution_SS: string;
40
46
  ipc_player_resolution_HD: string;
41
47
  ipc_player_resolution_SD: string;
48
+ ipc_player_resolution_UD: string;
49
+ ipc_player_resolution_SSP: string;
50
+ ipc_player_resolution_AUTO: string;
51
+ ipc_player_resolution_AUDIO: string;
42
52
  ipc_player_current_resolution_is_equal: string;
43
53
  ipc_player_screenshot_success_tip: string;
44
54
  ipc_player_error_screenshot_error_tip: string;
@@ -1,7 +1,12 @@
1
1
  export default {
2
2
  en: {
3
+ ipc_player_resolution_SS: 'Data Saver',
3
4
  ipc_player_resolution_HD: 'HD',
4
5
  ipc_player_resolution_SD: 'SD',
6
+ ipc_player_resolution_UD: 'Ultra HD',
7
+ ipc_player_resolution_SSP: 'Super Ultra HD',
8
+ ipc_player_resolution_AUTO: 'Auto',
9
+ ipc_player_resolution_AUDIO: 'Audio Mode',
5
10
  ipc_player_current_resolution_is_equal: 'Already at current clarity',
6
11
  ipc_player_screenshot_success_tip: 'Screenshot saved to album',
7
12
  ipc_player_error_screenshot_error_tip: 'Screenshot failed. Please try again later.',
@@ -37,8 +42,13 @@ export default {
37
42
  ipc_player_low_phone_not_support: 'This feature is not supported on this device'
38
43
  },
39
44
  zh: {
45
+ ipc_player_resolution_SS: '省流量',
40
46
  ipc_player_resolution_HD: '高清',
41
47
  ipc_player_resolution_SD: '标清',
48
+ ipc_player_resolution_UD: '超清',
49
+ ipc_player_resolution_SSP: '超超清',
50
+ ipc_player_resolution_AUTO: '自动',
51
+ ipc_player_resolution_AUDIO: '音频模式',
42
52
  ipc_player_current_resolution_is_equal: '已是当前清晰度',
43
53
  ipc_player_screenshot_success_tip: '截图已保存在APP相册',
44
54
  ipc_player_error_screenshot_error_tip: '截图失败了,请稍后再试',
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { PrimitiveAtom } from 'jotai';
3
+ import type { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
3
4
  import type { Toast, IntercomMode } from './ports.output';
4
5
  import { useMultiCameraCtx } from './ctx/multiCameraCtx';
5
6
  import type { ZoomSkill } from './widgets/zoomTurntable/lensSkill';
@@ -72,6 +73,7 @@ export type UseCtx = (options: {
72
73
  setZoomLensIndex: (value: number) => void;
73
74
  resolution: RetAtom<string>;
74
75
  resolutionList: RetAtom<string[]>;
76
+ autoClarity: RetAtom<ClarityType | null>;
75
77
  playState: RetAtom<PlayState>;
76
78
  IPCPlayerInstance: IpcContext;
77
79
  topLeftContent: RetAtom<ComponentConfig[]>;
@@ -85,7 +87,7 @@ export type UseCtx = (options: {
85
87
  setVerticalMic: (value: boolean) => void;
86
88
  setScreenType: (type: ScreenType) => void;
87
89
  setRecordingDisabled: (type: boolean) => void;
88
- setResolution: (type: string) => void;
90
+ setResolution: (type: string) => Promise<boolean>;
89
91
  setResolutionList: (type: string[]) => void;
90
92
  setRecording: (value: boolean, onlyUpdateAtom?: boolean) => Promise<RecordInfoData>;
91
93
  setIntercom: (value: boolean, onlyUpdateAtom?: boolean) => Promise<boolean>;
package/lib/ui/ui.js CHANGED
@@ -1,14 +1,17 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
3
  import "core-js/modules/esnext.iterator.constructor.js";
3
4
  import "core-js/modules/esnext.iterator.filter.js";
4
5
  import "core-js/modules/esnext.iterator.find.js";
5
6
  import "core-js/modules/esnext.iterator.map.js";
7
+ import "core-js/modules/esnext.iterator.some.js";
6
8
  import React, { useContext, useState, useRef, useMemo, useEffect, useImperativeHandle } from 'react';
7
9
  import { View, CoverView, getSystemInfoSync, usePageEvent, setNavigationBarBack, setPageOrientation, getCurrentPages } from '@ray-js/ray';
8
10
  import { unstable_batchedUpdates as batchedUpdates } from '@ray-core/ray';
9
11
  import clsx from 'clsx';
10
12
  import IPCPlayer from '@ray-js/ray-ipc-player';
11
13
  import { ipcTTTOperatorLog } from '@ray-js/ray-ipc-utils';
14
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
12
15
  import { PlayState, PlayerStreamStatus, MultiCameraScreenMode } from '../interface';
13
16
  import { useCtx } from '../ctx/ctx.composition';
14
17
  import { useStore, updateAtom, getDefaultStore } from '../ctx/store';
@@ -18,13 +21,44 @@ import BottomLeftContent from './bottomLeftContent';
18
21
  import BottomRightContent from './bottomRightContent';
19
22
  import TopLeftContent from './topLeftContent';
20
23
  import TopRightContent from './topRightContent';
21
- import { FlowLowTip } from '../widgets';
24
+ import { useOfflineShownNotification } from './useOfflineShownNotification';
25
+ import { FlowLowTip, VideoBitKBP } from '../widgets';
22
26
  import { useMemoizedFn } from '../hooks';
23
27
  import { Storage } from '../utils/storage';
24
28
  import './ui.less';
25
29
  import { updatePlayerWidgetProps } from '../features';
26
30
  import { getNgRawData, getSmartImageQualityState, isLowPhone } from '../utils/ttt';
27
31
  import { lensCount } from '../widgets/zoomTurntable/lensSkill';
32
+ const AutoClarityOnly = _ref => {
33
+ let {
34
+ instance
35
+ } = _ref;
36
+ return /*#__PURE__*/React.createElement(VideoBitKBP, _extends({}, instance, {
37
+ IPCPlayerContext: instance.IPCPlayerInstance,
38
+ className: "top-right-item-container",
39
+ hideKbsMenu: true,
40
+ hideSignalMenu: true
41
+ }));
42
+ };
43
+ const StandaloneAutoClarity = _ref2 => {
44
+ let {
45
+ instance,
46
+ show
47
+ } = _ref2;
48
+ const {
49
+ resolution,
50
+ autoClarity
51
+ } = useStore({
52
+ resolution: instance.resolution,
53
+ autoClarity: instance.autoClarity
54
+ });
55
+ if (!show || resolution !== ClarityType.AUTO || !autoClarity) return null;
56
+ return /*#__PURE__*/React.createElement(TopRightContent, {
57
+ ctx: instance
58
+ }, /*#__PURE__*/React.createElement(AutoClarityOnly, {
59
+ instance: instance
60
+ }));
61
+ };
28
62
  function getCtxInstance(instance, devId) {
29
63
  if (instance) return instance;
30
64
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -150,6 +184,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
150
184
  isLowPhoneRef.current = !!res;
151
185
  });
152
186
  }, []);
187
+ useOfflineShownNotification(devId, deviceOnline);
153
188
 
154
189
  // 展示顶部内容
155
190
  const [showTopContent, setShowTopContent] = useState(true);
@@ -1002,6 +1037,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1002
1037
  };
1003
1038
  }, []);
1004
1039
  const playerReady = playState === PlayState.PLAYING;
1040
+ const hasVisibleBitrateWidget = topRightContent === null || topRightContent === void 0 ? void 0 : topRightContent.some(item => item.id === 'VideoBitKBP' && !item.hidden);
1005
1041
  /**
1006
1042
  * 监听当前的zoom比例状态
1007
1043
  */
@@ -1195,7 +1231,12 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
1195
1231
  ctx: instance
1196
1232
  }, renderTopLeftContent), /*#__PURE__*/React.createElement(TopRightContent, {
1197
1233
  ctx: instance
1198
- }, renderTopRightContent))), /*#__PURE__*/React.createElement(View, {
1234
+ }, renderTopRightContent, !hasVisibleBitrateWidget && /*#__PURE__*/React.createElement(AutoClarityOnly, {
1235
+ instance: instance
1236
+ })))), /*#__PURE__*/React.createElement(StandaloneAutoClarity, {
1237
+ instance: instance,
1238
+ show: !showTopContent || componentHideState || !playerReady
1239
+ }), /*#__PURE__*/React.createElement(View, {
1199
1240
  className: clsx('ipc-player-bottom-content', {
1200
1241
  'ipc-player-bottom-content-hide': componentHideState,
1201
1242
  'ipc-player-bottom-content-show': !componentHideState,
@@ -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
+ }
@@ -1,3 +1,4 @@
1
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
1
2
  export type SmartImageQualityResult = {
2
3
  isPurchase: boolean;
3
4
  buttonState: number;
@@ -38,4 +39,29 @@ export declare function getAIFrameFeature(devId: string): Promise<GetAIFrameFeat
38
39
  export declare function setAIFrameFeature(params: SetAIFrameFeatureParams): Promise<any>;
39
40
  export declare function setTrailFinish(devId: string): Promise<unknown>;
40
41
  export declare function isLowPhone(): Promise<boolean>;
42
+ /**
43
+ * 通知宿主离线提示已经展示。
44
+ *
45
+ * 这个 TTT 方法不是所有宿主都提供,因此调用前必须做能力判断;
46
+ * 老宿主或 Web 环境下直接跳过,不能影响播放器自身的离线处理。
47
+ */
48
+ export declare function notifyOfflineShown(deviceId: string): boolean;
41
49
  export declare function getNgRawData(): Promise<unknown>;
50
+ export declare function isClarityChangedSupported(): boolean;
51
+ export type ClarityChangedResult = {
52
+ deviceId?: string;
53
+ clarity: ClarityType;
54
+ };
55
+ export type ClarityChangedHandler = (result: ClarityChangedResult) => void;
56
+ type ClarityChangedListener = (payload: ClarityChangedResult) => void;
57
+ export declare function getCachedAutoClarity(devId: string): ClarityType | null;
58
+ export declare function setCachedAutoClarity(devId: string, clarity: ClarityType): void;
59
+ export declare function offClarityChanged(listener: ClarityChangedListener): void;
60
+ /**
61
+ * 监听自动清晰度变化,返回取消监听函数。
62
+ *
63
+ * onClarityChanged / offClarityChanged 均使用同一个 listener 引用,
64
+ * 否则宿主无法正确移除监听。
65
+ */
66
+ export declare function subscribeClarityChanged(devId: string, handler: ClarityChangedHandler): () => void;
67
+ export {};
package/lib/utils/ttt.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
2
3
  export function getSmartImageQualityState(devId) {
3
4
  return new Promise(resolve => {
4
5
  var _ty$ipc;
@@ -120,10 +121,34 @@ export function isLowPhone() {
120
121
  }
121
122
  });
122
123
  }
124
+
125
+ /**
126
+ * 通知宿主离线提示已经展示。
127
+ *
128
+ * 这个 TTT 方法不是所有宿主都提供,因此调用前必须做能力判断;
129
+ * 老宿主或 Web 环境下直接跳过,不能影响播放器自身的离线处理。
130
+ */
131
+ export function notifyOfflineShown(deviceId) {
132
+ var _ty3;
133
+ const method = typeof ty !== 'undefined' ? (_ty3 = ty) === null || _ty3 === void 0 || (_ty3 = _ty3.ipc) === null || _ty3 === void 0 ? void 0 : _ty3.notifyOfflineShown : undefined;
134
+ if (typeof method !== 'function') {
135
+ return false;
136
+ }
137
+ try {
138
+ console.warn('res===notifyOfflineShown', deviceId);
139
+ method({
140
+ deviceId,
141
+ scene: 'preview_mini'
142
+ });
143
+ return true;
144
+ } catch (error) {
145
+ return false;
146
+ }
147
+ }
123
148
  export function getNgRawData() {
124
149
  return new Promise(resolve => {
125
- var _ty3;
126
- const isSupport = typeof ((_ty3 = ty) === null || _ty3 === void 0 ? void 0 : _ty3.getNgRawData) === 'function';
150
+ var _ty4;
151
+ const isSupport = typeof ((_ty4 = ty) === null || _ty4 === void 0 ? void 0 : _ty4.getNgRawData) === 'function';
127
152
  if (!isSupport) {
128
153
  resolve(false);
129
154
  return;
@@ -142,4 +167,89 @@ export function getNgRawData() {
142
167
  resolve(false);
143
168
  }
144
169
  });
170
+ }
171
+
172
+ // 是否支持自动清晰度(ttt 方法 onClarityChanged 存在即支持)
173
+ export function isClarityChangedSupported() {
174
+ var _ty5;
175
+ return typeof ty !== 'undefined' && typeof ((_ty5 = ty) === null || _ty5 === void 0 || (_ty5 = _ty5.ipc) === null || _ty5 === void 0 ? void 0 : _ty5.onClarityChanged) === 'function';
176
+ }
177
+ const actualClarityTypes = [ClarityType.SS, ClarityType.SD, ClarityType.HD, ClarityType.UD, ClarityType.SSP];
178
+ const autoClarityStorageKey = devId => `${devId}_auto_clarity`;
179
+ export function getCachedAutoClarity(devId) {
180
+ try {
181
+ const stored = ty.getStorageSync({
182
+ key: autoClarityStorageKey(devId)
183
+ });
184
+ const clarity = typeof stored === 'string' ? stored : stored === null || stored === void 0 ? void 0 : stored.data;
185
+ return actualClarityTypes.includes(clarity) ? clarity : null;
186
+ } catch (error) {
187
+ return null;
188
+ }
189
+ }
190
+ export function setCachedAutoClarity(devId, clarity) {
191
+ if (!actualClarityTypes.includes(clarity)) return;
192
+ try {
193
+ ty.setStorageSync({
194
+ key: autoClarityStorageKey(devId),
195
+ data: clarity
196
+ });
197
+ } catch (error) {
198
+ console.warn('res===setCachedAutoClarity fail', error);
199
+ }
200
+ }
201
+ export function offClarityChanged(listener) {
202
+ var _ty6;
203
+ const ipc = typeof ty !== 'undefined' ? (_ty6 = ty) === null || _ty6 === void 0 ? void 0 : _ty6.ipc : undefined;
204
+ if (!ipc || typeof ipc.offClarityChanged !== 'function') {
205
+ return;
206
+ }
207
+ try {
208
+ ipc.offClarityChanged(listener);
209
+ } catch (error) {
210
+ console.warn('res===offClarityChanged fail', error);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * 监听自动清晰度变化,返回取消监听函数。
216
+ *
217
+ * onClarityChanged / offClarityChanged 均使用同一个 listener 引用,
218
+ * 否则宿主无法正确移除监听。
219
+ */
220
+ export function subscribeClarityChanged(devId, handler) {
221
+ var _ty7;
222
+ const ipc = typeof ty !== 'undefined' ? (_ty7 = ty) === null || _ty7 === void 0 ? void 0 : _ty7.ipc : undefined;
223
+ if (!ipc || typeof ipc.onClarityChanged !== 'function') {
224
+ return () => undefined;
225
+ }
226
+ const listener = payload => {
227
+ console.log('[resolution] onClarityChanged 事件到达', JSON.stringify(payload !== null && payload !== void 0 ? payload : null));
228
+ const {
229
+ deviceId,
230
+ clarity
231
+ } = payload || {};
232
+ if (!actualClarityTypes.includes(clarity)) {
233
+ console.warn('[resolution] onClarityChanged 未返回实际清晰度');
234
+ return;
235
+ }
236
+ // 一页多设备时只认自己的;宿主没带 deviceId 就不过滤
237
+ if (deviceId && deviceId !== devId) {
238
+ console.warn('[resolution] onClarityChanged 非本设备,已忽略', `${deviceId} != ${devId}`);
239
+ return;
240
+ }
241
+ handler({
242
+ deviceId,
243
+ clarity
244
+ });
245
+ };
246
+ try {
247
+ ipc.onClarityChanged(listener);
248
+ } catch (error) {
249
+ console.warn('res===onClarityChanged fail', error);
250
+ return () => undefined;
251
+ }
252
+ return () => {
253
+ offClarityChanged(listener);
254
+ };
145
255
  }
@@ -11,7 +11,6 @@ import { useStore } from '../../ctx/store';
11
11
  import './resolution.less';
12
12
  export const Resolution = props => {
13
13
  const {
14
- IPCPlayerContext,
15
14
  setResolution,
16
15
  addContent,
17
16
  hasContent,
@@ -2,9 +2,11 @@ import React, { useEffect, useRef, useState } from 'react';
2
2
  import { View, Text, usePageEvent } from '@ray-js/ray';
3
3
  import clsx from 'clsx';
4
4
  import { getVideoBitrateKbps, requestWifiSignal } from '@ray-js/ray-ipc-utils';
5
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
5
6
  import { PlayState } from '../../interface';
6
7
  import './videoBitKBP.less';
7
8
  import { useStore } from '../../ctx/store';
9
+ import Strings from '../../i18n';
8
10
  export const VideoBitKBP = props => {
9
11
  const {
10
12
  devId,
@@ -16,7 +18,9 @@ export const VideoBitKBP = props => {
16
18
  const [bitKBP, setBitKBP] = useState('');
17
19
  const [signalStrength, setSignalStrength] = useState(null);
18
20
  const store = useStore({
19
- playState
21
+ playState,
22
+ resolution: props.resolution,
23
+ autoClarity: props.autoClarity
20
24
  });
21
25
  const timerRef = useRef();
22
26
  useEffect(() => {
@@ -52,12 +56,34 @@ export const VideoBitKBP = props => {
52
56
  }
53
57
  }
54
58
  };
55
- const hasKbps = !hideKbsMenu && bitKBP !== '' && bitKBP !== '0';
56
- const hasSignal = !hideSignalMenu && signalStrength !== null;
57
- if (!hasKbps && !hasSignal || store.playState !== PlayState.PLAYING) {
59
+ const isPlaying = store.playState === PlayState.PLAYING;
60
+ const hasKbps = isPlaying && !hideKbsMenu && bitKBP !== '' && bitKBP !== '0';
61
+ const hasSignal = isPlaying && !hideSignalMenu && signalStrength !== null;
62
+ const activeClarity = store.resolution === ClarityType.AUTO ? store.autoClarity : null;
63
+ const hasClarity = Boolean(activeClarity);
64
+ const bitrateLabel = [activeClarity ? (clarity => {
65
+ switch (clarity) {
66
+ case ClarityType.SS:
67
+ return Strings.getLang('ipc_player_resolution_SS');
68
+ case ClarityType.SD:
69
+ return Strings.getLang('ipc_player_resolution_SD');
70
+ case ClarityType.HD:
71
+ return Strings.getLang('ipc_player_resolution_HD');
72
+ case ClarityType.UD:
73
+ return Strings.getLang('ipc_player_resolution_UD');
74
+ case ClarityType.SSP:
75
+ return Strings.getLang('ipc_player_resolution_SSP');
76
+ case ClarityType.AUTO:
77
+ return Strings.getLang('ipc_player_resolution_AUTO');
78
+ case ClarityType.AUDIO:
79
+ return Strings.getLang('ipc_player_resolution_AUDIO');
80
+ default:
81
+ return clarity;
82
+ }
83
+ })(activeClarity) : '', hasKbps ? `${bitKBP} KB/S` : ''].filter(Boolean).join(' ');
84
+ if (!hasKbps && !hasSignal && !hasClarity) {
58
85
  return null;
59
86
  }
60
- if (hideKbsMenu && hideSignalMenu) return null;
61
87
  return /*#__PURE__*/React.createElement(View, {
62
88
  className: clsx({
63
89
  'ipc-player-plugin-videoBitKBP-container': true,
@@ -65,17 +91,21 @@ export const VideoBitKBP = props => {
65
91
  })
66
92
  }, /*#__PURE__*/React.createElement(View, {
67
93
  className: "ipc-player-plugin-videoBitKBP"
94
+ }, /*#__PURE__*/React.createElement(View, {
95
+ className: "ipc-player-plugin-videoBitKBP-content"
68
96
  }, hasSignal && /*#__PURE__*/React.createElement(View, {
69
97
  className: "ipc-player-plugin-videoBitKBP-signal"
70
98
  }, /*#__PURE__*/React.createElement(Text, {
71
99
  className: clsx('icon-panel', 'icon-panel-wi-Fi', 'ipc-player-plugin-videoBitKBP-signal-icon')
72
- }), /*#__PURE__*/React.createElement(Text, null, signalStrength), /*#__PURE__*/React.createElement(Text, {
73
- className: "ipc-player-plugin-videoBitKBP-unit-percent"
74
- }, signalStrength > 0 ? '%' : 'dBm')), hasSignal && hasKbps && /*#__PURE__*/React.createElement(View, {
100
+ }), /*#__PURE__*/React.createElement(Text, {
101
+ className: "ipc-player-plugin-videoBitKBP-signal-text"
102
+ }, signalStrength), /*#__PURE__*/React.createElement(Text, {
103
+ className: "ipc-player-plugin-videoBitKBP-signal-text ipc-player-plugin-videoBitKBP-unit-percent"
104
+ }, signalStrength > 0 ? '%' : 'dBm')), hasSignal && (hasKbps || hasClarity) && /*#__PURE__*/React.createElement(View, {
75
105
  className: "ipc-player-plugin-videoBitKBP-divider"
76
- }), hasKbps && /*#__PURE__*/React.createElement(View, {
106
+ }), (hasKbps || hasClarity) && /*#__PURE__*/React.createElement(View, {
77
107
  className: "ipc-player-plugin-videoBitKBP-kbps"
78
- }, /*#__PURE__*/React.createElement(Text, null, bitKBP), /*#__PURE__*/React.createElement(Text, {
79
- className: "ipc-player-plugin-videoBitKBP-unit-kbs"
80
- }, "KB/S"))));
108
+ }, /*#__PURE__*/React.createElement(Text, {
109
+ className: "ipc-player-plugin-videoBitKBP-kbps-text"
110
+ }, bitrateLabel)))));
81
111
  };
@@ -18,26 +18,35 @@
18
18
  background-color: rgba(255, 255, 255, 0.2);
19
19
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
20
20
  }
21
- .ipc-player-plugin-videoBitKBP-signal {
21
+ .ipc-player-plugin-videoBitKBP-content {
22
22
  display: flex;
23
- align-items: center;
23
+ align-items: baseline;
24
+ }
25
+ .ipc-player-plugin-videoBitKBP-signal,
26
+ .ipc-player-plugin-videoBitKBP-kbps {
27
+ display: flex;
28
+ align-items: baseline;
29
+ height: calc(16px * var(--ipc-player-size-scale, 1));
30
+ line-height: calc(16px * var(--ipc-player-size-scale, 1));
24
31
  }
25
32
  .ipc-player-plugin-videoBitKBP-signal-icon {
33
+ align-self: center;
26
34
  font-size: calc(14px * var(--ipc-player-size-scale, 1));
27
35
  margin-right: calc(4px * var(--ipc-player-size-scale, 1));
28
36
  }
37
+ .ipc-player-plugin-videoBitKBP-signal-text,
38
+ .ipc-player-plugin-videoBitKBP-kbps-text {
39
+ line-height: calc(16px * var(--ipc-player-size-scale, 1));
40
+ }
29
41
  .ipc-player-plugin-videoBitKBP-divider {
42
+ align-self: center;
30
43
  width: 1px;
31
44
  height: calc(10px * var(--ipc-player-size-scale, 1));
32
45
  background-color: var(--iconColor);
33
46
  margin: 0 calc(4px * var(--ipc-player-size-scale, 1));
34
47
  }
35
- .ipc-player-plugin-videoBitKBP-kbps {
36
- display: flex;
37
- align-items: center;
38
- }
39
- .ipc-player-plugin-videoBitKBP-unit-kbs {
40
- margin-left: calc(4px * var(--ipc-player-size-scale, 1));
48
+ .ipc-player-plugin-videoBitKBP-kbps-text {
49
+ white-space: nowrap;
41
50
  }
42
51
  .ipc-player-plugin-videoBitKBP-unit-percent {
43
52
  margin-left: calc(2px * var(--ipc-player-size-scale, 1));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.55-beta.0",
3
+ "version": "0.0.55",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@ray-js/direction-control": "^0.0.8",
39
39
  "@ray-js/ipc-ptz-zoom": "^0.0.3",
40
- "@ray-js/ray-ipc-player": "^2.1.3",
40
+ "@ray-js/ray-ipc-player": "^2.1.4",
41
41
  "@ray-js/ray-ipc-utils": "^1.1.16",
42
42
  "@ray-js/svg": "0.2.0",
43
43
  "clsx": "^1.2.1",