@ray-js/ipc-player-integration 0.0.53-beta.15 → 0.0.53-beta.17
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.album.test.d.ts +1 -0
- package/lib/ctx/ctx.album.test.js +179 -0
- package/lib/ctx/ctx.js +11 -44
- package/lib/ui/useOfflineShownNotification.js +6 -1
- package/lib/ui/useOfflineShownNotification.test.js +38 -0
- package/lib/utils/authorize/album.d.ts +1 -0
- package/lib/utils/authorize/album.js +39 -0
- package/lib/utils/authorize/album.test.d.ts +1 -0
- package/lib/utils/authorize/album.test.js +82 -0
- package/lib/widgets/recordVideo/recordVideo.js +5 -0
- package/lib/widgets/recordVideo/recordVideo.test.d.ts +1 -0
- package/lib/widgets/recordVideo/recordVideo.test.js +59 -0
- package/lib/widgets/screenshot/screenshot.js +8 -39
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { act, renderHook } from '@testing-library/react-hooks/dom';
|
|
3
|
+
import { authorize, authorizeStatus, getSystemInfoSync, showModal } from '@ray-js/ray';
|
|
4
|
+
import { createUseCtx } from './ctx';
|
|
5
|
+
import { useStore } from './store';
|
|
6
|
+
jest.mock('@ray-js/ray', () => ({
|
|
7
|
+
authorize: jest.fn(),
|
|
8
|
+
authorizeStatus: jest.fn(),
|
|
9
|
+
getSystemInfoSync: jest.fn(),
|
|
10
|
+
openAppSystemSettingPage: jest.fn(),
|
|
11
|
+
showModal: jest.fn()
|
|
12
|
+
}));
|
|
13
|
+
jest.mock('@ray-js/ray-ipc-utils/lib/interface', () => ({
|
|
14
|
+
ClarityType: {
|
|
15
|
+
HD: 'HD',
|
|
16
|
+
SD: 'SD',
|
|
17
|
+
AUTO: 'AUTO'
|
|
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: () => false,
|
|
37
|
+
setCachedAutoClarity: jest.fn(),
|
|
38
|
+
subscribeClarityChanged: () => () => undefined
|
|
39
|
+
}));
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
jest.clearAllMocks();
|
|
42
|
+
getSystemInfoSync.mockReturnValue({
|
|
43
|
+
platform: 'android',
|
|
44
|
+
system: 'android 12'
|
|
45
|
+
});
|
|
46
|
+
authorizeStatus.mockImplementation(_ref => {
|
|
47
|
+
let {
|
|
48
|
+
fail
|
|
49
|
+
} = _ref;
|
|
50
|
+
return fail({
|
|
51
|
+
errorCode: 9004
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
authorize.mockImplementation(_ref2 => {
|
|
55
|
+
let {
|
|
56
|
+
fail
|
|
57
|
+
} = _ref2;
|
|
58
|
+
return fail({
|
|
59
|
+
errorCode: 9004
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
const mountContext = () => {
|
|
64
|
+
const capture = {
|
|
65
|
+
tempImagePath: 'thingfile://capture.jpg',
|
|
66
|
+
filePath: 'thingfile://record.mp4'
|
|
67
|
+
};
|
|
68
|
+
const startRecord = jest.fn(_ref3 => {
|
|
69
|
+
let {
|
|
70
|
+
success
|
|
71
|
+
} = _ref3;
|
|
72
|
+
return success();
|
|
73
|
+
});
|
|
74
|
+
const stopRecord = jest.fn(_ref4 => {
|
|
75
|
+
let {
|
|
76
|
+
success
|
|
77
|
+
} = _ref4;
|
|
78
|
+
return success(capture);
|
|
79
|
+
});
|
|
80
|
+
const useCtx = createUseCtx({
|
|
81
|
+
createPlayContext: () => ({
|
|
82
|
+
startRecord,
|
|
83
|
+
stopRecord
|
|
84
|
+
}),
|
|
85
|
+
getMemoryState: jest.fn().mockResolvedValue({
|
|
86
|
+
resolution: 'HD',
|
|
87
|
+
resolutionList: ['HD', 'SD'],
|
|
88
|
+
mute: true,
|
|
89
|
+
intercomMode: 'TwoWay',
|
|
90
|
+
isIntercomSupported: false
|
|
91
|
+
}),
|
|
92
|
+
setResolutionMemoryState: jest.fn(),
|
|
93
|
+
setMuteMemoryState: jest.fn(),
|
|
94
|
+
authorizeStatus: jest.fn(),
|
|
95
|
+
toast: jest.fn()
|
|
96
|
+
});
|
|
97
|
+
const hook = renderHook(() => {
|
|
98
|
+
const ctx = useCtx({
|
|
99
|
+
devId: 'camera-1',
|
|
100
|
+
multiLens: true
|
|
101
|
+
});
|
|
102
|
+
const state = useStore({
|
|
103
|
+
recording: ctx.recording
|
|
104
|
+
});
|
|
105
|
+
return _objectSpread(_objectSpread({}, ctx), {}, {
|
|
106
|
+
state
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return _objectSpread(_objectSpread({}, hook), {}, {
|
|
110
|
+
startRecord,
|
|
111
|
+
stopRecord,
|
|
112
|
+
capture
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
it('starts without legacy authorization and retains the native stop result', async () => {
|
|
116
|
+
const {
|
|
117
|
+
result,
|
|
118
|
+
startRecord,
|
|
119
|
+
stopRecord,
|
|
120
|
+
capture,
|
|
121
|
+
unmount
|
|
122
|
+
} = mountContext();
|
|
123
|
+
await act(async () => {
|
|
124
|
+
expect(await result.current.setRecording(true)).toBe(true);
|
|
125
|
+
});
|
|
126
|
+
expect(startRecord).toHaveBeenCalledWith(expect.objectContaining({
|
|
127
|
+
saveToAlbum: 1
|
|
128
|
+
}));
|
|
129
|
+
expect(result.current.state.recording).toBe(true);
|
|
130
|
+
expect(result.current.multiLens).toBe(true);
|
|
131
|
+
await act(async () => {
|
|
132
|
+
expect(await result.current.setRecording(false)).toEqual(capture);
|
|
133
|
+
});
|
|
134
|
+
expect(stopRecord).toHaveBeenCalledTimes(1);
|
|
135
|
+
expect(result.current.state.recording).toBe(false);
|
|
136
|
+
expect(authorizeStatus).not.toHaveBeenCalled();
|
|
137
|
+
expect(authorize).not.toHaveBeenCalled();
|
|
138
|
+
unmount();
|
|
139
|
+
});
|
|
140
|
+
it('settles a denied start without calling the native recorder', async () => {
|
|
141
|
+
getSystemInfoSync.mockReturnValue({
|
|
142
|
+
platform: 'ios',
|
|
143
|
+
system: 'iOS 18'
|
|
144
|
+
});
|
|
145
|
+
const {
|
|
146
|
+
result,
|
|
147
|
+
startRecord,
|
|
148
|
+
unmount
|
|
149
|
+
} = mountContext();
|
|
150
|
+
await act(async () => {
|
|
151
|
+
expect(await result.current.setRecording(true)).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
expect(startRecord).not.toHaveBeenCalled();
|
|
154
|
+
expect(result.current.state.recording).toBe(false);
|
|
155
|
+
expect(showModal).toHaveBeenCalledTimes(1);
|
|
156
|
+
unmount();
|
|
157
|
+
});
|
|
158
|
+
it('propagates a native start failure without entering recording state', async () => {
|
|
159
|
+
const {
|
|
160
|
+
result,
|
|
161
|
+
startRecord,
|
|
162
|
+
unmount
|
|
163
|
+
} = mountContext();
|
|
164
|
+
const error = {
|
|
165
|
+
errorCode: 1001,
|
|
166
|
+
errorMsg: 'Start failed'
|
|
167
|
+
};
|
|
168
|
+
startRecord.mockImplementationOnce(_ref5 => {
|
|
169
|
+
let {
|
|
170
|
+
fail
|
|
171
|
+
} = _ref5;
|
|
172
|
+
return fail(error);
|
|
173
|
+
});
|
|
174
|
+
await act(async () => {
|
|
175
|
+
await expect(result.current.setRecording(true)).rejects.toEqual(error);
|
|
176
|
+
});
|
|
177
|
+
expect(result.current.state.recording).toBe(false);
|
|
178
|
+
unmount();
|
|
179
|
+
});
|
package/lib/ctx/ctx.js
CHANGED
|
@@ -6,6 +6,7 @@ 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';
|
|
@@ -519,53 +520,19 @@ export const createUseCtx = _ref => {
|
|
|
519
520
|
return false;
|
|
520
521
|
}
|
|
521
522
|
if (!target) return stopRecording(true);
|
|
523
|
+
const granted = await ensureAlbumPermission();
|
|
524
|
+
eventRef.current.emit(changeIgnoreHideStopPreview, false);
|
|
525
|
+
if (!granted) return false;
|
|
522
526
|
return new Promise((resolve, reject) => {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
saveToAlbum,
|
|
526
|
-
success: () => {
|
|
527
|
-
updateAtom(recording, true);
|
|
528
|
-
resolve(true);
|
|
529
|
-
},
|
|
530
|
-
fail: err => {
|
|
531
|
-
eventRef.current.emit(changeIgnoreHideStopPreview, false);
|
|
532
|
-
reject(err);
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
};
|
|
536
|
-
// 写入相册
|
|
537
|
-
ty.authorizeStatus({
|
|
538
|
-
scope: 'scope.writePhotosAlbum',
|
|
527
|
+
IPCPlayerInstance.current.startRecord({
|
|
528
|
+
saveToAlbum,
|
|
539
529
|
success: () => {
|
|
540
|
-
|
|
541
|
-
|
|
530
|
+
updateAtom(recording, true);
|
|
531
|
+
resolve(true);
|
|
542
532
|
},
|
|
543
|
-
fail:
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
success: () => {
|
|
547
|
-
startRecord();
|
|
548
|
-
},
|
|
549
|
-
fail: () => {
|
|
550
|
-
showModal({
|
|
551
|
-
title: '',
|
|
552
|
-
content: Strings.getLang('ipc_player_no_album_permission'),
|
|
553
|
-
cancelText: Strings.getLang('ipc_player_authorize_cancel_text'),
|
|
554
|
-
confirmText: Strings.getLang('ipc_player_authorize_confirm_text'),
|
|
555
|
-
isShowGlobal: true,
|
|
556
|
-
success: res => {
|
|
557
|
-
if (res.confirm) {
|
|
558
|
-
openAppSystemSettingPage({
|
|
559
|
-
scope: 'App-Settings',
|
|
560
|
-
success: () => {
|
|
561
|
-
console.log('跳转成功');
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
});
|
|
533
|
+
fail: err => {
|
|
534
|
+
eventRef.current.emit(changeIgnoreHideStopPreview, false);
|
|
535
|
+
reject(err);
|
|
569
536
|
}
|
|
570
537
|
});
|
|
571
538
|
});
|
|
@@ -10,12 +10,17 @@ export function useOfflineShownNotification(deviceId, deviceOnline) {
|
|
|
10
10
|
deviceId,
|
|
11
11
|
deviceOnline
|
|
12
12
|
};
|
|
13
|
+
const pageHiddenRef = useRef(false);
|
|
13
14
|
useEffect(() => {
|
|
14
|
-
if (!deviceOnline) {
|
|
15
|
+
if (!pageHiddenRef.current && !deviceOnline) {
|
|
15
16
|
notifyOfflineShown(deviceId);
|
|
16
17
|
}
|
|
17
18
|
}, [deviceId, deviceOnline]);
|
|
19
|
+
usePageEvent('onHide', () => {
|
|
20
|
+
pageHiddenRef.current = true;
|
|
21
|
+
});
|
|
18
22
|
usePageEvent('onShow', () => {
|
|
23
|
+
pageHiddenRef.current = false;
|
|
19
24
|
const {
|
|
20
25
|
deviceId: currentDeviceId,
|
|
21
26
|
deviceOnline: isOnline
|
|
@@ -57,4 +57,42 @@ describe('useOfflineShownNotification', () => {
|
|
|
57
57
|
expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
|
|
58
58
|
expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
|
|
59
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
|
+
});
|
|
60
98
|
});
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
});
|
|
@@ -274,6 +274,11 @@ export function RecordVideo(props) {
|
|
|
274
274
|
}
|
|
275
275
|
try {
|
|
276
276
|
const recordInfo = await setRecording(target);
|
|
277
|
+
if (recordInfo === false) {
|
|
278
|
+
var _props$event2;
|
|
279
|
+
((_props$event2 = props.event) !== null && _props$event2 !== void 0 ? _props$event2 : event).emit(changeIgnoreHideStopPreview, false);
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
277
282
|
if (target) {
|
|
278
283
|
setRecordingDisabled(true);
|
|
279
284
|
setState({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
jest.mock('../captureResult/captureResult.less', () => ({}));
|
|
26
|
+
it('keeps the record control idle when starting is declined', async () => {
|
|
27
|
+
const addContent = jest.fn();
|
|
28
|
+
const setRecordingDisabled = jest.fn();
|
|
29
|
+
const setRecording = jest.fn().mockResolvedValue(false);
|
|
30
|
+
const toast = jest.fn();
|
|
31
|
+
const props = {
|
|
32
|
+
recording: atom(false),
|
|
33
|
+
brandColor: atom('#000000'),
|
|
34
|
+
screenType: atom('vertical'),
|
|
35
|
+
recordingDisabled: atom(false),
|
|
36
|
+
playState: atom(PlayState.PLAYING),
|
|
37
|
+
setRecording,
|
|
38
|
+
setRecordingDisabled,
|
|
39
|
+
addContent,
|
|
40
|
+
deleteContent: jest.fn(),
|
|
41
|
+
toast,
|
|
42
|
+
devId: 'test-device',
|
|
43
|
+
event: {
|
|
44
|
+
emit: jest.fn()
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const {
|
|
48
|
+
result,
|
|
49
|
+
unmount
|
|
50
|
+
} = renderHook(() => RecordVideo(props));
|
|
51
|
+
await act(async () => {
|
|
52
|
+
await result.current.props.onClick();
|
|
53
|
+
});
|
|
54
|
+
expect(setRecording).toHaveBeenCalledWith(true);
|
|
55
|
+
expect(addContent).not.toHaveBeenCalled();
|
|
56
|
+
expect(setRecordingDisabled).not.toHaveBeenCalled();
|
|
57
|
+
expect(toast).not.toHaveBeenCalled();
|
|
58
|
+
unmount();
|
|
59
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useRef } from 'react';
|
|
2
|
-
import { View, Text,
|
|
2
|
+
import { View, 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 { getCaptureResultSummary } from '../../utils/captureResult';
|
|
11
12
|
import { CaptureResultToast } from '../captureResult/captureResult';
|
|
12
13
|
import './screenshot.less';
|
|
@@ -102,7 +103,7 @@ export function Screenshot(props) {
|
|
|
102
103
|
});
|
|
103
104
|
timeToCloseToast();
|
|
104
105
|
};
|
|
105
|
-
const handClick = useMemoizedFn(() => {
|
|
106
|
+
const handClick = useMemoizedFn(async () => {
|
|
106
107
|
var _props$event;
|
|
107
108
|
((_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event).emit(widgetClick, {
|
|
108
109
|
widgetId: widgetLabs.SCREENSHOT
|
|
@@ -131,7 +132,10 @@ export function Screenshot(props) {
|
|
|
131
132
|
title: errMsg
|
|
132
133
|
});
|
|
133
134
|
};
|
|
134
|
-
const
|
|
135
|
+
const granted = await ensureAlbumPermission();
|
|
136
|
+
setIgnoreHideStopPreview(false);
|
|
137
|
+
if (!granted) return;
|
|
138
|
+
(() => {
|
|
135
139
|
const requestId = ++snapshotRequestIdRef.current;
|
|
136
140
|
IPCPlayerContext.snapshot({
|
|
137
141
|
saveToAlbum,
|
|
@@ -157,42 +161,7 @@ export function Screenshot(props) {
|
|
|
157
161
|
},
|
|
158
162
|
fail: handleSnapshotFail
|
|
159
163
|
});
|
|
160
|
-
};
|
|
161
|
-
ty.authorizeStatus({
|
|
162
|
-
// 相册写入权限
|
|
163
|
-
scope: 'scope.writePhotosAlbum',
|
|
164
|
-
success: () => {
|
|
165
|
-
setIgnoreHideStopPreview(false);
|
|
166
|
-
takeSnapshot();
|
|
167
|
-
},
|
|
168
|
-
fail: () => {
|
|
169
|
-
ty.authorize({
|
|
170
|
-
scope: 'scope.writePhotosAlbum',
|
|
171
|
-
success: () => {
|
|
172
|
-
takeSnapshot();
|
|
173
|
-
},
|
|
174
|
-
fail: () => {
|
|
175
|
-
showModal({
|
|
176
|
-
title: '',
|
|
177
|
-
content: Strings.getLang('ipc_player_no_album_permission'),
|
|
178
|
-
cancelText: Strings.getLang('ipc_player_authorize_cancel_text'),
|
|
179
|
-
confirmText: Strings.getLang('ipc_player_authorize_confirm_text'),
|
|
180
|
-
isShowGlobal: true,
|
|
181
|
-
success: res => {
|
|
182
|
-
if (res.confirm) {
|
|
183
|
-
openAppSystemSettingPage({
|
|
184
|
-
scope: 'App-Settings',
|
|
185
|
-
success: () => {
|
|
186
|
-
console.log('跳转成功');
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
});
|
|
164
|
+
})();
|
|
196
165
|
});
|
|
197
166
|
if (hideScreenShotMenu) return null;
|
|
198
167
|
return /*#__PURE__*/React.createElement(View, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/ipc-player-integration",
|
|
3
|
-
"version": "0.0.53-beta.
|
|
3
|
+
"version": "0.0.53-beta.17",
|
|
4
4
|
"description": "IPC 融合播放器",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ray-js/direction-control": "^0.0.8",
|
|
39
39
|
"@ray-js/ipc-ptz-zoom": "^0.0.3",
|
|
40
|
-
"@ray-js/ray-ipc-player": "2.1.4
|
|
40
|
+
"@ray-js/ray-ipc-player": "^2.1.4",
|
|
41
41
|
"@ray-js/ray-ipc-utils": "^1.1.16",
|
|
42
42
|
"@ray-js/svg": "0.2.0",
|
|
43
43
|
"clsx": "^1.2.1",
|