@ray-js/ipc-player-integration 0.0.54 → 0.0.55-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 +33 -134
- package/lib/ctx/resolution.d.ts +8 -0
- package/lib/ctx/resolution.js +30 -0
- package/lib/ctx/useAutoClarity.d.ts +19 -0
- package/lib/ctx/useAutoClarity.js +73 -0
- package/lib/utils/authorize/album.d.ts +1 -0
- package/lib/utils/authorize/album.js +39 -0
- package/lib/utils/authorize/album.test.js +82 -0
- package/lib/widgets/recordVideo/recordVideo.js +5 -1
- package/lib/widgets/recordVideo/recordVideo.test.js +58 -0
- package/lib/widgets/screenshot/screenshot.js +20 -71
- package/lib/widgets/zoomTurntable/lensSkill.js +4 -1
- package/package.json +1 -1
- package/lib/ctx/ctx.autoClarity.test.js +0 -150
- package/lib/ui/useOfflineShownNotification.test.js +0 -98
- package/lib/utils/ttt.autoClarity.test.d.ts +0 -1
- package/lib/utils/ttt.autoClarity.test.js +0 -75
- package/lib/utils/ttt.notifyOfflineShown.test.d.ts +0 -1
- package/lib/utils/ttt.notifyOfflineShown.test.js +0 -30
- package/lib/widgets/videoBitKBP/videoBitKBP.test.d.ts +0 -1
- package/lib/widgets/videoBitKBP/videoBitKBP.test.js +0 -156
- /package/lib/{ctx/ctx.autoClarity.test.d.ts → utils/authorize/album.test.d.ts} +0 -0
- /package/lib/{ui/useOfflineShownNotification.test.d.ts → widgets/recordVideo/recordVideo.test.d.ts} +0 -0
package/lib/ctx/ctx.js
CHANGED
|
@@ -6,13 +6,14 @@ import "core-js/modules/esnext.iterator.map.js";
|
|
|
6
6
|
import { useRef, useCallback, useEffect } from 'react';
|
|
7
7
|
import { getSystemInfoSync, showModal, openAppSystemSettingPage } from '@ray-js/ray';
|
|
8
8
|
import Strings from '../i18n';
|
|
9
|
+
import { ensureAlbumPermission } from '../utils/authorize/album';
|
|
9
10
|
import { useAtom, updateAtom, getDefaultStore, useStore } from './store';
|
|
10
11
|
import { PlayState, IntercomMode } from '../interface';
|
|
11
12
|
import { changeIgnoreHideStopPreview } from '../ui/constant';
|
|
12
|
-
import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
|
|
13
13
|
import { getEventInstance } from './event';
|
|
14
14
|
import { isMultiCameraTileSupported, useMultiCameraCtx } from './multiCameraCtx';
|
|
15
|
-
import {
|
|
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 {
|
|
@@ -108,61 +109,21 @@ export const createUseCtx = _ref => {
|
|
|
108
109
|
_playState: playState,
|
|
109
110
|
currentResolution: resolution
|
|
110
111
|
});
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (!devId) return undefined;
|
|
123
|
-
return subscribeClarityChanged(devId, res => {
|
|
124
|
-
if (getDefaultStore().get(resolution) !== ClarityType.AUTO && !pendingAutoSelectionRef.current) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
freshAutoClarityRef.current = true;
|
|
128
|
-
updateAtom(autoClarity, res.clarity);
|
|
129
|
-
setCachedAutoClarity(devId, res.clarity);
|
|
130
|
-
});
|
|
131
|
-
}, [autoClarity, devId, resolution]);
|
|
112
|
+
const {
|
|
113
|
+
restoreResolution,
|
|
114
|
+
prepareResolutionSelection,
|
|
115
|
+
finishResolutionSelection,
|
|
116
|
+
refreshAfterPlayback
|
|
117
|
+
} = useAutoClarity({
|
|
118
|
+
devId,
|
|
119
|
+
autoClarity,
|
|
120
|
+
resolution,
|
|
121
|
+
playerRef: IPCPlayerInstance
|
|
122
|
+
});
|
|
132
123
|
const eventRef = useRef();
|
|
133
124
|
if (!eventRef.current) {
|
|
134
125
|
eventRef.current = getEventInstance();
|
|
135
126
|
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 只有宿主支持自动清晰度事件,且接口返回的清晰度档位数量不少于 2 个时,才展示 AUTO:
|
|
139
|
-
* 竖屏宿主弹框(由 resolutionList 构建 actionData)与横屏 FullResolutionControl 共用。
|
|
140
|
-
*/
|
|
141
|
-
const canShowAutoClarity = function () {
|
|
142
|
-
let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
143
|
-
return isClarityChangedSupported() && list.length >= 2;
|
|
144
|
-
};
|
|
145
|
-
const withAutoClarity = function () {
|
|
146
|
-
let list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
147
|
-
const withoutAuto = list.filter(clarity => clarity !== ClarityType.AUTO);
|
|
148
|
-
return canShowAutoClarity(list) ? [...withoutAuto, ClarityType.AUTO] : withoutAuto;
|
|
149
|
-
};
|
|
150
|
-
const normalizeResolution = (resolution, list) => {
|
|
151
|
-
if (resolution !== ClarityType.AUTO || canShowAutoClarity(list)) return resolution;
|
|
152
|
-
return list.find(clarity => clarity !== ClarityType.AUTO) || ClarityType.HD;
|
|
153
|
-
};
|
|
154
|
-
const restoreResolution = (cachedResolution, list) => {
|
|
155
|
-
if (userSelectedResolutionRef.current) return;
|
|
156
|
-
const target = normalizeResolution(cachedResolution, list);
|
|
157
|
-
if (target === ClarityType.AUTO) {
|
|
158
|
-
restoredAutoRef.current = true;
|
|
159
|
-
const cachedClarity = getCachedAutoClarity(devId);
|
|
160
|
-
if (cachedClarity && list.includes(cachedClarity) && !getDefaultStore().get(autoClarity)) {
|
|
161
|
-
updateAtom(autoClarity, cachedClarity);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
_setResolution(target, true);
|
|
165
|
-
};
|
|
166
127
|
useEffect(() => {
|
|
167
128
|
// 初始化获取缓存值
|
|
168
129
|
|
|
@@ -172,7 +133,7 @@ export const createUseCtx = _ref => {
|
|
|
172
133
|
var _res$maxZoomSettings;
|
|
173
134
|
const res = await getMemoryState(devId);
|
|
174
135
|
setResolutionList(withAutoClarity(res.resolutionList));
|
|
175
|
-
restoreResolution(res.resolution, res.resolutionList);
|
|
136
|
+
restoreResolution(res.resolution, res.resolutionList, _setResolution);
|
|
176
137
|
_setMute(res.mute, true);
|
|
177
138
|
setIntercomMode(res.intercomMode);
|
|
178
139
|
setIntercomSupported(res.isIntercomSupported);
|
|
@@ -189,7 +150,7 @@ export const createUseCtx = _ref => {
|
|
|
189
150
|
var _res$maxZoomSettings2;
|
|
190
151
|
setResolutionList(withAutoClarity(res.resolutionList));
|
|
191
152
|
// 传true表示值即可,会取播放器的值
|
|
192
|
-
restoreResolution(res.resolution, res.resolutionList);
|
|
153
|
+
restoreResolution(res.resolution, res.resolutionList, _setResolution);
|
|
193
154
|
_setMute(res.mute, true);
|
|
194
155
|
setIntercomMode(res.intercomMode);
|
|
195
156
|
setIntercomSupported(res.isIntercomSupported);
|
|
@@ -198,16 +159,7 @@ export const createUseCtx = _ref => {
|
|
|
198
159
|
}
|
|
199
160
|
}, [devId, _playState]);
|
|
200
161
|
useEffect(() => {
|
|
201
|
-
|
|
202
|
-
if (!devId || _playState !== PlayState.PLAYING || currentResolution !== ClarityType.AUTO || !restoredAutoRef.current || freshAutoClarityRef.current || refreshedAutoRef.current) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
refreshedAutoRef.current = true;
|
|
206
|
-
// 缓存只保证首屏有上次档位;出流后重申自动,让宿主回报本次实际档位。
|
|
207
|
-
(_IPCPlayerInstance$cu = IPCPlayerInstance.current) === null || _IPCPlayerInstance$cu === void 0 || _IPCPlayerInstance$cu.setClarity({
|
|
208
|
-
clarity: 'auto',
|
|
209
|
-
fail: error => console.warn('res===restore auto clarity fail', error)
|
|
210
|
-
});
|
|
162
|
+
refreshAfterPlayback(_playState, currentResolution);
|
|
211
163
|
}, [devId, _playState, currentResolution]);
|
|
212
164
|
// 获取content数据
|
|
213
165
|
const getContent = () => {
|
|
@@ -303,33 +255,18 @@ export const createUseCtx = _ref => {
|
|
|
303
255
|
updateAtom(resolution, target);
|
|
304
256
|
return false;
|
|
305
257
|
}
|
|
306
|
-
|
|
307
|
-
// 清晰度事件可能在 setClarity 的 success 回调前到达,进入自动前先清掉上次的值。
|
|
308
|
-
restoredAutoRef.current = false;
|
|
309
|
-
if (target === ClarityType.AUTO) {
|
|
310
|
-
pendingAutoSelectionRef.current = true;
|
|
311
|
-
updateAtom(autoClarity, null);
|
|
312
|
-
}
|
|
258
|
+
prepareResolutionSelection(target);
|
|
313
259
|
return new Promise((resolve, reject) => {
|
|
314
|
-
const clarityMap = {
|
|
315
|
-
[ClarityType.SS]: 'ss',
|
|
316
|
-
[ClarityType.SD]: 'normal',
|
|
317
|
-
[ClarityType.HD]: 'hd',
|
|
318
|
-
[ClarityType.UD]: 'ud',
|
|
319
|
-
[ClarityType.SSP]: 'ssp',
|
|
320
|
-
[ClarityType.AUTO]: 'auto',
|
|
321
|
-
[ClarityType.AUDIO]: 'audio'
|
|
322
|
-
};
|
|
323
260
|
IPCPlayerInstance.current.setClarity({
|
|
324
|
-
clarity:
|
|
261
|
+
clarity: toNativeClarity(target),
|
|
325
262
|
success: () => {
|
|
326
|
-
|
|
263
|
+
finishResolutionSelection();
|
|
327
264
|
setResolutionMemoryState(devId, target);
|
|
328
265
|
updateAtom(resolution, target);
|
|
329
266
|
resolve(true);
|
|
330
267
|
},
|
|
331
268
|
fail: err => {
|
|
332
|
-
|
|
269
|
+
finishResolutionSelection();
|
|
333
270
|
console.log(err, 'setClarity err');
|
|
334
271
|
// updateAtom(mute, !target);
|
|
335
272
|
reject(err);
|
|
@@ -491,60 +428,22 @@ export const createUseCtx = _ref => {
|
|
|
491
428
|
eventRef.current.emit(changeIgnoreHideStopPreview, false);
|
|
492
429
|
return false;
|
|
493
430
|
}
|
|
431
|
+
if (target) {
|
|
432
|
+
const granted = await ensureAlbumPermission();
|
|
433
|
+
eventRef.current.emit(changeIgnoreHideStopPreview, false);
|
|
434
|
+
if (!granted) return false;
|
|
435
|
+
}
|
|
494
436
|
return new Promise((resolve, reject) => {
|
|
495
437
|
if (target) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
scope: 'scope.writePhotosAlbum',
|
|
438
|
+
IPCPlayerInstance.current.startRecord({
|
|
439
|
+
saveToAlbum,
|
|
499
440
|
success: () => {
|
|
500
|
-
|
|
501
|
-
|
|
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
|
-
});
|
|
441
|
+
updateAtom(recording, true);
|
|
442
|
+
resolve(true);
|
|
512
443
|
},
|
|
513
|
-
fail:
|
|
514
|
-
|
|
515
|
-
|
|
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
|
-
});
|
|
444
|
+
fail: err => {
|
|
445
|
+
eventRef.current.emit(changeIgnoreHideStopPreview, false);
|
|
446
|
+
reject(err);
|
|
548
447
|
}
|
|
549
448
|
});
|
|
550
449
|
} else {
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ensureAlbumPermission(): Promise<boolean>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { authorize, authorizeStatus, getSystemInfoSync, openAppSystemSettingPage, showModal } from '@ray-js/ray';
|
|
2
|
+
import Strings from '../../i18n';
|
|
3
|
+
export async function ensureAlbumPermission() {
|
|
4
|
+
var _system$match;
|
|
5
|
+
const {
|
|
6
|
+
platform,
|
|
7
|
+
system
|
|
8
|
+
} = getSystemInfoSync();
|
|
9
|
+
// Scoped storage does not require the legacy album permission to save media.
|
|
10
|
+
if (platform === 'android' && Number((_system$match = system.match(/\d+/)) === null || _system$match === void 0 ? void 0 : _system$match[0]) >= 10) return true;
|
|
11
|
+
const granted = await new Promise(resolve => {
|
|
12
|
+
authorizeStatus({
|
|
13
|
+
scope: 'scope.writePhotosAlbum',
|
|
14
|
+
success: () => resolve(true),
|
|
15
|
+
fail: () => {
|
|
16
|
+
authorize({
|
|
17
|
+
scope: 'scope.writePhotosAlbum',
|
|
18
|
+
success: () => resolve(true),
|
|
19
|
+
fail: () => resolve(false)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
if (!granted) {
|
|
25
|
+
showModal({
|
|
26
|
+
title: '',
|
|
27
|
+
content: Strings.getLang('ipc_player_no_album_permission'),
|
|
28
|
+
cancelText: Strings.getLang('ipc_player_authorize_cancel_text'),
|
|
29
|
+
confirmText: Strings.getLang('ipc_player_authorize_confirm_text'),
|
|
30
|
+
isShowGlobal: true,
|
|
31
|
+
success: res => {
|
|
32
|
+
if (res.confirm) openAppSystemSettingPage({
|
|
33
|
+
scope: 'App-Settings'
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return granted;
|
|
39
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { authorize, authorizeStatus, getSystemInfoSync, openAppSystemSettingPage, showModal } from '@ray-js/ray';
|
|
2
|
+
import { ensureAlbumPermission } from './album';
|
|
3
|
+
jest.mock('@ray-js/ray', () => ({
|
|
4
|
+
authorize: jest.fn(),
|
|
5
|
+
authorizeStatus: jest.fn(),
|
|
6
|
+
getSystemInfoSync: jest.fn(),
|
|
7
|
+
openAppSystemSettingPage: jest.fn(),
|
|
8
|
+
showModal: jest.fn()
|
|
9
|
+
}));
|
|
10
|
+
jest.mock('../../i18n', () => ({
|
|
11
|
+
__esModule: true,
|
|
12
|
+
default: {
|
|
13
|
+
getLang: key => key
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.resetAllMocks();
|
|
18
|
+
authorizeStatus.mockImplementation(_ref => {
|
|
19
|
+
let {
|
|
20
|
+
fail
|
|
21
|
+
} = _ref;
|
|
22
|
+
return fail({
|
|
23
|
+
errorCode: 9004
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
authorize.mockImplementation(_ref2 => {
|
|
27
|
+
let {
|
|
28
|
+
fail
|
|
29
|
+
} = _ref2;
|
|
30
|
+
return fail({
|
|
31
|
+
errorCode: 9004
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('album permission', () => {
|
|
36
|
+
it.each(['android 10', 'android 12', 'android 15'])('allows native saving on %s without legacy storage access', async system => {
|
|
37
|
+
getSystemInfoSync.mockReturnValue({
|
|
38
|
+
platform: 'android',
|
|
39
|
+
system
|
|
40
|
+
});
|
|
41
|
+
expect(await ensureAlbumPermission()).toBe(true);
|
|
42
|
+
expect(authorizeStatus).not.toHaveBeenCalled();
|
|
43
|
+
expect(authorize).not.toHaveBeenCalled();
|
|
44
|
+
expect(showModal).not.toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
it.each([['ios', 'iOS 18'], ['android', 'android 9'], ['android', 'unknown']])('keeps rejection handling on %s %s', async (platform, system) => {
|
|
47
|
+
getSystemInfoSync.mockReturnValue({
|
|
48
|
+
platform,
|
|
49
|
+
system
|
|
50
|
+
});
|
|
51
|
+
expect(await ensureAlbumPermission()).toBe(false);
|
|
52
|
+
expect(showModal).toHaveBeenCalledTimes(1);
|
|
53
|
+
const {
|
|
54
|
+
success
|
|
55
|
+
} = showModal.mock.calls[0][0];
|
|
56
|
+
success({
|
|
57
|
+
confirm: false
|
|
58
|
+
});
|
|
59
|
+
expect(openAppSystemSettingPage).not.toHaveBeenCalled();
|
|
60
|
+
success({
|
|
61
|
+
confirm: true
|
|
62
|
+
});
|
|
63
|
+
expect(openAppSystemSettingPage).toHaveBeenCalledWith({
|
|
64
|
+
scope: 'App-Settings'
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('allows saving after authorization and checks it again on retry', async () => {
|
|
68
|
+
getSystemInfoSync.mockReturnValue({
|
|
69
|
+
platform: 'ios',
|
|
70
|
+
system: 'iOS 18'
|
|
71
|
+
});
|
|
72
|
+
authorize.mockImplementationOnce(_ref3 => {
|
|
73
|
+
let {
|
|
74
|
+
success
|
|
75
|
+
} = _ref3;
|
|
76
|
+
return success();
|
|
77
|
+
});
|
|
78
|
+
expect(await ensureAlbumPermission()).toBe(true);
|
|
79
|
+
expect(await ensureAlbumPermission()).toBe(false);
|
|
80
|
+
expect(showModal).toHaveBeenCalledTimes(1);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -231,7 +231,7 @@ export function RecordVideo(props) {
|
|
|
231
231
|
};
|
|
232
232
|
const handRecordVideo = async () => {
|
|
233
233
|
var _props$event, _props$event2;
|
|
234
|
-
(_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event;
|
|
234
|
+
const ev = (_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event;
|
|
235
235
|
((_props$event2 = props.event) !== null && _props$event2 !== void 0 ? _props$event2 : event).emit(widgetClick, {
|
|
236
236
|
widgetId: widgetLabs.RECORD_VIDEO
|
|
237
237
|
});
|
|
@@ -256,6 +256,10 @@ export function RecordVideo(props) {
|
|
|
256
256
|
}
|
|
257
257
|
try {
|
|
258
258
|
const recordInfo = await setRecording(target);
|
|
259
|
+
if (recordInfo === false) {
|
|
260
|
+
ev.emit(changeIgnoreHideStopPreview, false);
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
259
263
|
if (target) {
|
|
260
264
|
setRecordingDisabled(true);
|
|
261
265
|
setState({
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-hooks/dom';
|
|
2
|
+
import { atom } from 'jotai';
|
|
3
|
+
import { RecordVideo } from './recordVideo';
|
|
4
|
+
import { PlayState } from '../../interface';
|
|
5
|
+
jest.mock('@ray-js/ray', () => ({
|
|
6
|
+
View: 'div',
|
|
7
|
+
Text: 'span',
|
|
8
|
+
Image: 'img',
|
|
9
|
+
getSystemInfoSync: () => ({
|
|
10
|
+
platform: 'ios',
|
|
11
|
+
system: 'iOS 18'
|
|
12
|
+
})
|
|
13
|
+
}));
|
|
14
|
+
jest.mock('@ray-js/ray-ipc-utils', () => ({
|
|
15
|
+
goToIpcPageNativeRoute: jest.fn()
|
|
16
|
+
}));
|
|
17
|
+
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({}));
|
|
18
|
+
jest.mock('../../i18n', () => ({
|
|
19
|
+
__esModule: true,
|
|
20
|
+
default: {
|
|
21
|
+
getLang: key => key
|
|
22
|
+
}
|
|
23
|
+
}));
|
|
24
|
+
jest.mock('./recordVideo.less', () => ({}));
|
|
25
|
+
it('keeps the record control idle when starting is declined', async () => {
|
|
26
|
+
const addContent = jest.fn();
|
|
27
|
+
const setRecordingDisabled = jest.fn();
|
|
28
|
+
const setRecording = jest.fn().mockResolvedValue(false);
|
|
29
|
+
const toast = jest.fn();
|
|
30
|
+
const props = {
|
|
31
|
+
recording: atom(false),
|
|
32
|
+
brandColor: atom('#000000'),
|
|
33
|
+
screenType: atom('vertical'),
|
|
34
|
+
recordingDisabled: atom(false),
|
|
35
|
+
playState: atom(PlayState.PLAYING),
|
|
36
|
+
setRecording,
|
|
37
|
+
setRecordingDisabled,
|
|
38
|
+
addContent,
|
|
39
|
+
deleteContent: jest.fn(),
|
|
40
|
+
toast,
|
|
41
|
+
devId: 'test-device',
|
|
42
|
+
event: {
|
|
43
|
+
emit: jest.fn()
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const {
|
|
47
|
+
result,
|
|
48
|
+
unmount
|
|
49
|
+
} = renderHook(() => RecordVideo(props));
|
|
50
|
+
await act(async () => {
|
|
51
|
+
await result.current.props.onClick();
|
|
52
|
+
});
|
|
53
|
+
expect(setRecording).toHaveBeenCalledWith(true);
|
|
54
|
+
expect(addContent).not.toHaveBeenCalled();
|
|
55
|
+
expect(setRecordingDisabled).not.toHaveBeenCalled();
|
|
56
|
+
expect(toast).not.toHaveBeenCalled();
|
|
57
|
+
unmount();
|
|
58
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext, useRef } from 'react';
|
|
2
|
-
import { View, Image, Text,
|
|
2
|
+
import { View, Image, Text, getSystemInfoSync } from '@ray-js/ray';
|
|
3
3
|
import { useSetState, useUpdateEffect, useMemoizedFn } from 'ahooks';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';
|
|
@@ -7,6 +7,7 @@ import Strings from '../../i18n';
|
|
|
7
7
|
import { useStore } from '../../ctx/store';
|
|
8
8
|
import { UIEventContext } from '../../ui/context';
|
|
9
9
|
import { pauseTimeToHideAllComponent, changeIgnoreHideStopPreview, widgetLabs, widgetClick } from '../../ui/constant';
|
|
10
|
+
import { ensureAlbumPermission } from '../../utils/authorize/album';
|
|
10
11
|
import './screenshot.less';
|
|
11
12
|
const CLOSE_TIME = 5000;
|
|
12
13
|
export function Screenshot(props) {
|
|
@@ -101,9 +102,9 @@ export function Screenshot(props) {
|
|
|
101
102
|
});
|
|
102
103
|
timeToCloseToast();
|
|
103
104
|
};
|
|
104
|
-
const handClick = useMemoizedFn(() => {
|
|
105
|
+
const handClick = useMemoizedFn(async () => {
|
|
105
106
|
var _props$event, _props$event2;
|
|
106
|
-
(_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event;
|
|
107
|
+
const ev = (_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event;
|
|
107
108
|
((_props$event2 = props.event) !== null && _props$event2 !== void 0 ? _props$event2 : event).emit(widgetClick, {
|
|
108
109
|
widgetId: widgetLabs.SCREENSHOT
|
|
109
110
|
});
|
|
@@ -118,76 +119,24 @@ export function Screenshot(props) {
|
|
|
118
119
|
props.event ? props.event.emit(changeIgnoreHideStopPreview, true) : event.emit(changeIgnoreHideStopPreview, true);
|
|
119
120
|
}
|
|
120
121
|
event.emit(pauseTimeToHideAllComponent);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
props.event ? props.event.emit(changeIgnoreHideStopPreview, false) : event.emit(changeIgnoreHideStopPreview, false);
|
|
132
|
-
setState({
|
|
133
|
-
showShot: true,
|
|
134
|
-
shotUrl: res.tempImagePath
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
fail: err => {
|
|
138
|
-
props.event ? props.event.emit(changeIgnoreHideStopPreview, false) : event.emit(changeIgnoreHideStopPreview, false);
|
|
139
|
-
console.log(err, 'err');
|
|
140
|
-
const errObj = err.innerError || err || {};
|
|
141
|
-
const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_error_screenshot_error_tip');
|
|
142
|
-
toast({
|
|
143
|
-
title: errMsg
|
|
144
|
-
});
|
|
145
|
-
}
|
|
122
|
+
const granted = await ensureAlbumPermission();
|
|
123
|
+
ev.emit(changeIgnoreHideStopPreview, false);
|
|
124
|
+
if (!granted) return;
|
|
125
|
+
IPCPlayerContext.snapshot({
|
|
126
|
+
saveToAlbum,
|
|
127
|
+
success: res => {
|
|
128
|
+
ev.emit(changeIgnoreHideStopPreview, false);
|
|
129
|
+
setState({
|
|
130
|
+
showShot: true,
|
|
131
|
+
shotUrl: res.tempImagePath
|
|
146
132
|
});
|
|
147
133
|
},
|
|
148
|
-
fail:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// 保存到 IPC 相册
|
|
155
|
-
success: res => {
|
|
156
|
-
console.log(res, 'res');
|
|
157
|
-
setState({
|
|
158
|
-
showShot: true,
|
|
159
|
-
shotUrl: res.tempImagePath
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
fail: err => {
|
|
163
|
-
console.log(err, 'err');
|
|
164
|
-
const errObj = err.innerError || err || {};
|
|
165
|
-
const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_error_screenshot_error_tip');
|
|
166
|
-
toast({
|
|
167
|
-
title: errMsg
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
fail: () => {
|
|
173
|
-
showModal({
|
|
174
|
-
title: '',
|
|
175
|
-
content: Strings.getLang('ipc_player_no_album_permission'),
|
|
176
|
-
cancelText: Strings.getLang('ipc_player_authorize_cancel_text'),
|
|
177
|
-
confirmText: Strings.getLang('ipc_player_authorize_confirm_text'),
|
|
178
|
-
isShowGlobal: true,
|
|
179
|
-
success: res => {
|
|
180
|
-
if (res.confirm) {
|
|
181
|
-
openAppSystemSettingPage({
|
|
182
|
-
scope: 'App-Settings',
|
|
183
|
-
success: () => {
|
|
184
|
-
console.log('跳转成功');
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
134
|
+
fail: err => {
|
|
135
|
+
ev.emit(changeIgnoreHideStopPreview, false);
|
|
136
|
+
const errObj = err.innerError || err || {};
|
|
137
|
+
const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_error_screenshot_error_tip');
|
|
138
|
+
toast({
|
|
139
|
+
title: errMsg
|
|
191
140
|
});
|
|
192
141
|
}
|
|
193
142
|
});
|
|
@@ -126,7 +126,10 @@ export const isSwitchChannelSupported = () => {
|
|
|
126
126
|
const supported = typeof ((_ty = ty) === null || _ty === void 0 || (_ty = _ty.ipc) === null || _ty === void 0 ? void 0 : _ty.switchChannel) === 'function';
|
|
127
127
|
if (!supported && !switchChannelMissingLogged) {
|
|
128
128
|
switchChannelMissingLogged = true;
|
|
129
|
-
console.warn
|
|
129
|
+
// 只能用 log:本判定会在 render 期被调用,而 IDE 宿主下 render 期的 console.warn
|
|
130
|
+
// 会打坏 Ray 运行时,整个面板崩在 areHookInputsEqual / TDZ —— 且症状伪装成
|
|
131
|
+
// 「hook 顺序错位」(报 change in the order of Hooks),极难归因,勿改回 warn
|
|
132
|
+
console.log('[zoomTurntable] 宿主不支持 ty.ipc.switchChannel,焦距转盘入口不展示');
|
|
130
133
|
dumpChannelApis();
|
|
131
134
|
}
|
|
132
135
|
return supported;
|
package/package.json
CHANGED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import { act, renderHook } from '@testing-library/react-hooks';
|
|
3
|
-
import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
|
|
4
|
-
import { createUseCtx } from './ctx';
|
|
5
|
-
import { useStore } from './store';
|
|
6
|
-
import { PlayState } from '../interface';
|
|
7
|
-
import { getCachedAutoClarity, setCachedAutoClarity, subscribeClarityChanged } from '../utils/ttt';
|
|
8
|
-
jest.mock('@ray-js/ray', () => ({}));
|
|
9
|
-
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
|
|
10
|
-
ClarityType: {
|
|
11
|
-
SS: 'SS',
|
|
12
|
-
SD: 'SD',
|
|
13
|
-
HD: 'HD',
|
|
14
|
-
UD: 'UD',
|
|
15
|
-
SSP: 'SSP',
|
|
16
|
-
AUTO: 'AUTO',
|
|
17
|
-
AUDIO: 'AUDIO'
|
|
18
|
-
},
|
|
19
|
-
IntercomMode: {
|
|
20
|
-
OneWay: 'OneWay',
|
|
21
|
-
TwoWay: 'TwoWay'
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
jest.mock('../i18n', () => ({
|
|
25
|
-
__esModule: true,
|
|
26
|
-
default: {
|
|
27
|
-
getLang: key => key
|
|
28
|
-
}
|
|
29
|
-
}));
|
|
30
|
-
jest.mock('./multiCameraCtx', () => ({
|
|
31
|
-
isMultiCameraTileSupported: () => false,
|
|
32
|
-
useMultiCameraCtx: () => ({})
|
|
33
|
-
}));
|
|
34
|
-
jest.mock('../utils/ttt', () => ({
|
|
35
|
-
getCachedAutoClarity: jest.fn(),
|
|
36
|
-
isClarityChangedSupported: () => true,
|
|
37
|
-
setCachedAutoClarity: jest.fn(),
|
|
38
|
-
subscribeClarityChanged: jest.fn(() => () => undefined)
|
|
39
|
-
}));
|
|
40
|
-
const cameraState = resolution => ({
|
|
41
|
-
resolution,
|
|
42
|
-
resolutionList: [ClarityType.HD, ClarityType.SD],
|
|
43
|
-
mute: true,
|
|
44
|
-
intercomMode: 'TwoWay',
|
|
45
|
-
isIntercomSupported: false,
|
|
46
|
-
maxZoomSettings: 6
|
|
47
|
-
});
|
|
48
|
-
describe('cached auto clarity restoration', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
jest.clearAllMocks();
|
|
51
|
-
});
|
|
52
|
-
const mountContext = resolution => {
|
|
53
|
-
const setClarity = jest.fn();
|
|
54
|
-
const getMemoryState = jest.fn().mockResolvedValue(cameraState(resolution));
|
|
55
|
-
const useCtx = createUseCtx({
|
|
56
|
-
createPlayContext: () => ({
|
|
57
|
-
setClarity
|
|
58
|
-
}),
|
|
59
|
-
getMemoryState,
|
|
60
|
-
setResolutionMemoryState: jest.fn(),
|
|
61
|
-
setMuteMemoryState: jest.fn(),
|
|
62
|
-
authorizeStatus: jest.fn(),
|
|
63
|
-
toast: jest.fn()
|
|
64
|
-
});
|
|
65
|
-
const hook = renderHook(() => {
|
|
66
|
-
const ctx = useCtx({
|
|
67
|
-
devId: 'camera-1'
|
|
68
|
-
});
|
|
69
|
-
const state = useStore({
|
|
70
|
-
resolution: ctx.resolution,
|
|
71
|
-
autoClarity: ctx.autoClarity
|
|
72
|
-
});
|
|
73
|
-
return _objectSpread(_objectSpread({}, ctx), {}, {
|
|
74
|
-
state
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
return _objectSpread(_objectSpread({}, hook), {}, {
|
|
78
|
-
setClarity
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
it('shows last listener value on reopening AUTO and refreshes it after preview', async () => {
|
|
82
|
-
getCachedAutoClarity.mockReturnValue(ClarityType.HD);
|
|
83
|
-
const {
|
|
84
|
-
result,
|
|
85
|
-
setClarity,
|
|
86
|
-
unmount
|
|
87
|
-
} = mountContext(ClarityType.AUTO);
|
|
88
|
-
await act(async () => Promise.resolve());
|
|
89
|
-
expect(result.current.state).toEqual({
|
|
90
|
-
resolution: ClarityType.AUTO,
|
|
91
|
-
autoClarity: ClarityType.HD
|
|
92
|
-
});
|
|
93
|
-
act(() => result.current.setPlayState(PlayState.PLAYING));
|
|
94
|
-
await act(async () => Promise.resolve());
|
|
95
|
-
expect(setClarity).toHaveBeenCalledTimes(1);
|
|
96
|
-
expect(setClarity).toHaveBeenCalledWith(expect.objectContaining({
|
|
97
|
-
clarity: 'auto'
|
|
98
|
-
}));
|
|
99
|
-
const onReport = subscribeClarityChanged.mock.calls[0][1];
|
|
100
|
-
act(() => onReport({
|
|
101
|
-
deviceId: 'camera-1',
|
|
102
|
-
clarity: ClarityType.SD
|
|
103
|
-
}));
|
|
104
|
-
expect(result.current.state.autoClarity).toBe(ClarityType.SD);
|
|
105
|
-
expect(setCachedAutoClarity).toHaveBeenCalledWith('camera-1', ClarityType.SD);
|
|
106
|
-
unmount();
|
|
107
|
-
});
|
|
108
|
-
it('does not restore cached actual clarity in manual mode', async () => {
|
|
109
|
-
getCachedAutoClarity.mockReturnValue(ClarityType.HD);
|
|
110
|
-
const {
|
|
111
|
-
result,
|
|
112
|
-
unmount
|
|
113
|
-
} = mountContext(ClarityType.SD);
|
|
114
|
-
await act(async () => Promise.resolve());
|
|
115
|
-
expect(result.current.state).toEqual({
|
|
116
|
-
resolution: ClarityType.SD,
|
|
117
|
-
autoClarity: null
|
|
118
|
-
});
|
|
119
|
-
expect(getCachedAutoClarity).not.toHaveBeenCalled();
|
|
120
|
-
const onReport = subscribeClarityChanged.mock.calls[0][1];
|
|
121
|
-
act(() => onReport({
|
|
122
|
-
deviceId: 'camera-1',
|
|
123
|
-
clarity: ClarityType.HD
|
|
124
|
-
}));
|
|
125
|
-
expect(result.current.state.autoClarity).toBeNull();
|
|
126
|
-
expect(setCachedAutoClarity).not.toHaveBeenCalled();
|
|
127
|
-
unmount();
|
|
128
|
-
});
|
|
129
|
-
it('requests a fresh report when reopening AUTO without an actual clarity cache', async () => {
|
|
130
|
-
getCachedAutoClarity.mockReturnValue(null);
|
|
131
|
-
const {
|
|
132
|
-
result,
|
|
133
|
-
setClarity,
|
|
134
|
-
unmount
|
|
135
|
-
} = mountContext(ClarityType.AUTO);
|
|
136
|
-
await act(async () => Promise.resolve());
|
|
137
|
-
expect(result.current.state.autoClarity).toBeNull();
|
|
138
|
-
act(() => result.current.setPlayState(PlayState.PLAYING));
|
|
139
|
-
expect(setClarity).toHaveBeenCalledWith(expect.objectContaining({
|
|
140
|
-
clarity: 'auto'
|
|
141
|
-
}));
|
|
142
|
-
const onReport = subscribeClarityChanged.mock.calls[0][1];
|
|
143
|
-
act(() => onReport({
|
|
144
|
-
deviceId: 'camera-1',
|
|
145
|
-
clarity: ClarityType.HD
|
|
146
|
-
}));
|
|
147
|
-
expect(result.current.state.autoClarity).toBe(ClarityType.HD);
|
|
148
|
-
unmount();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
|
|
2
|
-
import { getCachedAutoClarity, setCachedAutoClarity, subscribeClarityChanged } from './ttt';
|
|
3
|
-
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
|
|
4
|
-
ClarityType: {
|
|
5
|
-
SS: 'SS',
|
|
6
|
-
SD: 'SD',
|
|
7
|
-
HD: 'HD',
|
|
8
|
-
UD: 'UD',
|
|
9
|
-
SSP: 'SSP',
|
|
10
|
-
AUTO: 'AUTO',
|
|
11
|
-
AUDIO: 'AUDIO'
|
|
12
|
-
}
|
|
13
|
-
}));
|
|
14
|
-
describe('auto clarity cache and listener', () => {
|
|
15
|
-
const storage = new Map();
|
|
16
|
-
let listener;
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
storage.clear();
|
|
19
|
-
globalThis.ty = {
|
|
20
|
-
getStorageSync: jest.fn(_ref => {
|
|
21
|
-
let {
|
|
22
|
-
key
|
|
23
|
-
} = _ref;
|
|
24
|
-
return storage.get(key);
|
|
25
|
-
}),
|
|
26
|
-
setStorageSync: jest.fn(_ref2 => {
|
|
27
|
-
let {
|
|
28
|
-
key,
|
|
29
|
-
data
|
|
30
|
-
} = _ref2;
|
|
31
|
-
return storage.set(key, data);
|
|
32
|
-
}),
|
|
33
|
-
ipc: {
|
|
34
|
-
onClarityChanged: jest.fn(callback => {
|
|
35
|
-
listener = callback;
|
|
36
|
-
}),
|
|
37
|
-
offClarityChanged: jest.fn()
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
it('restores the last reported actual clarity only for its device', () => {
|
|
42
|
-
setCachedAutoClarity('camera-1', ClarityType.HD);
|
|
43
|
-
expect(getCachedAutoClarity('camera-1')).toBe(ClarityType.HD);
|
|
44
|
-
expect(getCachedAutoClarity('camera-2')).toBeNull();
|
|
45
|
-
setCachedAutoClarity('camera-1', ClarityType.AUTO);
|
|
46
|
-
expect(getCachedAutoClarity('camera-1')).toBe(ClarityType.HD);
|
|
47
|
-
globalThis.ty.getStorageSync = jest.fn(() => ({
|
|
48
|
-
data: ClarityType.SD
|
|
49
|
-
}));
|
|
50
|
-
expect(getCachedAutoClarity('camera-1')).toBe(ClarityType.SD);
|
|
51
|
-
});
|
|
52
|
-
it('accepts a new actual clarity report for the same device', () => {
|
|
53
|
-
const handler = jest.fn();
|
|
54
|
-
const unsubscribe = subscribeClarityChanged('camera-1', handler);
|
|
55
|
-
listener({
|
|
56
|
-
deviceId: 'camera-2',
|
|
57
|
-
clarity: ClarityType.SD
|
|
58
|
-
});
|
|
59
|
-
listener({
|
|
60
|
-
deviceId: 'camera-1',
|
|
61
|
-
clarity: ClarityType.AUTO
|
|
62
|
-
});
|
|
63
|
-
listener({
|
|
64
|
-
deviceId: 'camera-1',
|
|
65
|
-
clarity: ClarityType.SD
|
|
66
|
-
});
|
|
67
|
-
expect(handler).toHaveBeenCalledTimes(1);
|
|
68
|
-
expect(handler).toHaveBeenCalledWith({
|
|
69
|
-
deviceId: 'camera-1',
|
|
70
|
-
clarity: ClarityType.SD
|
|
71
|
-
});
|
|
72
|
-
unsubscribe();
|
|
73
|
-
expect(globalThis.ty.ipc.offClarityChanged).toHaveBeenCalledWith(listener);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { notifyOfflineShown } from './ttt';
|
|
2
|
-
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
|
|
3
|
-
ClarityType: {}
|
|
4
|
-
}));
|
|
5
|
-
describe('notifyOfflineShown', () => {
|
|
6
|
-
const originalTy = globalThis.ty;
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
globalThis.ty = originalTy;
|
|
9
|
-
});
|
|
10
|
-
it('passes the device ID and scene as one object to the TTT method', () => {
|
|
11
|
-
const nativeNotify = jest.fn();
|
|
12
|
-
globalThis.ty = {
|
|
13
|
-
ipc: {
|
|
14
|
-
notifyOfflineShown: nativeNotify
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
expect(notifyOfflineShown('camera-1')).toBe(true);
|
|
18
|
-
expect(nativeNotify).toHaveBeenCalledTimes(1);
|
|
19
|
-
expect(nativeNotify).toHaveBeenCalledWith({
|
|
20
|
-
deviceId: 'camera-1',
|
|
21
|
-
scene: 'preview_mini'
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
it('skips hosts without the TTT method', () => {
|
|
25
|
-
globalThis.ty = {
|
|
26
|
-
ipc: {}
|
|
27
|
-
};
|
|
28
|
-
expect(notifyOfflineShown('camera-1')).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
-
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
|
-
import { renderToStaticMarkup } from 'react-dom/server';
|
|
6
|
-
import { act } from 'react-dom/test-utils';
|
|
7
|
-
import { getVideoBitrateKbps, requestWifiSignal } from '@ray-js/ray-ipc-utils';
|
|
8
|
-
let mockStoreState;
|
|
9
|
-
jest.mock('@ray-js/ray', () => ({
|
|
10
|
-
View: _ref => {
|
|
11
|
-
let {
|
|
12
|
-
children,
|
|
13
|
-
className
|
|
14
|
-
} = _ref;
|
|
15
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
16
|
-
className: className
|
|
17
|
-
}, children);
|
|
18
|
-
},
|
|
19
|
-
Text: _ref2 => {
|
|
20
|
-
let {
|
|
21
|
-
children,
|
|
22
|
-
className
|
|
23
|
-
} = _ref2;
|
|
24
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
25
|
-
className: className
|
|
26
|
-
}, children);
|
|
27
|
-
},
|
|
28
|
-
usePageEvent: () => undefined
|
|
29
|
-
}));
|
|
30
|
-
jest.mock('@ray-js/ray-ipc-utils', () => ({
|
|
31
|
-
getVideoBitrateKbps: jest.fn(),
|
|
32
|
-
requestWifiSignal: jest.fn()
|
|
33
|
-
}));
|
|
34
|
-
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
|
|
35
|
-
ClarityType: {
|
|
36
|
-
SS: 'SS',
|
|
37
|
-
SD: 'SD',
|
|
38
|
-
HD: 'HD',
|
|
39
|
-
UD: 'UD',
|
|
40
|
-
SSP: 'SSP',
|
|
41
|
-
AUTO: 'AUTO',
|
|
42
|
-
AUDIO: 'AUDIO'
|
|
43
|
-
}
|
|
44
|
-
}));
|
|
45
|
-
jest.mock('../../ctx/store', () => ({
|
|
46
|
-
useStore: () => mockStoreState
|
|
47
|
-
}));
|
|
48
|
-
jest.mock('../../i18n', () => ({
|
|
49
|
-
__esModule: true,
|
|
50
|
-
default: {
|
|
51
|
-
getLang: key => key
|
|
52
|
-
}
|
|
53
|
-
}));
|
|
54
|
-
jest.mock('./videoBitKBP.less', () => ({}));
|
|
55
|
-
const {
|
|
56
|
-
VideoBitKBP
|
|
57
|
-
} = require('./videoBitKBP');
|
|
58
|
-
const renderWidget = function (resolution, autoClarity) {
|
|
59
|
-
let playState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
60
|
-
let hideKbsMenu = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
61
|
-
mockStoreState = {
|
|
62
|
-
resolution,
|
|
63
|
-
autoClarity,
|
|
64
|
-
playState
|
|
65
|
-
};
|
|
66
|
-
return renderToStaticMarkup(/*#__PURE__*/React.createElement(VideoBitKBP, {
|
|
67
|
-
devId: 'device',
|
|
68
|
-
playState: {},
|
|
69
|
-
resolution: {},
|
|
70
|
-
autoClarity: {},
|
|
71
|
-
hideKbsMenu,
|
|
72
|
-
hideSignalMenu: true
|
|
73
|
-
}));
|
|
74
|
-
};
|
|
75
|
-
describe('VideoBitKBP auto clarity', () => {
|
|
76
|
-
it('renders clarity, bitrate and unit in one text line', async () => {
|
|
77
|
-
const container = document.createElement('div');
|
|
78
|
-
getVideoBitrateKbps.mockResolvedValue({
|
|
79
|
-
code: 0,
|
|
80
|
-
data: {
|
|
81
|
-
kbps: '128'
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
mockStoreState = {
|
|
85
|
-
resolution: 'AUTO',
|
|
86
|
-
autoClarity: 'HD',
|
|
87
|
-
playState: 1
|
|
88
|
-
};
|
|
89
|
-
try {
|
|
90
|
-
await act(async () => {
|
|
91
|
-
ReactDOM.render(/*#__PURE__*/React.createElement(VideoBitKBP, {
|
|
92
|
-
devId: 'device',
|
|
93
|
-
hideKbsMenu: false,
|
|
94
|
-
hideSignalMenu: true
|
|
95
|
-
}), container);
|
|
96
|
-
});
|
|
97
|
-
expect(container.innerHTML).toContain('<span class="ipc-player-plugin-videoBitKBP-kbps-text">ipc_player_resolution_HD 128 KB/S</span>');
|
|
98
|
-
} finally {
|
|
99
|
-
ReactDOM.unmountComponentAtNode(container);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
it('keeps signal and auto clarity in the same bitrate badge', async () => {
|
|
103
|
-
const container = document.createElement('div');
|
|
104
|
-
getVideoBitrateKbps.mockResolvedValue({
|
|
105
|
-
code: 0,
|
|
106
|
-
data: {
|
|
107
|
-
kbps: '128'
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
requestWifiSignal.mockResolvedValue({
|
|
111
|
-
code: 0,
|
|
112
|
-
data: '-60'
|
|
113
|
-
});
|
|
114
|
-
mockStoreState = {
|
|
115
|
-
resolution: 'AUTO',
|
|
116
|
-
autoClarity: 'HD',
|
|
117
|
-
playState: 1
|
|
118
|
-
};
|
|
119
|
-
try {
|
|
120
|
-
var _container$querySelec, _container$querySelec2, _container$querySelec3, _container$querySelec4, _container$querySelec5;
|
|
121
|
-
await act(async () => {
|
|
122
|
-
ReactDOM.render(/*#__PURE__*/React.createElement(VideoBitKBP, {
|
|
123
|
-
devId: 'device'
|
|
124
|
-
}), container);
|
|
125
|
-
});
|
|
126
|
-
expect((_container$querySelec = container.querySelector('.ipc-player-plugin-videoBitKBP-signal')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.textContent).toBe('-60dBm');
|
|
127
|
-
expect((_container$querySelec2 = container.querySelector('.ipc-player-plugin-videoBitKBP-kbps')) === null || _container$querySelec2 === void 0 ? void 0 : _container$querySelec2.textContent).toBe('ipc_player_resolution_HD 128 KB/S');
|
|
128
|
-
expect(Array.from((_container$querySelec3 = (_container$querySelec4 = container.querySelector('.ipc-player-plugin-videoBitKBP-content')) === null || _container$querySelec4 === void 0 ? void 0 : _container$querySelec4.children) !== null && _container$querySelec3 !== void 0 ? _container$querySelec3 : []).map(element => element.className)).toEqual(['ipc-player-plugin-videoBitKBP-signal', 'ipc-player-plugin-videoBitKBP-divider', 'ipc-player-plugin-videoBitKBP-kbps']);
|
|
129
|
-
mockStoreState = {
|
|
130
|
-
resolution: 'HD',
|
|
131
|
-
autoClarity: 'HD',
|
|
132
|
-
playState: 1
|
|
133
|
-
};
|
|
134
|
-
act(() => {
|
|
135
|
-
ReactDOM.render(/*#__PURE__*/React.createElement(VideoBitKBP, {
|
|
136
|
-
devId: 'device'
|
|
137
|
-
}), container);
|
|
138
|
-
});
|
|
139
|
-
expect((_container$querySelec5 = container.querySelector('.ipc-player-plugin-videoBitKBP-kbps')) === null || _container$querySelec5 === void 0 ? void 0 : _container$querySelec5.textContent).toBe('128 KB/S');
|
|
140
|
-
} finally {
|
|
141
|
-
ReactDOM.unmountComponentAtNode(container);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
it('shows actual clarity independently of bitrate, signal and play state', () => {
|
|
145
|
-
const markup = renderWidget('AUTO', 'HD', 2);
|
|
146
|
-
expect(markup).toContain('ipc_player_resolution_HD');
|
|
147
|
-
expect(markup).not.toContain('KB/S');
|
|
148
|
-
expect(markup).toContain('<span class="ipc-player-plugin-videoBitKBP-kbps-text">ipc_player_resolution_HD</span>');
|
|
149
|
-
});
|
|
150
|
-
it('does not show clarity outside auto mode', () => {
|
|
151
|
-
expect(renderWidget('SD', 'HD')).toBe('');
|
|
152
|
-
});
|
|
153
|
-
it('waits for the native clarity report in auto mode', () => {
|
|
154
|
-
expect(renderWidget('AUTO', null)).toBe('');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
File without changes
|
/package/lib/{ui/useOfflineShownNotification.test.d.ts → widgets/recordVideo/recordVideo.test.d.ts}
RENAMED
|
File without changes
|