@ray-js/ipc-player-integration 0.0.54 → 0.0.55-beta.0

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.
Files changed (31) hide show
  1. package/lib/ctx/ctx.js +20 -144
  2. package/lib/i18n/index.d.ts +0 -20
  3. package/lib/i18n/strings.d.ts +0 -10
  4. package/lib/i18n/strings.js +0 -10
  5. package/lib/interface.d.ts +1 -3
  6. package/lib/ui/ui.js +2 -43
  7. package/lib/utils/authorize/album.d.ts +1 -0
  8. package/lib/utils/authorize/album.js +39 -0
  9. package/lib/utils/authorize/album.test.js +82 -0
  10. package/lib/utils/ttt.d.ts +0 -26
  11. package/lib/utils/ttt.js +2 -112
  12. package/lib/widgets/recordVideo/recordVideo.js +5 -1
  13. package/lib/widgets/recordVideo/recordVideo.test.js +58 -0
  14. package/lib/widgets/resolution/resolution.js +1 -0
  15. package/lib/widgets/screenshot/screenshot.js +20 -71
  16. package/lib/widgets/videoBitKBP/videoBitKBP.js +12 -42
  17. package/lib/widgets/videoBitKBP/videoBitKBP.less +8 -17
  18. package/lib/widgets/zoomTurntable/lensSkill.js +4 -1
  19. package/package.json +2 -2
  20. package/lib/ctx/ctx.autoClarity.test.js +0 -150
  21. package/lib/ui/useOfflineShownNotification.d.ts +0 -1
  22. package/lib/ui/useOfflineShownNotification.js +0 -32
  23. package/lib/ui/useOfflineShownNotification.test.js +0 -98
  24. package/lib/utils/ttt.autoClarity.test.d.ts +0 -1
  25. package/lib/utils/ttt.autoClarity.test.js +0 -75
  26. package/lib/utils/ttt.notifyOfflineShown.test.d.ts +0 -1
  27. package/lib/utils/ttt.notifyOfflineShown.test.js +0 -30
  28. package/lib/widgets/videoBitKBP/videoBitKBP.test.d.ts +0 -1
  29. package/lib/widgets/videoBitKBP/videoBitKBP.test.js +0 -156
  30. /package/lib/{ctx/ctx.autoClarity.test.d.ts → utils/authorize/album.test.d.ts} +0 -0
  31. /package/lib/{ui/useOfflineShownNotification.test.d.ts → widgets/recordVideo/recordVideo.test.d.ts} +0 -0
@@ -1,32 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
- import { usePageEvent } from '@ray-js/ray';
3
- import { notifyOfflineShown } from '../utils/ttt';
4
- export function useOfflineShownNotification(deviceId, deviceOnline) {
5
- const latestDeviceRef = useRef({
6
- deviceId,
7
- deviceOnline
8
- });
9
- latestDeviceRef.current = {
10
- deviceId,
11
- deviceOnline
12
- };
13
- const pageHiddenRef = useRef(false);
14
- useEffect(() => {
15
- if (!pageHiddenRef.current && !deviceOnline) {
16
- notifyOfflineShown(deviceId);
17
- }
18
- }, [deviceId, deviceOnline]);
19
- usePageEvent('onHide', () => {
20
- pageHiddenRef.current = true;
21
- });
22
- usePageEvent('onShow', () => {
23
- pageHiddenRef.current = false;
24
- const {
25
- deviceId: currentDeviceId,
26
- deviceOnline: isOnline
27
- } = latestDeviceRef.current;
28
- if (!isOnline) {
29
- notifyOfflineShown(currentDeviceId);
30
- }
31
- });
32
- }
@@ -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
- });