@ray-js/ipc-player-integration 0.0.58-beta.0 → 0.0.58-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ctx/ctx.js +8 -14
- package/lib/ctx/resolution.d.ts +1 -1
- package/lib/ctx/resolution.js +2 -8
- package/lib/interface.d.ts +2 -0
- package/lib/ui/ui.d.ts +2 -0
- package/lib/ui/ui.js +4 -3
- package/lib/widgets/recordVideo/recordVideo.js +4 -18
- package/lib/widgets/recordVideo/recordVideo.lifecycle.test.d.ts +1 -0
- package/lib/widgets/recordVideo/recordVideo.lifecycle.test.js +106 -0
- package/package.json +1 -1
- package/lib/ctx/useAutoClarityConfig.d.ts +0 -8
- package/lib/ctx/useAutoClarityConfig.js +0 -40
- package/lib/utils/productAbility.d.ts +0 -6
- package/lib/utils/productAbility.js +0 -20
package/lib/ctx/ctx.js
CHANGED
|
@@ -15,7 +15,6 @@ import { getEventInstance } from './event';
|
|
|
15
15
|
import { isMultiCameraTileSupported, useMultiCameraCtx } from './multiCameraCtx';
|
|
16
16
|
import { toNativeClarity, withAutoClarity } from './resolution';
|
|
17
17
|
import { useAutoClarity } from './useAutoClarity';
|
|
18
|
-
import { useAutoClarityConfig } from './useAutoClarityConfig';
|
|
19
18
|
const SAVE_TO_ALBUM = 1;
|
|
20
19
|
export const createUseCtx = _ref => {
|
|
21
20
|
let {
|
|
@@ -34,6 +33,7 @@ export const createUseCtx = _ref => {
|
|
|
34
33
|
return _ref2 => {
|
|
35
34
|
let {
|
|
36
35
|
devId,
|
|
36
|
+
autoClarityDisabled,
|
|
37
37
|
initTopLeftContent,
|
|
38
38
|
initTopRightContent,
|
|
39
39
|
initBottomLeftContent,
|
|
@@ -80,11 +80,6 @@ export const createUseCtx = _ref => {
|
|
|
80
80
|
const [resolutionList, setResolutionList] = useAtom([]);
|
|
81
81
|
const [memoryState, setMemoryState] = useState(null);
|
|
82
82
|
const autoFallbackPendingRef = useRef(null);
|
|
83
|
-
const {
|
|
84
|
-
is4G,
|
|
85
|
-
enableAutoClarity,
|
|
86
|
-
ready: autoConfigReady
|
|
87
|
-
} = useAutoClarityConfig(devId);
|
|
88
83
|
// 自动模式下宿主上报的实际清晰度,供横竖屏码率区域共用
|
|
89
84
|
const [autoClarity] = useAtom(null);
|
|
90
85
|
|
|
@@ -141,7 +136,7 @@ export const createUseCtx = _ref => {
|
|
|
141
136
|
devId,
|
|
142
137
|
data: res
|
|
143
138
|
});
|
|
144
|
-
// 历史 Auto
|
|
139
|
+
// 历史 Auto 等宿主配置确定后再恢复,避免先显示 Auto 再回退。
|
|
145
140
|
if (res.resolution !== ClarityType.AUTO) {
|
|
146
141
|
restoreResolution(res.resolution, res.resolutionList, _setResolution);
|
|
147
142
|
}
|
|
@@ -184,25 +179,24 @@ export const createUseCtx = _ref => {
|
|
|
184
179
|
};
|
|
185
180
|
}, [devId, _playState]);
|
|
186
181
|
useEffect(() => {
|
|
187
|
-
//
|
|
182
|
+
// 普通档位或宿主配置变化时,决定是否追加 Auto。
|
|
188
183
|
const list = (memoryState === null || memoryState === void 0 ? void 0 : memoryState.devId) === devId ? memoryState.data.resolutionList : [];
|
|
189
|
-
if (
|
|
184
|
+
if (autoClarityDisabled === null) {
|
|
190
185
|
setResolutionList(list.filter(clarity => clarity !== ClarityType.AUTO));
|
|
191
186
|
return;
|
|
192
187
|
}
|
|
193
|
-
setResolutionList(withAutoClarity(list,
|
|
194
|
-
const autoDisabled = is4G && enableAutoClarity === false;
|
|
188
|
+
setResolutionList(withAutoClarity(list, autoClarityDisabled));
|
|
195
189
|
if ((memoryState === null || memoryState === void 0 ? void 0 : memoryState.devId) !== devId || memoryState.data.resolution !== ClarityType.AUTO) return;
|
|
196
|
-
if (
|
|
190
|
+
if (autoClarityDisabled && autoFallbackPendingRef.current !== devId) {
|
|
197
191
|
autoFallbackPendingRef.current = devId;
|
|
198
192
|
_setResolution(memoryState.data.defaultResolution).catch(error => {
|
|
199
193
|
autoFallbackPendingRef.current = null;
|
|
200
194
|
console.warn('恢复默认清晰度失败:', error);
|
|
201
195
|
});
|
|
202
|
-
} else if (!
|
|
196
|
+
} else if (!autoClarityDisabled) {
|
|
203
197
|
restoreResolution(memoryState.data.resolution, list, _setResolution);
|
|
204
198
|
}
|
|
205
|
-
}, [devId, memoryState, currentResolution,
|
|
199
|
+
}, [devId, memoryState, currentResolution, autoClarityDisabled]);
|
|
206
200
|
useEffect(() => {
|
|
207
201
|
refreshAfterPlayback(_playState, currentResolution);
|
|
208
202
|
}, [devId, _playState, currentResolution]);
|
package/lib/ctx/resolution.d.ts
CHANGED
|
@@ -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[],
|
|
6
|
+
export declare const withAutoClarity: (list?: ClarityType[], autoClarityDisabled?: boolean) => ClarityType[];
|
|
7
7
|
export declare const normalizeResolution: (resolution: ClarityType, list: ClarityType[]) => ClarityType;
|
|
8
8
|
export {};
|
package/lib/ctx/resolution.js
CHANGED
|
@@ -21,15 +21,9 @@ 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
|
|
25
|
-
let enableAutoClarity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
24
|
+
let autoClarityDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
26
25
|
const withoutAuto = list.filter(clarity => clarity !== ClarityType.AUTO);
|
|
27
|
-
|
|
28
|
-
// 仅 4G 能力开启且面板云配置明确关闭时隐藏 Auto。
|
|
29
|
-
if (is4G && enableAutoClarity === false) {
|
|
30
|
-
showAuto = false;
|
|
31
|
-
}
|
|
32
|
-
console.log('res===showAuto', is4G, enableAutoClarity, showAuto);
|
|
26
|
+
const showAuto = !autoClarityDisabled && canShowAutoClarity(withoutAuto);
|
|
33
27
|
return showAuto ? [...withoutAuto, ClarityType.AUTO] : withoutAuto;
|
|
34
28
|
};
|
|
35
29
|
export const normalizeResolution = (resolution, list) => {
|
package/lib/interface.d.ts
CHANGED
|
@@ -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
package/lib/ui/ui.js
CHANGED
|
@@ -61,11 +61,12 @@ const StandaloneAutoClarity = _ref2 => {
|
|
|
61
61
|
instance: instance
|
|
62
62
|
}));
|
|
63
63
|
};
|
|
64
|
-
function getCtxInstance(instance, devId) {
|
|
64
|
+
function getCtxInstance(instance, devId, autoClarityDisabled) {
|
|
65
65
|
if (instance) return instance;
|
|
66
66
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
67
67
|
return useCtx({
|
|
68
|
-
devId
|
|
68
|
+
devId,
|
|
69
|
+
autoClarityDisabled
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -128,7 +129,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
|
|
|
128
129
|
const {
|
|
129
130
|
event
|
|
130
131
|
} = useContext(UIEventContext);
|
|
131
|
-
const instance = getCtxInstance(props.instance, devId);
|
|
132
|
+
const instance = getCtxInstance(props.instance, devId, props.autoClarityDisabled);
|
|
132
133
|
const {
|
|
133
134
|
setPlayState,
|
|
134
135
|
setScreenType,
|
|
@@ -102,7 +102,6 @@ export function RecordVideo(props) {
|
|
|
102
102
|
playState: props.playState
|
|
103
103
|
});
|
|
104
104
|
const [state, setState] = useSetState({
|
|
105
|
-
showTimer: false,
|
|
106
105
|
showShot: false,
|
|
107
106
|
shotUrl: '',
|
|
108
107
|
shotCount: 0
|
|
@@ -125,7 +124,6 @@ export function RecordVideo(props) {
|
|
|
125
124
|
if (requestId !== recordResultRequestIdRef.current) return;
|
|
126
125
|
if (!summary) return;
|
|
127
126
|
setState({
|
|
128
|
-
showTimer: false,
|
|
129
127
|
showShot: true,
|
|
130
128
|
shotUrl: summary.thumbnailPath,
|
|
131
129
|
shotCount: summary.isMultiLens ? summary.count : 0
|
|
@@ -139,9 +137,6 @@ export function RecordVideo(props) {
|
|
|
139
137
|
(async () => {
|
|
140
138
|
if (playState !== PlayState.PLAYING && recording) {
|
|
141
139
|
try {
|
|
142
|
-
setState({
|
|
143
|
-
showTimer: false
|
|
144
|
-
});
|
|
145
140
|
const recordInfo = await setRecording(false);
|
|
146
141
|
await showRecordResult(recordInfo);
|
|
147
142
|
} catch {
|
|
@@ -180,16 +175,13 @@ export function RecordVideo(props) {
|
|
|
180
175
|
showRecordToast();
|
|
181
176
|
}
|
|
182
177
|
}, [state.showShot, screenType]);
|
|
183
|
-
|
|
184
|
-
/** 根据showTimer的显示定时器 */
|
|
185
178
|
useUpdateEffect(() => {
|
|
186
|
-
if (
|
|
179
|
+
if (recording) {
|
|
187
180
|
showRecordTimer();
|
|
188
181
|
} else {
|
|
189
182
|
deleteContent('absolute', RECORD_VIDEO_TIMER_ID);
|
|
190
|
-
// 清除定时器,元素移除
|
|
191
183
|
}
|
|
192
|
-
}, [
|
|
184
|
+
}, [recording]);
|
|
193
185
|
|
|
194
186
|
/** 跳转相册 */
|
|
195
187
|
const handCheck = () => {
|
|
@@ -236,8 +228,8 @@ export function RecordVideo(props) {
|
|
|
236
228
|
absoluteContentClassName: 'ipc-player-plugin-record-video-toast-wrap',
|
|
237
229
|
content: () => /*#__PURE__*/React.createElement(View, {
|
|
238
230
|
className: clsx('ipc-player-plugin-record-video-toast', {
|
|
239
|
-
'ipc-player-plugin-record-video-toast-show':
|
|
240
|
-
'ipc-player-plugin-record-video-toast-hide': !
|
|
231
|
+
'ipc-player-plugin-record-video-toast-show': recording,
|
|
232
|
+
'ipc-player-plugin-record-video-toast-hide': !recording
|
|
241
233
|
})
|
|
242
234
|
}, /*#__PURE__*/React.createElement(View, {
|
|
243
235
|
className: "ipc-player-plugin-record-video-toast-point",
|
|
@@ -281,9 +273,6 @@ export function RecordVideo(props) {
|
|
|
281
273
|
}
|
|
282
274
|
if (target) {
|
|
283
275
|
setRecordingDisabled(true);
|
|
284
|
-
setState({
|
|
285
|
-
showTimer: true
|
|
286
|
-
});
|
|
287
276
|
/** 录制开始后3秒后才可结束 */
|
|
288
277
|
timeToResetRecordDisabled();
|
|
289
278
|
} else {
|
|
@@ -298,9 +287,6 @@ export function RecordVideo(props) {
|
|
|
298
287
|
toast({
|
|
299
288
|
title: errMsg
|
|
300
289
|
});
|
|
301
|
-
setState({
|
|
302
|
-
showTimer: false
|
|
303
|
-
});
|
|
304
290
|
}
|
|
305
291
|
return true;
|
|
306
292
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
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.map.js";
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import ReactDOM from 'react-dom';
|
|
6
|
+
import { act, Simulate } from 'react-dom/test-utils';
|
|
7
|
+
import { atom, getDefaultStore } from 'jotai';
|
|
8
|
+
import { PlayState } from '../../interface';
|
|
9
|
+
import { RecordVideo } from './recordVideo';
|
|
10
|
+
jest.mock('@ray-js/ray', () => ({
|
|
11
|
+
View: 'div',
|
|
12
|
+
Text: 'span',
|
|
13
|
+
Image: 'img',
|
|
14
|
+
getSystemInfoSync: () => ({
|
|
15
|
+
platform: 'android'
|
|
16
|
+
})
|
|
17
|
+
}));
|
|
18
|
+
jest.mock('@ray-js/ray-ipc-utils', () => ({
|
|
19
|
+
goToIpcPageNativeRoute: jest.fn()
|
|
20
|
+
}));
|
|
21
|
+
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({}));
|
|
22
|
+
jest.mock('../../utils/device', () => ({
|
|
23
|
+
getDeviceInfo: jest.fn()
|
|
24
|
+
}));
|
|
25
|
+
jest.mock('../../i18n', () => ({
|
|
26
|
+
__esModule: true,
|
|
27
|
+
default: {
|
|
28
|
+
getLang: key => key
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
jest.mock('./recordVideo.less', () => ({}));
|
|
32
|
+
jest.mock('../captureResult/captureResult.less', () => ({}));
|
|
33
|
+
describe('RecordVideo', () => {
|
|
34
|
+
let container;
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
jest.useFakeTimers('modern');
|
|
37
|
+
container = document.createElement('div');
|
|
38
|
+
document.body.appendChild(container);
|
|
39
|
+
});
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
act(() => ReactDOM.unmountComponentAtNode(container));
|
|
42
|
+
container.remove();
|
|
43
|
+
jest.clearAllTimers();
|
|
44
|
+
jest.useRealTimers();
|
|
45
|
+
});
|
|
46
|
+
it.each([false, true])('removes the recording timer after stop (remounted: %s)', async remount => {
|
|
47
|
+
var _container$querySelec, _container$querySelec2;
|
|
48
|
+
const store = getDefaultStore();
|
|
49
|
+
const recording = atom(false);
|
|
50
|
+
const recordingDisabled = atom(false);
|
|
51
|
+
const screenType = atom('vertical');
|
|
52
|
+
const setRecording = jest.fn(async value => {
|
|
53
|
+
store.set(recording, value);
|
|
54
|
+
return value ? true : {
|
|
55
|
+
tempImagePath: 'thingfile://record.jpg'
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
function Harness(_ref) {
|
|
59
|
+
let {
|
|
60
|
+
widgetKey
|
|
61
|
+
} = _ref;
|
|
62
|
+
const [contents, setContents] = useState([]);
|
|
63
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RecordVideo, {
|
|
64
|
+
key: widgetKey,
|
|
65
|
+
devId: 'device',
|
|
66
|
+
recording,
|
|
67
|
+
recordingDisabled,
|
|
68
|
+
screenType,
|
|
69
|
+
brandColor: atom('#ff592a'),
|
|
70
|
+
playState: atom(PlayState.PLAYING),
|
|
71
|
+
setRecording,
|
|
72
|
+
setRecordingDisabled: value => store.set(recordingDisabled, value),
|
|
73
|
+
addContent: (_type, content) => setContents(items => [...items, content]),
|
|
74
|
+
deleteContent: (_type, id) => setContents(items => items.filter(item => item.id !== id))
|
|
75
|
+
}), contents.map(item => /*#__PURE__*/React.createElement(item.content, {
|
|
76
|
+
key: item.id
|
|
77
|
+
})));
|
|
78
|
+
}
|
|
79
|
+
const clickRecord = async () => {
|
|
80
|
+
await act(async () => {
|
|
81
|
+
Simulate.click(container.querySelector('.ipc-player-plugin-record-video-icon').parentElement);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
await act(async () => {
|
|
85
|
+
ReactDOM.render(/*#__PURE__*/React.createElement(Harness, {
|
|
86
|
+
widgetKey: 0
|
|
87
|
+
}), container);
|
|
88
|
+
});
|
|
89
|
+
await clickRecord();
|
|
90
|
+
act(() => jest.advanceTimersByTime(3000));
|
|
91
|
+
expect((_container$querySelec = container.querySelector('.ipc-player-plugin-record-video-toast-time')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.textContent).toBe('00:03');
|
|
92
|
+
if (remount) {
|
|
93
|
+
await act(async () => {
|
|
94
|
+
store.set(screenType, 'full');
|
|
95
|
+
ReactDOM.render(/*#__PURE__*/React.createElement(Harness, {
|
|
96
|
+
widgetKey: 1
|
|
97
|
+
}), container);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
expect((_container$querySelec2 = container.querySelector('.ipc-player-plugin-record-video-toast-time')) === null || _container$querySelec2 === void 0 ? void 0 : _container$querySelec2.textContent).toBe('00:03');
|
|
101
|
+
await clickRecord();
|
|
102
|
+
expect(setRecording).toHaveBeenLastCalledWith(false);
|
|
103
|
+
expect(container.querySelector('.icon-panel-record-stop')).toBeNull();
|
|
104
|
+
expect(container.querySelector('.ipc-player-plugin-record-video-toast-time')).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
});
|
package/package.json
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { usePanelConfig } from '@ray-js/panel-sdk';
|
|
3
|
-
import { getAbilityCodeIsOpened } from '../utils/productAbility';
|
|
4
|
-
const TRAFFIC_CAMERA_ABILITY = 'tyabips49q';
|
|
5
|
-
const AUTO_CLARITY_CONFIG = 'tyabij5ce4';
|
|
6
|
-
/** 与 432 面板一致:先取得 4G 能力和面板云开关,再由清晰度列表决定是否加入 Auto。 */
|
|
7
|
-
export const useAutoClarityConfig = devId => {
|
|
8
|
-
var _panelConfig$fun;
|
|
9
|
-
const panelConfig = usePanelConfig();
|
|
10
|
-
const [trafficAbility, setTrafficAbility] = useState(null);
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (!devId) return undefined;
|
|
13
|
-
let active = true;
|
|
14
|
-
getAbilityCodeIsOpened(TRAFFIC_CAMERA_ABILITY, devId).then(data => {
|
|
15
|
-
if (!active) return;
|
|
16
|
-
setTrafficAbility({
|
|
17
|
-
devId,
|
|
18
|
-
is4G: (data === null || data === void 0 ? void 0 : data.isOpen) === true
|
|
19
|
-
});
|
|
20
|
-
}).catch(error => {
|
|
21
|
-
console.warn('获取 4G 能力失败:', error);
|
|
22
|
-
if (active) setTrafficAbility({
|
|
23
|
-
devId,
|
|
24
|
-
is4G: false
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
return () => {
|
|
28
|
-
active = false;
|
|
29
|
-
};
|
|
30
|
-
}, [devId]);
|
|
31
|
-
const configValue = (_panelConfig$fun = panelConfig.fun) === null || _panelConfig$fun === void 0 ? void 0 : _panelConfig$fun[AUTO_CLARITY_CONFIG];
|
|
32
|
-
const abilityReady = (trafficAbility === null || trafficAbility === void 0 ? void 0 : trafficAbility.devId) === devId;
|
|
33
|
-
const is4G = abilityReady && trafficAbility.is4G;
|
|
34
|
-
// 非 4G 设备只需等待能力查询;4G 设备还需等待面板云配置初始化。
|
|
35
|
-
return {
|
|
36
|
-
is4G,
|
|
37
|
-
enableAutoClarity: configValue !== false && configValue !== 'false',
|
|
38
|
-
ready: abilityReady && (!is4G || panelConfig.initialized)
|
|
39
|
-
};
|
|
40
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { apiRequestByAtop } from '@ray-js/ray';
|
|
2
|
-
/** 按 PID 维度查询设备的高级能力。 */
|
|
3
|
-
export const getAbilityCodeIsOpened = (abilityCode, deviceId) => new Promise((resolve, reject) => {
|
|
4
|
-
apiRequestByAtop({
|
|
5
|
-
api: 'm.life.app.device.product.ability',
|
|
6
|
-
postData: {
|
|
7
|
-
abilityCode,
|
|
8
|
-
deviceId
|
|
9
|
-
},
|
|
10
|
-
version: '1.0',
|
|
11
|
-
success: result => {
|
|
12
|
-
try {
|
|
13
|
-
resolve(typeof result === 'string' ? JSON.parse(result) : result);
|
|
14
|
-
} catch (error) {
|
|
15
|
-
reject(error);
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
fail: reject
|
|
19
|
-
});
|
|
20
|
-
});
|