@ray-js/ipc-player-integration 0.0.70 → 0.0.71-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 (120) hide show
  1. package/README.md +6 -0
  2. package/lib/ctx/ctx.js +12 -17
  3. package/lib/ctx/ctx.test.js +54 -19
  4. package/lib/ctx/intercom.test.d.ts +1 -0
  5. package/lib/ctx/intercom.test.js +85 -0
  6. package/lib/index.d.ts +4 -0
  7. package/lib/index.js +3 -1
  8. package/lib/renderer/capabilities.d.ts +8 -0
  9. package/lib/renderer/capabilities.js +19 -0
  10. package/lib/renderer/context.d.ts +5 -0
  11. package/lib/renderer/context.js +6 -0
  12. package/lib/renderer/directionControl.d.ts +6 -0
  13. package/lib/renderer/directionControl.js +3 -0
  14. package/lib/renderer/font-manifest.json +9 -0
  15. package/lib/renderer/font.less +5 -0
  16. package/lib/renderer/glyphs.d.ts +1 -0
  17. package/lib/renderer/glyphs.js +256 -0
  18. package/lib/renderer/index.module.less +48 -0
  19. package/lib/renderer/overlay.d.ts +6 -0
  20. package/lib/renderer/overlay.js +18 -0
  21. package/lib/renderer/ptzZoom.d.ts +6 -0
  22. package/lib/renderer/ptzZoom.js +3 -0
  23. package/lib/renderer/text.d.ts +4 -0
  24. package/lib/renderer/text.js +32 -0
  25. package/lib/renderer/text.module.less +4 -0
  26. package/lib/renderer/viewport.d.ts +7 -0
  27. package/lib/renderer/viewport.js +24 -0
  28. package/lib/res/lynx-signal/index.d.ts +1 -0
  29. package/lib/res/lynx-signal/index.js +22 -0
  30. package/lib/res/lynx-signal/signalFour0.png +0 -0
  31. package/lib/res/lynx-signal/signalFour1.png +0 -0
  32. package/lib/res/lynx-signal/signalFour2.png +0 -0
  33. package/lib/res/lynx-signal/signalFour3.png +0 -0
  34. package/lib/res/lynx-signal/signalFour4.png +0 -0
  35. package/lib/res/lynx-signal/signalThree0.png +0 -0
  36. package/lib/res/lynx-signal/signalThree1.png +0 -0
  37. package/lib/res/lynx-signal/signalThree2.png +0 -0
  38. package/lib/res/lynx-signal/signalThree3.png +0 -0
  39. package/lib/res/player-charging.png +0 -0
  40. package/lib/res/player-more-arrow.png +0 -0
  41. package/lib/res/player-solar.png +0 -0
  42. package/lib/ui/bottomLeftContent.js +121 -53
  43. package/lib/ui/bottomRightContent.js +10 -5
  44. package/lib/ui/scrollHintArrow.d.ts +23 -0
  45. package/lib/ui/scrollHintArrow.js +83 -0
  46. package/lib/ui/topLeftContent.js +4 -2
  47. package/lib/ui/topRightContent.js +4 -2
  48. package/lib/ui/ui.d.ts +5 -0
  49. package/lib/ui/ui.js +46 -23
  50. package/lib/widgets/battery/battery.js +7 -5
  51. package/lib/widgets/battery/batteryFull.js +7 -5
  52. package/lib/widgets/battery/statusIcon.d.ts +6 -0
  53. package/lib/widgets/battery/statusIcon.js +36 -0
  54. package/lib/widgets/battery/statusIcon.less +24 -0
  55. package/lib/widgets/captureResult/captureResult.js +2 -1
  56. package/lib/widgets/captureToast/captureToast.d.ts +10 -0
  57. package/lib/widgets/captureToast/captureToast.js +58 -0
  58. package/lib/widgets/floodlight/floodlight.js +2 -1
  59. package/lib/widgets/flowLowTip/flowLowTip.js +2 -1
  60. package/lib/widgets/fullScreen/fullScreen.js +2 -1
  61. package/lib/widgets/fullScreen/fullTravelRouteControl.d.ts +1 -1
  62. package/lib/widgets/fullScreen/fullTravelRouteControl.js +1 -1
  63. package/lib/widgets/fullScreen/verticalScreen.js +2 -1
  64. package/lib/widgets/moveInteractiveControl/controlButton.js +2 -1
  65. package/lib/widgets/moveInteractiveControl/moveInteractiveControlUI.js +16 -5
  66. package/lib/widgets/moveInteractiveControl/moveInteractiveControlUI.less +24 -4
  67. package/lib/widgets/multiCamera/landscapeTip.js +8 -2
  68. package/lib/widgets/multiCamera/moveablePtzControl.js +5 -3
  69. package/lib/widgets/multiCamera/multiPtz.js +2 -1
  70. package/lib/widgets/multiCamera/ptzMoveableTip.js +8 -2
  71. package/lib/widgets/multiCamera/switchLayout.js +2 -1
  72. package/lib/widgets/multiCamera/tileMultiPtz.js +2 -1
  73. package/lib/widgets/multiCamera/tileSwitchLayout.js +2 -1
  74. package/lib/widgets/multiCamera/tileTip.js +8 -2
  75. package/lib/widgets/muted/muted.js +2 -1
  76. package/lib/widgets/muted/muted.test.js +66 -52
  77. package/lib/widgets/ptz/ptz.js +2 -1
  78. package/lib/widgets/ptz/ptzControl.js +4 -3
  79. package/lib/widgets/ptzControlTip/ptzControlTip.js +9 -4
  80. package/lib/widgets/ptzControlTip/ptzControlTip.less +6 -0
  81. package/lib/widgets/realTimeMagnification/realTimeMagnification.js +2 -1
  82. package/lib/widgets/recordVideo/recordVideo.js +47 -169
  83. package/lib/widgets/recordVideo/recordVideo.lifecycle.test.js +4 -2
  84. package/lib/widgets/recordVideo/recordVideo.test.js +169 -2
  85. package/lib/widgets/recordVideo/recordVideoTimer.d.ts +3 -0
  86. package/lib/widgets/recordVideo/recordVideoTimer.js +26 -0
  87. package/lib/widgets/resolution/fullResolutionControl.js +29 -19
  88. package/lib/widgets/resolution/resolution.js +3 -2
  89. package/lib/widgets/screenshot/screenshot.js +48 -122
  90. package/lib/widgets/screenshot/screenshot.permissions.test.d.ts +1 -0
  91. package/lib/widgets/screenshot/screenshot.permissions.test.js +137 -0
  92. package/lib/widgets/screenshot/screenshot.test.js +108 -113
  93. package/lib/widgets/signal4G/signal4G.js +4 -1
  94. package/lib/widgets/siren/siren.js +2 -1
  95. package/lib/widgets/tempHumidity/tempHumidity.js +2 -1
  96. package/lib/widgets/toggleVerticalFull/toggleVerticalFull.js +2 -1
  97. package/lib/widgets/trialBadge/index.js +8 -3
  98. package/lib/widgets/trialBadge/index.less +24 -0
  99. package/lib/widgets/tryExperience/tryExperience.js +2 -1
  100. package/lib/widgets/videoBitKBP/videoBitKBP.js +2 -1
  101. package/lib/widgets/voiceIntercom/voiceIntercom.js +57 -81
  102. package/lib/widgets/voiceIntercom/voiceIntercom.less +35 -0
  103. package/lib/widgets/voiceIntercom/voiceIntercom.test.d.ts +1 -0
  104. package/lib/widgets/voiceIntercom/voiceIntercom.test.js +135 -0
  105. package/lib/widgets/zoomTurntable/lynxDockLayout.d.ts +6 -0
  106. package/lib/widgets/zoomTurntable/lynxDockLayout.js +30 -0
  107. package/lib/widgets/zoomTurntable/turntable/index.d.ts +5 -7
  108. package/lib/widgets/zoomTurntable/turntable/index.js +3 -1
  109. package/lib/widgets/zoomTurntable/turntable/lynx.d.ts +5 -0
  110. package/lib/widgets/zoomTurntable/turntable/lynx.js +273 -0
  111. package/lib/widgets/zoomTurntable/turntable/lynx.less +9 -0
  112. package/lib/widgets/zoomTurntable/turntable/lynxModel.d.ts +37 -0
  113. package/lib/widgets/zoomTurntable/turntable/lynxModel.js +122 -0
  114. package/lib/widgets/zoomTurntable/turntable/lynxPaint.d.ts +3 -0
  115. package/lib/widgets/zoomTurntable/turntable/lynxPaint.js +36 -0
  116. package/lib/widgets/zoomTurntable/zoomTurntableDock.d.ts +5 -3
  117. package/lib/widgets/zoomTurntable/zoomTurntableDock.js +4 -4
  118. package/lib/widgets/zoomTurntable/zoomTurntableEntry.js +32 -19
  119. package/lib/widgets/zoomTurntable/zoomTurntableTip.js +17 -3
  120. package/package.json +15 -7
@@ -1,3 +1,4 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import "core-js/modules/esnext.iterator.constructor.js";
2
3
  import "core-js/modules/esnext.iterator.filter.js";
3
4
  import "core-js/modules/esnext.iterator.map.js";
@@ -9,6 +10,7 @@ import { PlayState } from '../../interface';
9
10
  import { RecordVideo } from './recordVideo';
10
11
  jest.mock('@ray-js/ray', () => ({
11
12
  View: 'div',
13
+ CoverView: 'div',
12
14
  Text: 'span',
13
15
  Image: 'img',
14
16
  getSystemInfoSync: () => ({
@@ -72,9 +74,9 @@ describe('RecordVideo', () => {
72
74
  setRecordingDisabled: value => store.set(recordingDisabled, value),
73
75
  addContent: (_type, content) => setContents(items => [...items, content]),
74
76
  deleteContent: (_type, id) => setContents(items => items.filter(item => item.id !== id))
75
- }), contents.map(item => /*#__PURE__*/React.createElement(item.content, {
77
+ }), contents.map(item => /*#__PURE__*/React.createElement(item.content, _objectSpread(_objectSpread({}, item.initProps), {}, {
76
78
  key: item.id
77
- })));
79
+ }))));
78
80
  }
79
81
  const clickRecord = async () => {
80
82
  await act(async () => {
@@ -1,9 +1,18 @@
1
- import { act, renderHook } from '@testing-library/react-hooks/dom';
2
- import { atom } from 'jotai';
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.filter.js";
4
+ import "core-js/modules/esnext.iterator.map.js";
5
+ import React from 'react';
6
+ import ReactDOM from 'react-dom';
7
+ import { act, Simulate } from 'react-dom/test-utils';
8
+ import { renderHook } from '@testing-library/react-hooks/dom';
9
+ import { atom, getDefaultStore } from 'jotai';
3
10
  import { RecordVideo } from './recordVideo';
4
11
  import { PlayState } from '../../interface';
12
+ import { PlayerRenderModeContext } from '../../renderer/context';
5
13
  jest.mock('@ray-js/ray', () => ({
6
14
  View: 'div',
15
+ CoverView: 'div',
7
16
  Text: 'span',
8
17
  Image: 'img',
9
18
  getSystemInfoSync: () => ({
@@ -56,4 +65,162 @@ it('keeps the record control idle when starting is declined', async () => {
56
65
  expect(setRecordingDisabled).not.toHaveBeenCalled();
57
66
  expect(toast).not.toHaveBeenCalled();
58
67
  unmount();
68
+ });
69
+ describe('successful recording timer', () => {
70
+ let container;
71
+ beforeEach(() => {
72
+ jest.useFakeTimers();
73
+ jest.setSystemTime(10000);
74
+ container = document.createElement('div');
75
+ document.body.appendChild(container);
76
+ });
77
+ afterEach(() => {
78
+ act(() => {
79
+ ReactDOM.unmountComponentAtNode(container);
80
+ });
81
+ container.remove();
82
+ jest.clearAllTimers();
83
+ jest.restoreAllMocks();
84
+ jest.useRealTimers();
85
+ });
86
+ function mountRecorder(mode) {
87
+ const store = getDefaultStore();
88
+ const recording = atom(false);
89
+ const recordingDisabled = atom(false);
90
+ const brandColor = atom('#000000');
91
+ let updateContents;
92
+ let recreateControl;
93
+ const props = {
94
+ recording,
95
+ recordingDisabled,
96
+ brandColor,
97
+ screenType: atom('vertical'),
98
+ playState: atom(PlayState.PLAYING),
99
+ setRecording: jest.fn(async value => {
100
+ store.set(recording, value);
101
+ return value ? true : {
102
+ tempImagePath: 'record.jpg'
103
+ };
104
+ }),
105
+ setRecordingDisabled: value => store.set(recordingDisabled, value),
106
+ addContent: (_area, item) => updateContents(items => [...items, item]),
107
+ deleteContent: (_area, id) => updateContents(items => items.filter(item => item.id !== id)),
108
+ toast: jest.fn(),
109
+ devId: 'test-device',
110
+ event: {
111
+ emit: jest.fn()
112
+ }
113
+ };
114
+ const Harness = () => {
115
+ const [contents, setContents] = React.useState([]);
116
+ const [generation, setGeneration] = React.useState(0);
117
+ recreateControl = () => setGeneration(value => value + 1);
118
+ updateContents = setContents;
119
+ return /*#__PURE__*/React.createElement(PlayerRenderModeContext.Provider, {
120
+ value: mode
121
+ }, /*#__PURE__*/React.createElement(RecordVideo, _extends({
122
+ key: generation
123
+ }, props)), contents.map(item => /*#__PURE__*/React.createElement(item.content, _extends({
124
+ key: item.id
125
+ }, item.initProps))));
126
+ };
127
+ act(() => {
128
+ ReactDOM.render(/*#__PURE__*/React.createElement(Harness, null), container);
129
+ });
130
+ return {
131
+ props,
132
+ store,
133
+ brandColor,
134
+ remountControl: () => {
135
+ act(() => {
136
+ recreateControl();
137
+ });
138
+ },
139
+ click: async () => {
140
+ await act(async () => {
141
+ Simulate.click(container.firstElementChild);
142
+ });
143
+ },
144
+ timer: () => container.querySelector('.ipc-player-plugin-record-video-toast-time')
145
+ };
146
+ }
147
+ it.each(['webview', 'lynx'])('ticks and cleans up in %s', async mode => {
148
+ const clear = jest.spyOn(global, 'clearInterval');
149
+ const start = jest.spyOn(global, 'setInterval');
150
+ const recorder = mountRecorder(mode);
151
+ await recorder.click();
152
+ expect(recorder.props.setRecording).toHaveBeenCalledWith(true);
153
+ expect(recorder.timer().textContent).toBe('00:00');
154
+ expect(start).toHaveBeenCalledTimes(1);
155
+ const interval = start.mock.results[0].value;
156
+ act(() => {
157
+ jest.advanceTimersByTime(1000);
158
+ });
159
+ expect(recorder.timer().textContent).toBe('00:01');
160
+ act(() => {
161
+ recorder.store.set(recorder.brandColor, '#ffffff');
162
+ });
163
+ expect(recorder.timer().textContent).toBe('00:01');
164
+ act(() => {
165
+ jest.advanceTimersByTime(59000);
166
+ });
167
+ expect(recorder.timer().textContent).toBe('01:00');
168
+ expect(start).toHaveBeenCalledTimes(1);
169
+ await recorder.click();
170
+ expect(recorder.props.setRecording).toHaveBeenLastCalledWith(false);
171
+ expect(recorder.timer()).toBeNull();
172
+ expect(clear).toHaveBeenCalledWith(interval);
173
+ await recorder.click();
174
+ expect(recorder.timer().textContent).toBe('00:00');
175
+ const nextInterval = start.mock.results[1].value;
176
+ act(() => {
177
+ ReactDOM.unmountComponentAtNode(container);
178
+ });
179
+ expect(clear).toHaveBeenCalledWith(nextInterval);
180
+ });
181
+ it('uses elapsed wall time after a delayed tick', async () => {
182
+ const recorder = mountRecorder('lynx');
183
+ await recorder.click();
184
+ act(() => {
185
+ jest.setSystemTime(74000);
186
+ jest.advanceTimersByTime(1000);
187
+ });
188
+ expect(recorder.timer().textContent).toBe('01:05');
189
+ });
190
+ it.each(['webview', 'lynx'])('stops the persistent timer after orientation remounts the %s toolbar', async mode => {
191
+ const clear = jest.spyOn(global, 'clearInterval');
192
+ const start = jest.spyOn(global, 'setInterval');
193
+ const recorder = mountRecorder(mode);
194
+ await recorder.click();
195
+ const interval = start.mock.results[0].value;
196
+ act(() => {
197
+ jest.advanceTimersByTime(4000);
198
+ });
199
+ act(() => {
200
+ recorder.store.set(recorder.props.screenType, 'full');
201
+ });
202
+ recorder.remountControl();
203
+ expect(recorder.timer().textContent).toBe('00:04');
204
+ act(() => {
205
+ jest.advanceTimersByTime(1000);
206
+ });
207
+ act(() => {
208
+ recorder.store.set(recorder.props.screenType, 'vertical');
209
+ });
210
+ recorder.remountControl();
211
+ expect(recorder.timer().textContent).toBe('00:05');
212
+ await recorder.click();
213
+ expect(recorder.props.setRecording).toHaveBeenLastCalledWith(false);
214
+ expect(recorder.timer()).toBeNull();
215
+ expect(clear).toHaveBeenCalledWith(interval);
216
+ });
217
+ it('removes the timer when recording stops outside the remounted control', async () => {
218
+ const recorder = mountRecorder('lynx');
219
+ await recorder.click();
220
+ recorder.remountControl();
221
+ act(() => {
222
+ recorder.store.set(recorder.props.recording, false);
223
+ });
224
+ expect(recorder.timer()).toBeNull();
225
+ });
59
226
  });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const RecordVideoTimer: () => React.JSX.Element;
3
+ export default RecordVideoTimer;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { View } from '@ray-js/ray';
3
+
4
+ // Keep the timer state in this component, without a separate custom-hook binding.
5
+ const RecordVideoTimer = () => {
6
+ const [elapsedSeconds, setElapsedSeconds] = React.useState(0);
7
+ React.useEffect(() => {
8
+ const startedAt = Date.now();
9
+ const interval = setInterval(() => {
10
+ setElapsedSeconds(Math.max(0, Math.floor((Date.now() - startedAt) / 1000)));
11
+ }, 1000);
12
+ return () => clearInterval(interval);
13
+ }, []);
14
+ const minutes = String(Math.floor(elapsedSeconds / 60)).padStart(2, '0');
15
+ const seconds = String(elapsedSeconds % 60).padStart(2, '0');
16
+ return /*#__PURE__*/React.createElement(View, {
17
+ className: "ipc-player-plugin-record-video-toast-time"
18
+ }, /*#__PURE__*/React.createElement(View, {
19
+ className: "ipc-player-plugin-record-video-toast-time-warp"
20
+ }, minutes), /*#__PURE__*/React.createElement(View, {
21
+ className: "ipc-player-plugin-record-video-toast-time-delimiter"
22
+ }, ":"), /*#__PURE__*/React.createElement(View, {
23
+ className: "ipc-player-plugin-record-video-toast-time-warp"
24
+ }, seconds));
25
+ };
26
+ export default RecordVideoTimer;
@@ -1,8 +1,9 @@
1
1
  import "core-js/modules/esnext.iterator.constructor.js";
2
2
  import "core-js/modules/esnext.iterator.map.js";
3
3
  import React, { useState, useContext, useEffect } from 'react';
4
- import { Text, View, showToast } from '@ray-js/ray';
4
+ import { View, showToast } from '@ray-js/ray';
5
5
  import clsx from 'clsx';
6
+ import { PlayerText as Text } from '../../renderer/text';
6
7
  import Strings from '../../i18n';
7
8
  import { useMemoizedFn } from '../../hooks';
8
9
  import { useStore } from '../../ctx/store';
@@ -33,6 +34,10 @@ export const FullResolutionControl = props => {
33
34
  const onPlayerTap = useMemoizedFn(() => {
34
35
  setHide(true);
35
36
  });
37
+ const normalizeResolution = value => {
38
+ const normalized = String(value || '').toUpperCase();
39
+ return normalized === 'HD' ? 'HD' : 'SD';
40
+ };
36
41
  useEffect(() => {
37
42
  event.on('showFullResolutionControl', onShowFullResolutionControl);
38
43
  event.on(playerTap, onPlayerTap);
@@ -42,13 +47,14 @@ export const FullResolutionControl = props => {
42
47
  };
43
48
  }, []);
44
49
  const changeResolution = useMemoizedFn(value => {
45
- if (value === resolution) {
50
+ const targetResolution = normalizeResolution(value);
51
+ if (targetResolution === normalizeResolution(resolution)) {
46
52
  showToast({
47
53
  icon: 'none',
48
54
  title: Strings.getLang('ipc_player_current_resolution_is_equal')
49
55
  });
50
56
  } else {
51
- setResolution(value).then(() => {
57
+ setResolution(targetResolution).then(() => {
52
58
  showToast({
53
59
  icon: 'none',
54
60
  title: Strings.getLang('ipc_player_change_resolution_success')
@@ -68,20 +74,24 @@ export const FullResolutionControl = props => {
68
74
  className: clsx('ipc-player-plugin-full-resolution-control', 'ipc-plugin-absolute-move-in-right', {
69
75
  'ipc-plugin-absolute-move-in-right-hide': hide
70
76
  })
71
- }, resolutionList.map(item => /*#__PURE__*/React.createElement(Text, {
72
- onClick: () => {
73
- event.emit(widgetClick, {
74
- widgetId: widgetLabs.FULL_RESOLUTION_CONTROL,
75
- extra: {
76
- resolution: item
77
- }
78
- });
79
- changeResolution(item);
80
- },
81
- key: item,
82
- className: clsx('ipc-player-plugin-full-resolution-control-text'),
83
- style: item === resolution && {
84
- color: brandColor
85
- }
86
- }, Strings.getLang(`ipc_player_resolution_${item}`))));
77
+ }, resolutionList.map(item => {
78
+ const normalizedItem = normalizeResolution(item);
79
+ const selected = normalizedItem === normalizeResolution(resolution);
80
+ return /*#__PURE__*/React.createElement(Text, {
81
+ key: item,
82
+ onClick: () => {
83
+ event.emit(widgetClick, {
84
+ widgetId: widgetLabs.FULL_RESOLUTION_CONTROL,
85
+ extra: {
86
+ resolution: normalizedItem
87
+ }
88
+ });
89
+ changeResolution(normalizedItem);
90
+ },
91
+ className: clsx('ipc-player-plugin-full-resolution-control-text'),
92
+ style: selected ? {
93
+ color: brandColor
94
+ } : undefined
95
+ }, Strings.getLang(`ipc_player_resolution_${normalizedItem}`));
96
+ }));
87
97
  };
@@ -1,8 +1,9 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import { View, Text } from '@ray-js/ray';
2
+ import { View } from '@ray-js/ray';
3
3
  import clsx from 'clsx';
4
4
  import React, { useContext } from 'react';
5
5
  import { useMemoizedFn } from 'ahooks';
6
+ import { PlayerText as Text } from '../../renderer/text';
6
7
  import Strings from '../../i18n';
7
8
  import { FullResolutionControl } from './fullResolutionControl';
8
9
  import { fullResolutionId, pauseTimeToHideAllComponent, hideAllComponent, widgetLabs, widgetClick } from '../../ui/constant';
@@ -52,7 +53,7 @@ export const Resolution = props => {
52
53
  }
53
54
  if (verticalResolutionCustomClick) return false;
54
55
  if (screenType === 'vertical') {
55
- setResolution(resolution === 'HD' ? 'SD' : 'HD');
56
+ setResolution(String(resolution).toUpperCase() === 'HD' ? 'SD' : 'HD');
56
57
  }
57
58
  event.emit(pauseTimeToHideAllComponent);
58
59
  return true;
@@ -1,19 +1,17 @@
1
1
  import "core-js/modules/esnext.iterator.constructor.js";
2
2
  import "core-js/modules/esnext.iterator.map.js";
3
- import React, { useContext, useEffect, useRef } from 'react';
4
- import { View, Text, getSystemInfoSync } from '@ray-js/ray';
5
- import { useSetState, useUpdateEffect, useMemoizedFn } from 'ahooks';
3
+ import React, { useContext, useRef, useEffect } from 'react';
4
+ import { View, getSystemInfoSync } from '@ray-js/ray';
5
+ import { useMemoizedFn } from 'ahooks';
6
6
  import clsx from 'clsx';
7
- import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';
7
+ import { getCaptureResultSummary } from '../../utils/captureResult';
8
+ import { PlayerText as Text } from '../../renderer/text';
8
9
  import Strings from '../../i18n';
9
- import { useStore } from '../../ctx/store';
10
10
  import { UIEventContext } from '../../ui/context';
11
11
  import { pauseTimeToHideAllComponent, changeIgnoreHideStopPreview, widgetLabs, widgetClick } from '../../ui/constant';
12
- import { getCaptureResultSummary } from '../../utils/captureResult';
13
12
  import { ensureAlbumPermission } from '../../utils/authorize/album';
14
- import { CaptureResultToast } from '../captureResult/captureResult';
13
+ import CaptureToast from '../captureToast/captureToast';
15
14
  import './screenshot.less';
16
- const CLOSE_TIME = 5000;
17
15
  export function Screenshot(props) {
18
16
  const {
19
17
  IPCPlayerContext,
@@ -25,97 +23,39 @@ export function Screenshot(props) {
25
23
  className,
26
24
  hideScreenShotMenu
27
25
  } = props;
28
- const {
29
- screenType,
30
- brandColor
31
- } = useStore({
32
- screenType: props.screenType,
33
- brandColor: props.brandColor
34
- });
35
26
  const {
36
27
  event
37
28
  } = useContext(UIEventContext);
38
-
39
- /** 记录截屏url */
40
- const [state, setState] = useSetState({
41
- showShot: false,
42
- shotUrl: '',
43
- shotCount: 0
44
- });
45
- const snapshotRequestIdRef = useRef(0);
46
- useEffect(() => {
47
- return () => {
48
- snapshotRequestIdRef.current += 1;
49
- };
29
+ const requestIdRef = useRef(0);
30
+ useEffect(() => () => {
31
+ requestIdRef.current += 1;
50
32
  }, []);
51
- useUpdateEffect(() => {
52
- if (state.showShot && screenType) {
53
- showShotToast();
54
- }
55
- }, [state.showShot, screenType]);
56
- const timer = useRef();
57
- const timeToCloseToast = () => {
58
- clearInterval(timer.current);
59
- // @ts-ignore
60
- timer.current = setTimeout(() => {
61
- setState({
62
- showShot: false,
63
- shotUrl: '',
64
- shotCount: 0
65
- });
66
- deleteContent('absolute', 'plugin-screenshot-toast');
67
- }, CLOSE_TIME);
68
- };
69
-
70
- /** 跳转相册 */
71
- const handCheck = () => {
72
- setState({
73
- showShot: false,
74
- shotUrl: '',
75
- shotCount: 0
76
- });
77
- deleteContent('absolute', 'plugin-screenshot-toast');
78
- clearInterval(timer.current);
79
- goToIpcPageNativeRoute('ipc_album_panel', devId);
80
- };
81
-
82
- /** 添加截屏成功弹窗 */
83
- const showShotToast = () => {
33
+ const showShotToast = (imageUrl, count) => {
84
34
  deleteContent('absolute', 'plugin-screenshot-toast');
85
35
  addContent('absolute', {
86
36
  id: 'plugin-screenshot-toast',
87
- absoluteContentClassName: 'ipc-player-plugin-screenshot-toast-wrap',
88
- absolutePosition: {
89
- top: screenType === 'vertical' ? '12px' : '60px',
90
- left: screenType === 'vertical' ? '16px' : '50%',
91
- right: screenType === 'vertical' ? '16px' : 'unset',
92
- display: 'flex',
93
- width: screenType === 'vertical' ? 'auto' : '400px',
94
- marginLeft: screenType === 'vertical' ? '0' : '-200px'
95
- },
96
- content: () => {
97
- return /*#__PURE__*/React.createElement(CaptureResultToast, {
98
- brandColor: brandColor,
99
- count: state.shotCount,
100
- kind: "screenshot",
101
- onCheck: handCheck,
102
- thumbnailPath: state.shotUrl
103
- });
37
+ absoluteNoCoverView: true,
38
+ content: CaptureToast,
39
+ initProps: {
40
+ kind: 'screenshot',
41
+ count,
42
+ imageUrl,
43
+ captureId: Date.now(),
44
+ screenType: props.screenType,
45
+ brandColor: props.brandColor,
46
+ devId,
47
+ deleteContent
104
48
  }
105
49
  });
106
- timeToCloseToast();
107
50
  };
108
51
  const handClick = useMemoizedFn(async () => {
109
- var _props$event;
110
- ((_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event).emit(widgetClick, {
52
+ var _props$event, _props$event2;
53
+ const ev = (_props$event = props.event) !== null && _props$event !== void 0 ? _props$event : event;
54
+ ((_props$event2 = props.event) !== null && _props$event2 !== void 0 ? _props$event2 : event).emit(widgetClick, {
111
55
  widgetId: widgetLabs.SCREENSHOT
112
56
  });
113
57
  console.log('截屏!!!');
114
58
  deleteContent('absolute', 'plugin-screenshot-toast');
115
- clearTimeout(timer.current);
116
- setState({
117
- showShot: false
118
- });
119
59
  const {
120
60
  platform
121
61
  } = getSystemInfoSync();
@@ -123,46 +63,32 @@ export function Screenshot(props) {
123
63
  props.event ? props.event.emit(changeIgnoreHideStopPreview, true) : event.emit(changeIgnoreHideStopPreview, true);
124
64
  }
125
65
  event.emit(pauseTimeToHideAllComponent);
126
- const setIgnoreHideStopPreview = value => {
127
- var _props$event2;
128
- ((_props$event2 = props.event) !== null && _props$event2 !== void 0 ? _props$event2 : event).emit(changeIgnoreHideStopPreview, value);
129
- };
130
- const handleSnapshotFail = err => {
131
- setIgnoreHideStopPreview(false);
132
- console.log(err, 'err');
133
- const errObj = err.innerError || err || {};
134
- const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_error_screenshot_error_tip');
135
- toast({
136
- title: errMsg
137
- });
138
- };
139
66
  const granted = await ensureAlbumPermission();
140
- setIgnoreHideStopPreview(false);
67
+ ev.emit(changeIgnoreHideStopPreview, false);
141
68
  if (!granted) return;
142
- (() => {
143
- const requestId = ++snapshotRequestIdRef.current;
144
- IPCPlayerContext.snapshot({
145
- saveToAlbum,
146
- success: async res => {
147
- var _props$multiCameraCtx;
148
- setIgnoreHideStopPreview(false);
149
- const lensIndices = (_props$multiCameraCtx = props.multiCameraCtx) === null || _props$multiCameraCtx === void 0 || (_props$multiCameraCtx = _props$multiCameraCtx.protocol) === null || _props$multiCameraCtx === void 0 || (_props$multiCameraCtx = _props$multiCameraCtx.split_info) === null || _props$multiCameraCtx === void 0 ? void 0 : _props$multiCameraCtx.map(lens => lens.index);
150
- const summary = await getCaptureResultSummary(res, {
151
- multiLens: props.multiLens,
152
- lensIndices,
153
- devId
154
- });
155
- if (requestId !== snapshotRequestIdRef.current) return;
156
- if (!summary) return;
157
- setState({
158
- showShot: true,
159
- shotUrl: summary.thumbnailPath,
160
- shotCount: summary.isMultiLens ? summary.count : 0
161
- });
162
- },
163
- fail: handleSnapshotFail
164
- });
165
- })();
69
+ const requestId = ++requestIdRef.current;
70
+ IPCPlayerContext.snapshot({
71
+ saveToAlbum,
72
+ success: async res => {
73
+ var _props$multiCameraCtx;
74
+ ev.emit(changeIgnoreHideStopPreview, false);
75
+ const summary = await getCaptureResultSummary(res, {
76
+ multiLens: props.multiLens,
77
+ lensIndices: (_props$multiCameraCtx = props.multiCameraCtx) === null || _props$multiCameraCtx === void 0 || (_props$multiCameraCtx = _props$multiCameraCtx.protocol) === null || _props$multiCameraCtx === void 0 || (_props$multiCameraCtx = _props$multiCameraCtx.split_info) === null || _props$multiCameraCtx === void 0 ? void 0 : _props$multiCameraCtx.map(lens => lens.index),
78
+ devId
79
+ });
80
+ if (requestId !== requestIdRef.current || !summary) return;
81
+ showShotToast(summary.thumbnailPath, summary.isMultiLens ? summary.count : 0);
82
+ },
83
+ fail: err => {
84
+ ev.emit(changeIgnoreHideStopPreview, false);
85
+ const errObj = (err === null || err === void 0 ? void 0 : err.innerError) || err || {};
86
+ const errMsg = errObj.errorMsg || Strings.getLang('ipc_player_error_screenshot_error_tip');
87
+ toast({
88
+ title: errMsg
89
+ });
90
+ }
91
+ });
166
92
  });
167
93
  if (hideScreenShotMenu) return null;
168
94
  return /*#__PURE__*/React.createElement(View, {