@ray-js/ipc-player-integration 0.0.52-beta.5 → 0.0.53-beta.1

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
@@ -109,6 +109,15 @@ export const createUseCtx = _ref => {
109
109
  if (!eventRef.current) {
110
110
  eventRef.current = getEventInstance();
111
111
  }
112
+
113
+ /**
114
+ * 自动清晰度作为独立档位并入清晰度列表:
115
+ * 竖屏宿主弹框(由 resolutionList 构建 actionData)与横屏 FullResolutionControl 共用。
116
+ */
117
+ const withAutoClarity = function () {
118
+ let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
119
+ return list.includes(ClarityType.AUTO) ? list : [...list, ClarityType.AUTO];
120
+ };
112
121
  useEffect(() => {
113
122
  // 初始化获取缓存值
114
123
 
@@ -117,7 +126,7 @@ export const createUseCtx = _ref => {
117
126
  try {
118
127
  var _res$maxZoomSettings;
119
128
  const res = await getMemoryState(devId);
120
- setResolutionList(res.resolutionList);
129
+ setResolutionList(withAutoClarity(res.resolutionList));
121
130
  _setResolution(res.resolution, true);
122
131
  _setMute(res.mute, true);
123
132
  setIntercomMode(res.intercomMode);
@@ -133,7 +142,7 @@ export const createUseCtx = _ref => {
133
142
  // 获取缓存的值且同步
134
143
  getMemoryState(devId).then(res => {
135
144
  var _res$maxZoomSettings2;
136
- setResolutionList(res.resolutionList);
145
+ setResolutionList(withAutoClarity(res.resolutionList));
137
146
  // 传true表示值即可,会取播放器的值
138
147
  _setResolution(res.resolution, true);
139
148
  _setMute(res.mute, true);
@@ -238,8 +247,17 @@ export const createUseCtx = _ref => {
238
247
  return false;
239
248
  }
240
249
  return new Promise((resolve, reject) => {
250
+ const clarityMap = {
251
+ [ClarityType.SS]: 'ss',
252
+ [ClarityType.SD]: 'normal',
253
+ [ClarityType.HD]: 'hd',
254
+ [ClarityType.UD]: 'ud',
255
+ [ClarityType.SSP]: 'ssp',
256
+ [ClarityType.AUTO]: 'auto',
257
+ [ClarityType.AUDIO]: 'audio'
258
+ };
241
259
  IPCPlayerInstance.current.setClarity({
242
- clarity: target === ClarityType.HD ? 'hd' : 'normal',
260
+ clarity: clarityMap[target] || 'normal',
243
261
  success: () => {
244
262
  setResolutionMemoryState(devId, target);
245
263
  updateAtom(resolution, target);
@@ -3,6 +3,7 @@ declare const Strings: kit.I18N<{
3
3
  en: {
4
4
  ipc_player_resolution_HD: string;
5
5
  ipc_player_resolution_SD: string;
6
+ ipc_player_resolution_AUTO: string;
6
7
  ipc_player_current_resolution_is_equal: string;
7
8
  ipc_player_screenshot_success_tip: string;
8
9
  ipc_player_screenshot_multi_success_tip: string;
@@ -43,6 +44,7 @@ declare const Strings: kit.I18N<{
43
44
  zh: {
44
45
  ipc_player_resolution_HD: string;
45
46
  ipc_player_resolution_SD: string;
47
+ ipc_player_resolution_AUTO: string;
46
48
  ipc_player_current_resolution_is_equal: string;
47
49
  ipc_player_screenshot_success_tip: string;
48
50
  ipc_player_screenshot_multi_success_tip: string;
@@ -83,6 +85,7 @@ declare const Strings: kit.I18N<{
83
85
  }, {
84
86
  ipc_player_resolution_HD: string;
85
87
  ipc_player_resolution_SD: string;
88
+ ipc_player_resolution_AUTO: string;
86
89
  ipc_player_current_resolution_is_equal: string;
87
90
  ipc_player_screenshot_success_tip: string;
88
91
  ipc_player_screenshot_multi_success_tip: string;
@@ -122,6 +125,7 @@ declare const Strings: kit.I18N<{
122
125
  } | {
123
126
  ipc_player_resolution_HD: string;
124
127
  ipc_player_resolution_SD: string;
128
+ ipc_player_resolution_AUTO: string;
125
129
  ipc_player_current_resolution_is_equal: string;
126
130
  ipc_player_screenshot_success_tip: string;
127
131
  ipc_player_screenshot_multi_success_tip: string;
@@ -2,6 +2,7 @@ declare const _default: {
2
2
  en: {
3
3
  ipc_player_resolution_HD: string;
4
4
  ipc_player_resolution_SD: string;
5
+ ipc_player_resolution_AUTO: string;
5
6
  ipc_player_current_resolution_is_equal: string;
6
7
  ipc_player_screenshot_success_tip: string;
7
8
  ipc_player_screenshot_multi_success_tip: string;
@@ -42,6 +43,7 @@ declare const _default: {
42
43
  zh: {
43
44
  ipc_player_resolution_HD: string;
44
45
  ipc_player_resolution_SD: string;
46
+ ipc_player_resolution_AUTO: string;
45
47
  ipc_player_current_resolution_is_equal: string;
46
48
  ipc_player_screenshot_success_tip: string;
47
49
  ipc_player_screenshot_multi_success_tip: string;
@@ -2,6 +2,7 @@ export default {
2
2
  en: {
3
3
  ipc_player_resolution_HD: 'HD',
4
4
  ipc_player_resolution_SD: 'SD',
5
+ ipc_player_resolution_AUTO: 'Auto',
5
6
  ipc_player_current_resolution_is_equal: 'Already at current clarity',
6
7
  ipc_player_screenshot_success_tip: 'Screenshot saved to album',
7
8
  ipc_player_screenshot_multi_success_tip: 'Screenshots saved to album',
@@ -42,6 +43,7 @@ export default {
42
43
  zh: {
43
44
  ipc_player_resolution_HD: '高清',
44
45
  ipc_player_resolution_SD: '标清',
46
+ ipc_player_resolution_AUTO: '自动',
45
47
  ipc_player_current_resolution_is_equal: '已是当前清晰度',
46
48
  ipc_player_screenshot_success_tip: '截图已保存在APP相册',
47
49
  ipc_player_screenshot_multi_success_tip: '图片已保存至相册',
@@ -87,7 +87,7 @@ export type UseCtx = (options: {
87
87
  setVerticalMic: (value: boolean) => void;
88
88
  setScreenType: (type: ScreenType) => void;
89
89
  setRecordingDisabled: (type: boolean) => void;
90
- setResolution: (type: string) => void;
90
+ setResolution: (type: string) => Promise<boolean>;
91
91
  setResolutionList: (type: string[]) => void;
92
92
  setRecording: (value: boolean, onlyUpdateAtom?: boolean) => Promise<CaptureResult>;
93
93
  stopRecordingOnUnload: () => Promise<CaptureResult>;
@@ -60,6 +60,12 @@ export declare const widgetLabs: {
60
60
  */
61
61
  export declare const bottomLeftContentResize = "bottomLeftContentResize";
62
62
  export declare const zoomLevelChange = "zoomLevelChange";
63
+ /**
64
+ * 自动清晰度状态变化事件:Resolution 控件检测到清晰度进入/退出自动模式或收到
65
+ * clarityChanged 回调结果时触发,携带 { enabled, clarity }(clarity 为 'HD' | 'SD' | null)。
66
+ * VideoBitKBP 监听此事件,在码率前展示当前高清/标清文案。
67
+ */
68
+ export declare const autoClarityChange = "autoClarityChange";
63
69
  export declare const setScaleMultipleEvent = "setScaleMultipleEvent";
64
70
  export declare const decodeClarityDic: {
65
71
  SS: string;
@@ -63,6 +63,13 @@ export const widgetLabs = {
63
63
  */
64
64
  export const bottomLeftContentResize = 'bottomLeftContentResize';
65
65
  export const zoomLevelChange = 'zoomLevelChange';
66
+
67
+ /**
68
+ * 自动清晰度状态变化事件:Resolution 控件检测到清晰度进入/退出自动模式或收到
69
+ * clarityChanged 回调结果时触发,携带 { enabled, clarity }(clarity 为 'HD' | 'SD' | null)。
70
+ * VideoBitKBP 监听此事件,在码率前展示当前高清/标清文案。
71
+ */
72
+ export const autoClarityChange = 'autoClarityChange';
66
73
  export const setScaleMultipleEvent = 'setScaleMultipleEvent';
67
74
  export const decodeClarityDic = {
68
75
  SS: 'ss',
package/lib/ui/ui.js CHANGED
@@ -23,7 +23,7 @@ import { useMemoizedFn } from '../hooks';
23
23
  import { Storage } from '../utils/storage';
24
24
  import './ui.less';
25
25
  import { updatePlayerWidgetProps } from '../features';
26
- import { getNgRawData, getSmartImageQualityState, isLowPhone } from '../utils/ttt';
26
+ import { getNgRawData, getSmartImageQualityState, isLowPhone, notifyOfflineShown } from '../utils/ttt';
27
27
  import { getCaptureResultSummary } from '../utils/captureResult';
28
28
  import { lensCount } from '../widgets/zoomTurntable/lensSkill';
29
29
  import { shouldRenderContent } from './absoluteContent';
@@ -153,6 +153,13 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
153
153
  });
154
154
  }, []);
155
155
 
156
+ // 监听设备在线状态,离线提示展示时通知宿主;notifyOfflineShown 内部兼容没有该 TTT 方法的宿主。
157
+ useEffect(() => {
158
+ if (!deviceOnline) {
159
+ notifyOfflineShown(devId);
160
+ }
161
+ }, [deviceOnline, devId]);
162
+
156
163
  // 展示顶部内容
157
164
  const [showTopContent, setShowTopContent] = useState(true);
158
165
 
@@ -38,4 +38,16 @@ export declare function getAIFrameFeature(devId: string): Promise<GetAIFrameFeat
38
38
  export declare function setAIFrameFeature(params: SetAIFrameFeatureParams): Promise<any>;
39
39
  export declare function setTrailFinish(devId: string): Promise<unknown>;
40
40
  export declare function isLowPhone(): Promise<boolean>;
41
+ /**
42
+ * 通知宿主离线提示已经展示。
43
+ *
44
+ * 这个 TTT 方法不是所有宿主都提供,因此调用前必须做能力判断;
45
+ * 老宿主或 Web 环境下直接跳过,不能影响播放器自身的离线处理。
46
+ */
47
+ export declare function notifyOfflineShown(deviceId: string): boolean;
41
48
  export declare function getNgRawData(): Promise<unknown>;
49
+ export declare function isClarityChangedSupported(): boolean;
50
+ export type ClarityChangedResult = {
51
+ clarity: 'HD' | 'SD';
52
+ };
53
+ export declare function clarityChanged(devId: string): Promise<ClarityChangedResult | null>;
package/lib/utils/ttt.js CHANGED
@@ -120,10 +120,31 @@ export function isLowPhone() {
120
120
  }
121
121
  });
122
122
  }
123
+
124
+ /**
125
+ * 通知宿主离线提示已经展示。
126
+ *
127
+ * 这个 TTT 方法不是所有宿主都提供,因此调用前必须做能力判断;
128
+ * 老宿主或 Web 环境下直接跳过,不能影响播放器自身的离线处理。
129
+ */
130
+ export function notifyOfflineShown(deviceId) {
131
+ var _ty3;
132
+ const method = typeof ty !== 'undefined' ? (_ty3 = ty) === null || _ty3 === void 0 || (_ty3 = _ty3.ipc) === null || _ty3 === void 0 ? void 0 : _ty3.notifyOfflineShown : undefined;
133
+ if (typeof method !== 'function') {
134
+ return false;
135
+ }
136
+ try {
137
+ console.warn('res===notifyOfflineShown');
138
+ method(deviceId, 'preview_mini');
139
+ return true;
140
+ } catch (error) {
141
+ return false;
142
+ }
143
+ }
123
144
  export function getNgRawData() {
124
145
  return new Promise(resolve => {
125
- var _ty3;
126
- const isSupport = typeof ((_ty3 = ty) === null || _ty3 === void 0 ? void 0 : _ty3.getNgRawData) === 'function';
146
+ var _ty4;
147
+ const isSupport = typeof ((_ty4 = ty) === null || _ty4 === void 0 ? void 0 : _ty4.getNgRawData) === 'function';
127
148
  if (!isSupport) {
128
149
  resolve(false);
129
150
  return;
@@ -142,4 +163,37 @@ export function getNgRawData() {
142
163
  resolve(false);
143
164
  }
144
165
  });
166
+ }
167
+
168
+ // 是否支持自动清晰度(ttt 方法 clarityChanged 存在即支持)
169
+ export function isClarityChangedSupported() {
170
+ var _ty$ipc6;
171
+ return typeof ((_ty$ipc6 = ty.ipc) === null || _ty$ipc6 === void 0 ? void 0 : _ty$ipc6.clarityChanged) === 'function';
172
+ }
173
+ export function clarityChanged(devId) {
174
+ return new Promise(resolve => {
175
+ var _ty$ipc7;
176
+ if (typeof ((_ty$ipc7 = ty.ipc) === null || _ty$ipc7 === void 0 ? void 0 : _ty$ipc7.clarityChanged) !== 'function') {
177
+ resolve(null);
178
+ return;
179
+ }
180
+ if (!isClarityChangedSupported()) {
181
+ resolve(null);
182
+ return;
183
+ }
184
+ try {
185
+ ty.ipc.clarityChanged({
186
+ devId,
187
+ success: res => {
188
+ resolve(res !== null && res !== void 0 ? res : null);
189
+ },
190
+ fail: e => {
191
+ console.warn('res===clarityChanged fail', e);
192
+ resolve(null);
193
+ }
194
+ });
195
+ } catch (e) {
196
+ resolve(null);
197
+ }
198
+ });
145
199
  }
@@ -1,17 +1,19 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { View, Text } from '@ray-js/ray';
3
3
  import clsx from 'clsx';
4
- import React, { useContext } from 'react';
4
+ import React, { useContext, useEffect } from 'react';
5
5
  import { useMemoizedFn } from 'ahooks';
6
+ import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
6
7
  import Strings from '../../i18n';
7
8
  import { FullResolutionControl } from './fullResolutionControl';
8
- import { fullResolutionId, pauseTimeToHideAllComponent, hideAllComponent, widgetLabs, widgetClick } from '../../ui/constant';
9
+ import { fullResolutionId, pauseTimeToHideAllComponent, hideAllComponent, widgetLabs, widgetClick, autoClarityChange } from '../../ui/constant';
9
10
  import { UIEventContext } from '../../ui/context';
10
11
  import { useStore } from '../../ctx/store';
12
+ import { clarityChanged } from '../../utils/ttt';
11
13
  import './resolution.less';
12
14
  export const Resolution = props => {
13
15
  const {
14
- IPCPlayerContext,
16
+ devId,
15
17
  setResolution,
16
18
  addContent,
17
19
  hasContent,
@@ -29,6 +31,30 @@ export const Resolution = props => {
29
31
  const {
30
32
  event
31
33
  } = useContext(UIEventContext);
34
+
35
+ // 广播自动清晰度状态给 VideoBitKBP 等监听方;
36
+ // 自动模式下读取一次当前实际清晰度,仅用于码率区域展示。
37
+ useEffect(() => {
38
+ const emitClarity = (enabled, clarity) => {
39
+ event.emit(autoClarityChange, {
40
+ enabled,
41
+ clarity
42
+ });
43
+ };
44
+ if (resolution !== ClarityType.AUTO) {
45
+ emitClarity(false, null);
46
+ return;
47
+ }
48
+ emitClarity(true, null);
49
+ if (devId) {
50
+ clarityChanged(devId).then(res => {
51
+ if (res !== null && res !== void 0 && res.clarity) {
52
+ emitClarity(true, res.clarity);
53
+ }
54
+ });
55
+ }
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ }, [devId, resolution]);
32
58
  const onResolution = useMemoizedFn(() => {
33
59
  event.emit(widgetClick, {
34
60
  widgetId: widgetLabs.RESOLUTION
@@ -1,10 +1,14 @@
1
- import React, { useEffect, useRef, useState } from 'react';
1
+ import React, { useContext, 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';
10
+ import { UIEventContext } from '../../ui/context';
11
+ import { autoClarityChange } from '../../ui/constant';
8
12
  export const VideoBitKBP = props => {
9
13
  const {
10
14
  devId,
@@ -15,10 +19,32 @@ export const VideoBitKBP = props => {
15
19
  } = props;
16
20
  const [bitKBP, setBitKBP] = useState('');
17
21
  const [signalStrength, setSignalStrength] = useState(null);
22
+ // 自动清晰度当前实际档位:null 表示未开启自动模式,不展示
23
+ const [autoClarity, setAutoClarity] = useState(null);
18
24
  const store = useStore({
19
- playState
25
+ playState,
26
+ resolution: props.resolution
20
27
  });
28
+ const {
29
+ event
30
+ } = useContext(UIEventContext);
21
31
  const timerRef = useRef();
32
+
33
+ // 监听 Resolution 控件广播的自动清晰度状态
34
+ useEffect(() => {
35
+ const onAutoClarityChange = payload => {
36
+ setAutoClarity(payload.enabled ? payload.clarity : null);
37
+ };
38
+ event.on(autoClarityChange, onAutoClarityChange);
39
+ return () => {
40
+ event.off(autoClarityChange, onAutoClarityChange);
41
+ };
42
+ }, [event]);
43
+ useEffect(() => {
44
+ if (store.resolution !== ClarityType.AUTO) {
45
+ setAutoClarity(null);
46
+ }
47
+ }, [store.resolution]);
22
48
  useEffect(() => {
23
49
  if (store.playState === PlayState.PLAYING && (!hideKbsMenu || !hideSignalMenu)) {
24
50
  init();
@@ -75,7 +101,9 @@ export const VideoBitKBP = props => {
75
101
  className: "ipc-player-plugin-videoBitKBP-divider"
76
102
  }), hasKbps && /*#__PURE__*/React.createElement(View, {
77
103
  className: "ipc-player-plugin-videoBitKBP-kbps"
78
- }, /*#__PURE__*/React.createElement(Text, null, bitKBP), /*#__PURE__*/React.createElement(Text, {
104
+ }, autoClarity && /*#__PURE__*/React.createElement(Text, {
105
+ className: "ipc-player-plugin-videoBitKBP-clarity"
106
+ }, autoClarity === 'HD' ? Strings.getLang('ipc_player_resolution_HD') : Strings.getLang('ipc_player_resolution_SD')), /*#__PURE__*/React.createElement(Text, null, bitKBP), /*#__PURE__*/React.createElement(Text, {
79
107
  className: "ipc-player-plugin-videoBitKBP-unit-kbs"
80
108
  }, "KB/S"))));
81
109
  };
@@ -36,6 +36,9 @@
36
36
  display: flex;
37
37
  align-items: center;
38
38
  }
39
+ .ipc-player-plugin-videoBitKBP-clarity {
40
+ margin-right: calc(4px * var(--ipc-player-size-scale, 1));
41
+ }
39
42
  .ipc-player-plugin-videoBitKBP-unit-kbs {
40
43
  margin-left: calc(4px * var(--ipc-player-size-scale, 1));
41
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.52-beta.5",
3
+ "version": "0.0.53-beta.1",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [