@ray-js/ipc-player-integration 0.0.53-beta.10 → 0.0.53-beta.12

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/ui/ui.js CHANGED
@@ -21,12 +21,13 @@ import BottomLeftContent from './bottomLeftContent';
21
21
  import BottomRightContent from './bottomRightContent';
22
22
  import TopLeftContent from './topLeftContent';
23
23
  import TopRightContent from './topRightContent';
24
+ import { useOfflineShownNotification } from './useOfflineShownNotification';
24
25
  import { FlowLowTip, VideoBitKBP } from '../widgets';
25
26
  import { useMemoizedFn } from '../hooks';
26
27
  import { Storage } from '../utils/storage';
27
28
  import './ui.less';
28
29
  import { updatePlayerWidgetProps } from '../features';
29
- import { getNgRawData, getSmartImageQualityState, isLowPhone, notifyOfflineShown } from '../utils/ttt';
30
+ import { getNgRawData, getSmartImageQualityState, isLowPhone } from '../utils/ttt';
30
31
  import { getCaptureResultSummary } from '../utils/captureResult';
31
32
  import { lensCount } from '../widgets/zoomTurntable/lensSkill';
32
33
  import { shouldRenderContent } from './absoluteContent';
@@ -185,13 +186,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
185
186
  isLowPhoneRef.current = !!res;
186
187
  });
187
188
  }, []);
188
-
189
- // 监听设备在线状态,离线提示展示时通知宿主;notifyOfflineShown 内部兼容没有该 TTT 方法的宿主。
190
- useEffect(() => {
191
- if (!deviceOnline) {
192
- notifyOfflineShown(devId);
193
- }
194
- }, [deviceOnline, devId]);
189
+ useOfflineShownNotification(devId, deviceOnline);
195
190
 
196
191
  // 展示顶部内容
197
192
  const [showTopContent, setShowTopContent] = useState(true);
@@ -0,0 +1 @@
1
+ export declare function useOfflineShownNotification(deviceId: string, deviceOnline: boolean): void;
@@ -0,0 +1,33 @@
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 pageWasHiddenRef = useRef(false);
14
+ useEffect(() => {
15
+ if (!deviceOnline) {
16
+ notifyOfflineShown(deviceId);
17
+ }
18
+ }, [deviceId, deviceOnline]);
19
+ usePageEvent('onHide', () => {
20
+ pageWasHiddenRef.current = true;
21
+ });
22
+ usePageEvent('onShow', () => {
23
+ if (!pageWasHiddenRef.current) return;
24
+ pageWasHiddenRef.current = false;
25
+ const {
26
+ deviceId: currentDeviceId,
27
+ deviceOnline: isOnline
28
+ } = latestDeviceRef.current;
29
+ if (!isOnline) {
30
+ notifyOfflineShown(currentDeviceId);
31
+ }
32
+ });
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
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 once on initial offline state and once per foreground return', () => {
22
+ renderHook(() => useOfflineShownNotification('camera-1', false));
23
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
24
+ act(() => mockPageEventHandlers.onShow());
25
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
26
+ act(() => {
27
+ mockPageEventHandlers.onHide();
28
+ mockPageEventHandlers.onShow();
29
+ });
30
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
31
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-1');
32
+ act(() => mockPageEventHandlers.onShow());
33
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(2);
34
+ });
35
+ it('uses the latest online state and device id on foreground return', () => {
36
+ const {
37
+ rerender
38
+ } = renderHook(_ref => {
39
+ let {
40
+ deviceId,
41
+ deviceOnline
42
+ } = _ref;
43
+ return useOfflineShownNotification(deviceId, deviceOnline);
44
+ }, {
45
+ initialProps: {
46
+ deviceId: 'camera-1',
47
+ deviceOnline: false
48
+ }
49
+ });
50
+ rerender({
51
+ deviceId: 'camera-2',
52
+ deviceOnline: true
53
+ });
54
+ act(() => {
55
+ mockPageEventHandlers.onHide();
56
+ mockPageEventHandlers.onShow();
57
+ });
58
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(1);
59
+ rerender({
60
+ deviceId: 'camera-2',
61
+ deviceOnline: false
62
+ });
63
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
64
+ act(() => {
65
+ mockPageEventHandlers.onHide();
66
+ mockPageEventHandlers.onShow();
67
+ });
68
+ expect(notifyOfflineShown).toHaveBeenCalledTimes(3);
69
+ expect(notifyOfflineShown).toHaveBeenLastCalledWith('camera-2');
70
+ });
71
+ });
@@ -91,17 +91,21 @@ export const VideoBitKBP = props => {
91
91
  })
92
92
  }, /*#__PURE__*/React.createElement(View, {
93
93
  className: "ipc-player-plugin-videoBitKBP"
94
+ }, /*#__PURE__*/React.createElement(View, {
95
+ className: "ipc-player-plugin-videoBitKBP-content"
94
96
  }, hasSignal && /*#__PURE__*/React.createElement(View, {
95
97
  className: "ipc-player-plugin-videoBitKBP-signal"
96
98
  }, /*#__PURE__*/React.createElement(Text, {
97
99
  className: clsx('icon-panel', 'icon-panel-wi-Fi', 'ipc-player-plugin-videoBitKBP-signal-icon')
98
- }), /*#__PURE__*/React.createElement(Text, null, signalStrength), /*#__PURE__*/React.createElement(Text, {
99
- className: "ipc-player-plugin-videoBitKBP-unit-percent"
100
+ }), /*#__PURE__*/React.createElement(Text, {
101
+ className: "ipc-player-plugin-videoBitKBP-signal-text"
102
+ }, signalStrength), /*#__PURE__*/React.createElement(Text, {
103
+ className: "ipc-player-plugin-videoBitKBP-signal-text ipc-player-plugin-videoBitKBP-unit-percent"
100
104
  }, signalStrength > 0 ? '%' : 'dBm')), hasSignal && (hasKbps || hasClarity) && /*#__PURE__*/React.createElement(View, {
101
105
  className: "ipc-player-plugin-videoBitKBP-divider"
102
106
  }), (hasKbps || hasClarity) && /*#__PURE__*/React.createElement(View, {
103
107
  className: "ipc-player-plugin-videoBitKBP-kbps"
104
108
  }, /*#__PURE__*/React.createElement(Text, {
105
109
  className: "ipc-player-plugin-videoBitKBP-kbps-text"
106
- }, bitrateLabel))));
110
+ }, bitrateLabel)))));
107
111
  };
@@ -18,24 +18,33 @@
18
18
  background-color: rgba(255, 255, 255, 0.2);
19
19
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
20
20
  }
21
- .ipc-player-plugin-videoBitKBP-signal {
21
+ .ipc-player-plugin-videoBitKBP-content {
22
22
  display: flex;
23
- align-items: center;
23
+ align-items: baseline;
24
+ }
25
+ .ipc-player-plugin-videoBitKBP-signal,
26
+ .ipc-player-plugin-videoBitKBP-kbps {
27
+ display: flex;
28
+ align-items: baseline;
29
+ height: calc(16px * var(--ipc-player-size-scale, 1));
30
+ line-height: calc(16px * var(--ipc-player-size-scale, 1));
24
31
  }
25
32
  .ipc-player-plugin-videoBitKBP-signal-icon {
33
+ align-self: center;
26
34
  font-size: calc(14px * var(--ipc-player-size-scale, 1));
27
35
  margin-right: calc(4px * var(--ipc-player-size-scale, 1));
28
36
  }
37
+ .ipc-player-plugin-videoBitKBP-signal-text,
38
+ .ipc-player-plugin-videoBitKBP-kbps-text {
39
+ line-height: calc(16px * var(--ipc-player-size-scale, 1));
40
+ }
29
41
  .ipc-player-plugin-videoBitKBP-divider {
42
+ align-self: center;
30
43
  width: 1px;
31
44
  height: calc(10px * var(--ipc-player-size-scale, 1));
32
45
  background-color: var(--iconColor);
33
46
  margin: 0 calc(4px * var(--ipc-player-size-scale, 1));
34
47
  }
35
- .ipc-player-plugin-videoBitKBP-kbps {
36
- display: flex;
37
- align-items: center;
38
- }
39
48
  .ipc-player-plugin-videoBitKBP-kbps-text {
40
49
  white-space: nowrap;
41
50
  }
@@ -1,8 +1,10 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
1
3
  import React from 'react';
2
4
  import ReactDOM from 'react-dom';
3
5
  import { renderToStaticMarkup } from 'react-dom/server';
4
6
  import { act } from 'react-dom/test-utils';
5
- import { getVideoBitrateKbps } from '@ray-js/ray-ipc-utils';
7
+ import { getVideoBitrateKbps, requestWifiSignal } from '@ray-js/ray-ipc-utils';
6
8
  let mockStoreState;
7
9
  jest.mock('@ray-js/ray', () => ({
8
10
  View: _ref => {
@@ -97,6 +99,48 @@ describe('VideoBitKBP auto clarity', () => {
97
99
  ReactDOM.unmountComponentAtNode(container);
98
100
  }
99
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
+ });
100
144
  it('shows actual clarity independently of bitrate, signal and play state', () => {
101
145
  const markup = renderWidget('AUTO', 'HD', 2);
102
146
  expect(markup).toContain('ipc_player_resolution_HD');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.53-beta.10",
3
+ "version": "0.0.53-beta.12",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [