@ray-js/ipc-player-integration 0.0.62 → 0.0.64

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.
@@ -129,6 +129,7 @@ const getMemoryState = devId => {
129
129
  mute: true,
130
130
  intercomMode: IntercomMode.TwoWay,
131
131
  resolution: ClarityType.HD,
132
+ defaultResolution: ClarityType.HD,
132
133
  resolutionList: [ClarityType.HD, ClarityType.SD],
133
134
  isIntercomSupported: false,
134
135
  maxZoomSettings: 6
@@ -140,12 +141,16 @@ const getMemoryState = devId => {
140
141
  return resolve(defaultValue);
141
142
  }
142
143
  const muteValue = res.data.microphoneSettings.cachedMuteMode === MuteMode.OFF;
144
+ const {
145
+ availableResolutions
146
+ } = res.data.videoResolution;
143
147
  return resolve({
144
148
  mute: muteValue,
145
149
  intercomMode: res.data.intercomInfo.cachedIntercomMode,
146
150
  isIntercomSupported: res.data.intercomInfo.isIntercomSupported,
147
151
  resolution: res.data.videoResolution.cachedResolution,
148
- resolutionList: res.data.videoResolution.availableResolutions,
152
+ defaultResolution: res.data.videoResolution.defaultResolution,
153
+ resolutionList: Array.isArray(availableResolutions) && availableResolutions.length > 0 ? availableResolutions : defaultValue.resolutionList,
149
154
  maxZoomSettings: (_res$data$maxZoomSett = res.data.maxZoomSettings) !== null && _res$data$maxZoomSett !== void 0 ? _res$data$maxZoomSett : 6
150
155
  });
151
156
  }).catch(err => {
package/lib/ctx/ctx.js CHANGED
@@ -3,13 +3,14 @@ import "core-js/modules/esnext.iterator.constructor.js";
3
3
  import "core-js/modules/esnext.iterator.filter.js";
4
4
  import "core-js/modules/esnext.iterator.find.js";
5
5
  import "core-js/modules/esnext.iterator.map.js";
6
- import { useRef, useCallback, useEffect } from 'react';
6
+ import { useRef, useCallback, useEffect, useState } from 'react';
7
7
  import { getSystemInfoSync, showModal, openAppSystemSettingPage } from '@ray-js/ray';
8
8
  import Strings from '../i18n';
9
9
  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';
13
14
  import { getEventInstance } from './event';
14
15
  import { isMultiCameraTileSupported, useMultiCameraCtx } from './multiCameraCtx';
15
16
  import { toNativeClarity, withAutoClarity } from './resolution';
@@ -32,6 +33,7 @@ export const createUseCtx = _ref => {
32
33
  return _ref2 => {
33
34
  let {
34
35
  devId,
36
+ autoClarityDisabled,
35
37
  initTopLeftContent,
36
38
  initTopRightContent,
37
39
  initBottomLeftContent,
@@ -74,6 +76,8 @@ export const createUseCtx = _ref => {
74
76
  const [resolution] = useAtom('HD');
75
77
  // resolution 清晰度列表
76
78
  const [resolutionList, setResolutionList] = useAtom([]);
79
+ const [memoryState, setMemoryState] = useState(null);
80
+ const autoFallbackPendingRef = useRef(null);
77
81
  // 自动模式下宿主上报的实际清晰度,供横竖屏码率区域共用
78
82
  const [autoClarity] = useAtom(null);
79
83
 
@@ -124,40 +128,73 @@ export const createUseCtx = _ref => {
124
128
  if (!eventRef.current) {
125
129
  eventRef.current = getEventInstance();
126
130
  }
131
+ const syncMemoryState = res => {
132
+ var _res$maxZoomSettings;
133
+ setMemoryState({
134
+ devId,
135
+ data: res
136
+ });
137
+ // 历史 Auto 等宿主配置确定后再恢复,避免先显示 Auto 再回退。
138
+ if (res.resolution !== ClarityType.AUTO) {
139
+ restoreResolution(res.resolution, res.resolutionList, _setResolution);
140
+ }
141
+ _setMute(res.mute, true);
142
+ setIntercomMode(res.intercomMode);
143
+ setIntercomSupported(res.isIntercomSupported);
144
+ setMaxZoomSettings((_res$maxZoomSettings = res.maxZoomSettings) !== null && _res$maxZoomSettings !== void 0 ? _res$maxZoomSettings : 6);
145
+ };
146
+ useEffect(() => {
147
+ autoFallbackPendingRef.current = null;
148
+ }, [devId]);
127
149
  useEffect(() => {
128
150
  // 初始化获取缓存值
129
-
151
+ let active = true;
130
152
  (async () => {
131
153
  if (!devId) return;
132
154
  try {
133
- var _res$maxZoomSettings;
134
155
  const res = await getMemoryState(devId);
135
- setResolutionList(withAutoClarity(res.resolutionList));
136
- restoreResolution(res.resolution, res.resolutionList, _setResolution);
137
- _setMute(res.mute, true);
138
- setIntercomMode(res.intercomMode);
139
- setIntercomSupported(res.isIntercomSupported);
140
- setMaxZoomSettings((_res$maxZoomSettings = res.maxZoomSettings) !== null && _res$maxZoomSettings !== void 0 ? _res$maxZoomSettings : 6);
156
+ if (!active) return;
157
+ syncMemoryState(res);
141
158
  } catch (error) {
142
159
  console.error('获取 getMemoryState 失败:', error);
143
160
  }
144
161
  })();
162
+ return () => {
163
+ active = false;
164
+ };
145
165
  }, [devId]);
146
166
  useEffect(() => {
167
+ let active = true;
147
168
  if (devId && _playState === PlayState.PLAYING) {
148
169
  // 获取缓存的值且同步
149
170
  getMemoryState(devId).then(res => {
150
- var _res$maxZoomSettings2;
151
- setResolutionList(withAutoClarity(res.resolutionList));
152
- // 传true表示值即可,会取播放器的值
153
- restoreResolution(res.resolution, res.resolutionList, _setResolution);
154
- _setMute(res.mute, true);
155
- setIntercomMode(res.intercomMode);
156
- setIntercomSupported(res.isIntercomSupported);
157
- setMaxZoomSettings((_res$maxZoomSettings2 = res.maxZoomSettings) !== null && _res$maxZoomSettings2 !== void 0 ? _res$maxZoomSettings2 : 6);
171
+ if (!active) return;
172
+ syncMemoryState(res);
158
173
  });
159
174
  }
175
+ return () => {
176
+ active = false;
177
+ };
160
178
  }, [devId, _playState]);
179
+ useEffect(() => {
180
+ // 普通档位或宿主配置变化时,决定是否追加 Auto。
181
+ const list = (memoryState === null || memoryState === void 0 ? void 0 : memoryState.devId) === devId ? memoryState.data.resolutionList : [];
182
+ if (autoClarityDisabled === null) {
183
+ setResolutionList(list.filter(clarity => clarity !== ClarityType.AUTO));
184
+ return;
185
+ }
186
+ setResolutionList(withAutoClarity(list, autoClarityDisabled));
187
+ if ((memoryState === null || memoryState === void 0 ? void 0 : memoryState.devId) !== devId || memoryState.data.resolution !== ClarityType.AUTO) return;
188
+ if (autoClarityDisabled && autoFallbackPendingRef.current !== devId) {
189
+ autoFallbackPendingRef.current = devId;
190
+ _setResolution(memoryState.data.defaultResolution).catch(error => {
191
+ autoFallbackPendingRef.current = null;
192
+ console.warn('恢复默认清晰度失败:', error);
193
+ });
194
+ } else if (!autoClarityDisabled) {
195
+ restoreResolution(memoryState.data.resolution, list, _setResolution);
196
+ }
197
+ }, [devId, memoryState, currentResolution, autoClarityDisabled]);
161
198
  useEffect(() => {
162
199
  refreshAfterPlayback(_playState, currentResolution);
163
200
  }, [devId, _playState, currentResolution]);
@@ -329,7 +366,7 @@ export const createUseCtx = _ref => {
329
366
  ty.authorizeStatus({
330
367
  // 麦克风权限
331
368
  scope: 'scope.record',
332
- success: () => {
369
+ success: success => {
333
370
  eventRef.current.emit(changeIgnoreHideStopPreview, false);
334
371
  IPCPlayerInstance.current.startTalk({
335
372
  success: () => {
@@ -347,12 +384,12 @@ export const createUseCtx = _ref => {
347
384
  }
348
385
  });
349
386
  },
350
- fail: () => {
387
+ fail: err => {
351
388
  console.log('authorizeStatus失败回调');
352
389
  ty.authorize({
353
390
  // 麦克风权限
354
391
  scope: 'scope.record',
355
- success: () => {
392
+ success: success => {
356
393
  console.log('authorize成功回调');
357
394
  IPCPlayerInstance.current.startTalk({
358
395
  success: () => {
@@ -8,6 +8,7 @@ export type GetMemoryState = (devId: string) => Promise<{
8
8
  intercomMode: IntercomMode;
9
9
  isIntercomSupported: boolean;
10
10
  resolution: ClarityType;
11
+ defaultResolution: ClarityType;
11
12
  resolutionList: [ClarityType.HD, ClarityType.SD];
12
13
  maxZoomSettings?: number;
13
14
  }>;
@@ -3,6 +3,6 @@ type NativeClarity = Parameters<IpcContext['setClarity']>[0]['clarity'];
3
3
  export declare const toNativeClarity: (clarity: ClarityType) => NativeClarity;
4
4
  /** 宿主支持自动清晰度,且返回至少两个档位时才展示 AUTO。 */
5
5
  export declare const canShowAutoClarity: (list?: ClarityType[]) => boolean;
6
- export declare const withAutoClarity: (list?: ClarityType[]) => ClarityType[];
6
+ export declare const withAutoClarity: (list?: ClarityType[], autoClarityDisabled?: boolean) => ClarityType[];
7
7
  export declare const normalizeResolution: (resolution: ClarityType, list: ClarityType[]) => ClarityType;
8
8
  export {};
@@ -21,8 +21,10 @@ export const canShowAutoClarity = function () {
21
21
  };
22
22
  export const withAutoClarity = function () {
23
23
  let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
24
+ let autoClarityDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
24
25
  const withoutAuto = list.filter(clarity => clarity !== ClarityType.AUTO);
25
- return canShowAutoClarity(list) ? [...withoutAuto, ClarityType.AUTO] : withoutAuto;
26
+ const showAuto = !autoClarityDisabled && canShowAutoClarity(withoutAuto);
27
+ return showAuto ? [...withoutAuto, ClarityType.AUTO] : withoutAuto;
26
28
  };
27
29
  export const normalizeResolution = (resolution, list) => {
28
30
  if (resolution !== ClarityType.AUTO || canShowAutoClarity(list)) return resolution;
@@ -41,6 +41,8 @@ export type EventInstance = {
41
41
  };
42
42
  export type UseCtx = (options: {
43
43
  devId: string;
44
+ /** 宿主决定是否禁用 Auto;null 表示本次配置查询尚未完成。 */
45
+ autoClarityDisabled?: boolean | null;
44
46
  initTopLeftContent?: ComponentConfig[];
45
47
  initTopRightContent?: ComponentConfig[];
46
48
  initBottomLeftContent?: ComponentConfig[];
package/lib/ui/ui.d.ts CHANGED
@@ -15,6 +15,8 @@ type CSSVariable = {
15
15
  };
16
16
  type Props = {
17
17
  devId: string;
18
+ /** 未提供 instance 时,传给播放器内部的 useCtx。null 表示配置查询中。 */
19
+ autoClarityDisabled?: boolean | null;
18
20
  isShare?: boolean;
19
21
  ignoreHideStopPreview?: boolean;
20
22
  instance?: CtxInstance;
package/lib/ui/ui.js CHANGED
@@ -59,11 +59,12 @@ const StandaloneAutoClarity = _ref2 => {
59
59
  instance: instance
60
60
  }));
61
61
  };
62
- function getCtxInstance(instance, devId) {
62
+ function getCtxInstance(instance, devId, autoClarityDisabled) {
63
63
  if (instance) return instance;
64
64
  // eslint-disable-next-line react-hooks/rules-of-hooks
65
65
  return useCtx({
66
- devId
66
+ devId,
67
+ autoClarityDisabled
67
68
  });
68
69
  }
69
70
 
@@ -126,7 +127,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
126
127
  const {
127
128
  event
128
129
  } = useContext(UIEventContext);
129
- const instance = getCtxInstance(props.instance, devId);
130
+ const instance = getCtxInstance(props.instance, devId, props.autoClarityDisabled);
130
131
  const {
131
132
  setPlayState,
132
133
  setScreenType,
@@ -563,7 +564,6 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
563
564
  // canOpenSettings: true,
564
565
  // };
565
566
  const getNgRes = await getNgRawData();
566
- console.log('res===getSmartImageQualityState', res);
567
567
  updatePlayerWidgetProps(instance, 'bottomLeft', 'TryExperience', {
568
568
  isPurchase: res.isPurchase,
569
569
  buttonState: res.buttonState,
package/lib/utils/ttt.js CHANGED
@@ -37,11 +37,9 @@ export function getAIFrameFeature(devId) {
37
37
  ty.ipc.getAIFrameFeature({
38
38
  devId,
39
39
  success: data => {
40
- console.log('res===getAIFrameFeature data', data);
41
40
  resolve(data);
42
41
  },
43
- fail: e => {
44
- console.warn('res===getAIFrameFeature fail', e);
42
+ fail: () => {
45
43
  resolve(null);
46
44
  }
47
45
  });
@@ -61,11 +59,9 @@ export function setAIFrameFeature(params) {
61
59
  try {
62
60
  ty.ipc.setAIFrameFeature(_objectSpread(_objectSpread({}, params), {}, {
63
61
  success: data => {
64
- console.log('res===setAIFrameFeature data', data);
65
62
  resolve(data);
66
63
  },
67
- fail: e => {
68
- console.warn('res===setAIFrameFeature fail', e);
64
+ fail: () => {
69
65
  resolve(null);
70
66
  }
71
67
  }));
@@ -135,7 +131,6 @@ export function notifyOfflineShown(deviceId) {
135
131
  return false;
136
132
  }
137
133
  try {
138
- console.warn('res===notifyOfflineShown', deviceId);
139
134
  method({
140
135
  deviceId,
141
136
  scene: 'preview_mini'
@@ -246,7 +241,6 @@ export function subscribeClarityChanged(devId, handler) {
246
241
  try {
247
242
  ipc.onClarityChanged(listener);
248
243
  } catch (error) {
249
- console.warn('res===onClarityChanged fail', error);
250
244
  return () => undefined;
251
245
  }
252
246
  return () => {
@@ -17,13 +17,19 @@ export const Muted = props => {
17
17
  } = useContext(UIEventContext);
18
18
  const event = propsEvent !== null && propsEvent !== void 0 ? propsEvent : ctxEvent;
19
19
  const {
20
- isMuted
20
+ isMuted,
21
+ intercom
21
22
  } = useStore({
22
- isMuted: mute
23
+ isMuted: mute,
24
+ intercom: props.intercom
23
25
  });
26
+ const disabled = intercom;
24
27
  return /*#__PURE__*/React.createElement(View, {
25
- className: clsx(className),
28
+ className: clsx(className, {
29
+ 'ipc-player-plugin-muted-disabled': disabled
30
+ }),
26
31
  onClick: () => {
32
+ if (disabled) return;
27
33
  event.emit(widgetClick, {
28
34
  widgetId: widgetLabs.MUTED
29
35
  });
@@ -8,4 +8,8 @@
8
8
  .ipc-player-plugin-muted-text-icon {
9
9
  color: var(--iconColor);
10
10
  font-size: calc(var(--iconPlayerSize) * var(--ipc-player-size-scale, 1)) !important;
11
- }
11
+ }
12
+
13
+ .ipc-player-plugin-muted-disabled {
14
+ opacity: 0.4;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { act, renderHook } from '@testing-library/react-hooks/dom';
2
+ import { atom, getDefaultStore } from 'jotai';
3
+ import { IntercomMode } from '../../interface';
4
+ import { Muted } from './muted';
5
+ jest.mock('@ray-js/ray', () => ({
6
+ View: 'div',
7
+ Text: 'span'
8
+ }));
9
+ jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
10
+ IntercomMode: {
11
+ OneWay: 'OneWay',
12
+ TwoWay: 'TwoWay'
13
+ }
14
+ }));
15
+ jest.mock('./muted.less', () => ({}));
16
+ const createProps = function () {
17
+ let talking = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
18
+ let mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : IntercomMode.OneWay;
19
+ let muted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
20
+ return {
21
+ mute: atom(muted),
22
+ intercom: atom(talking),
23
+ intercomMode: atom(mode),
24
+ setMute: jest.fn(),
25
+ event: {
26
+ emit: jest.fn()
27
+ }
28
+ };
29
+ };
30
+ it.each([[IntercomMode.OneWay, true], [IntercomMode.OneWay, false], [IntercomMode.TwoWay, true], [IntercomMode.TwoWay, false]])('blocks speaker changes and control events during talk in mode=%s, muted=%s', (mode, muted) => {
31
+ const props = createProps(true, mode, muted);
32
+ const {
33
+ result,
34
+ unmount
35
+ } = renderHook(() => Muted(props));
36
+ act(() => result.current.props.onClick());
37
+ expect(props.setMute).not.toHaveBeenCalled();
38
+ expect(props.event.emit).not.toHaveBeenCalled();
39
+ expect(result.current.props.className).toContain('ipc-player-plugin-muted-disabled');
40
+ unmount();
41
+ });
42
+ it.each([[false, IntercomMode.OneWay, true, false], [false, IntercomMode.OneWay, false, true], [false, IntercomMode.TwoWay, true, false], [false, IntercomMode.TwoWay, false, true]])('keeps speaker switching when talking=%s, mode=%s, muted=%s', (talking, mode, muted, target) => {
43
+ const props = createProps(talking, mode, muted);
44
+ const {
45
+ result,
46
+ unmount
47
+ } = renderHook(() => Muted(props));
48
+ act(() => result.current.props.onClick());
49
+ expect(props.setMute).toHaveBeenCalledTimes(1);
50
+ expect(props.setMute).toHaveBeenCalledWith(target);
51
+ expect(result.current.props.className).not.toContain('ipc-player-plugin-muted-disabled');
52
+ unmount();
53
+ });
54
+ it.each([IntercomMode.OneWay, IntercomMode.TwoWay])('uses shared talk state after remount and unlocks when talk ends in mode=%s', mode => {
55
+ const props = createProps(false, mode);
56
+ const store = getDefaultStore();
57
+ const first = renderHook(() => Muted(props));
58
+ act(() => store.set(props.intercom, true));
59
+ act(() => first.result.current.props.onClick());
60
+ expect(props.setMute).not.toHaveBeenCalled();
61
+ first.unmount();
62
+ const second = renderHook(() => Muted(props));
63
+ act(() => second.result.current.props.onClick());
64
+ expect(props.setMute).not.toHaveBeenCalled();
65
+ act(() => store.set(props.intercom, false));
66
+ act(() => second.result.current.props.onClick());
67
+ expect(props.setMute).toHaveBeenCalledWith(false);
68
+ second.unmount();
69
+ });
70
+ it.each([[IntercomMode.OneWay, IntercomMode.TwoWay], [IntercomMode.TwoWay, IntercomMode.OneWay]])('keeps the speaker locked when active talk changes from %s to %s', (mode, nextMode) => {
71
+ const props = createProps(true, mode);
72
+ const {
73
+ result,
74
+ unmount
75
+ } = renderHook(() => Muted(props));
76
+ act(() => getDefaultStore().set(props.intercomMode, nextMode));
77
+ act(() => result.current.props.onClick());
78
+ expect(props.setMute).not.toHaveBeenCalled();
79
+ expect(props.event.emit).not.toHaveBeenCalled();
80
+ unmount();
81
+ });
@@ -77,7 +77,6 @@ export const TryExperience = props => {
77
77
  }
78
78
  }, [buttonState]);
79
79
  const onTryExperience = useCallback(async () => {
80
- console.log('res===onTryExperience', lockRef.current, isLowPhone);
81
80
  if (lockRef.current) return;
82
81
  if (isLowPhone) {
83
82
  showToast({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -37,6 +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/panel-sdk": "^1.13.1",
40
41
  "@ray-js/ray-ipc-player": "^2.1.7",
41
42
  "@ray-js/ray-ipc-utils": "^1.1.16",
42
43
  "@ray-js/svg": "0.2.0",