@ray-js/ray-ipc-player 2.0.31 → 2.1.0-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.
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ interface ErrorOverlayProps {
3
+ isError: boolean;
4
+ videoErrCode: string | number;
5
+ borderRadius: number;
6
+ brandColor: string;
7
+ getClassName: (className: string) => string;
8
+ renderErrIcon?: () => React.ReactNode;
9
+ onRetry: () => void;
10
+ phoneNetworkConnect: boolean;
11
+ onlineStatus: boolean;
12
+ privateState: boolean;
13
+ isLowPowerDevice: boolean;
14
+ lowPowerDeviceOnlineState: boolean;
15
+ lowPrivateOutTimeFlag: boolean;
16
+ device4GIsFreeze: boolean;
17
+ deviceFreezeReason: number;
18
+ playStateErrorMsg: string;
19
+ devId: string;
20
+ hideSuggestedText: boolean;
21
+ hideHelpButton: boolean;
22
+ hideFeedBackButton: boolean;
23
+ isShare: boolean;
24
+ limitFlow: boolean;
25
+ autoPlay: boolean;
26
+ }
27
+ declare const ErrorOverlay: React.FC<ErrorOverlayProps>;
28
+ export default ErrorOverlay;
@@ -0,0 +1,293 @@
1
+ import React, { useMemo, useCallback } from 'react';
2
+ import { View, CoverView } from '@ray-js/components';
3
+ import clsx from 'clsx';
4
+ import _isEmpty from 'lodash/isEmpty';
5
+ import { getServiceUrl } from '@ray-js/ray-ipc-utils';
6
+ import Strings from '../i18n';
7
+ import { openTargetMinByShortLink, getLanguage, getHomeInfo, getDeviceInfo } from '../utils';
8
+ import { getErrCodeDetailDataByCode, codeCoverToInt } from '../config/errCodeConfig';
9
+ import { deviceFreezeReasonStore, miniIdLabs } from '../config';
10
+ const ErrorOverlay = _ref => {
11
+ let {
12
+ isError,
13
+ videoErrCode,
14
+ borderRadius,
15
+ brandColor,
16
+ getClassName,
17
+ renderErrIcon,
18
+ onRetry,
19
+ phoneNetworkConnect,
20
+ onlineStatus,
21
+ privateState,
22
+ isLowPowerDevice,
23
+ lowPowerDeviceOnlineState,
24
+ lowPrivateOutTimeFlag,
25
+ device4GIsFreeze,
26
+ deviceFreezeReason,
27
+ playStateErrorMsg,
28
+ devId,
29
+ hideSuggestedText,
30
+ hideHelpButton,
31
+ hideFeedBackButton,
32
+ isShare,
33
+ limitFlow,
34
+ autoPlay
35
+ } = _ref;
36
+ /**
37
+ * 获取错误展示内容
38
+ */
39
+ const getErrorContent = useMemo(() => {
40
+ if (!phoneNetworkConnect) {
41
+ return Strings.getLang('ipc_player_network_fail');
42
+ }
43
+
44
+ // 离线&流量不足
45
+ if (!onlineStatus && limitFlow) {
46
+ return Strings.getLang('ipc_player_traffic_load_offline_limit_tip');
47
+ }
48
+ if (!onlineStatus) {
49
+ return Strings.getLang('ipc_player_device_offline');
50
+ }
51
+
52
+ // 在线&流量不足
53
+ if (onlineStatus && limitFlow) {
54
+ return Strings.getLang('ipc_player_traffic_load_online_zero_tip');
55
+ }
56
+
57
+ // 未自动播放
58
+ if (!autoPlay) {
59
+ return Strings.getLang('ipc_player_sleep_tip');
60
+ }
61
+ if (!isLowPowerDevice && onlineStatus && privateState) {
62
+ return Strings.getLang('ipc_player_device_sleep');
63
+ }
64
+
65
+ // 低功耗隐私模式正常唤醒
66
+ if (isLowPowerDevice && lowPowerDeviceOnlineState && privateState && !lowPrivateOutTimeFlag) {
67
+ return Strings.getLang('ipc_player_device_sleep');
68
+ }
69
+ // 低功耗隐私模式正常唤醒,下发指令失败
70
+ if (isLowPowerDevice && lowPowerDeviceOnlineState && privateState && lowPrivateOutTimeFlag) {
71
+ return Strings.getLang('ipc_player_private_open_low_stream_fail');
72
+ }
73
+ if (!isLowPowerDevice && device4GIsFreeze && onlineStatus && !privateState) {
74
+ return deviceFreezeReasonStore[deviceFreezeReason];
75
+ }
76
+ if (isLowPowerDevice && device4GIsFreeze && lowPowerDeviceOnlineState && !privateState) {
77
+ return deviceFreezeReasonStore[deviceFreezeReason];
78
+ }
79
+ if (videoErrCode !== '') {
80
+ if (Strings["ipc_player_error_".concat(codeCoverToInt(videoErrCode))]) {
81
+ return "".concat(Strings.getLang("ipc_player_error_".concat(codeCoverToInt(videoErrCode))), "(").concat(videoErrCode, ")");
82
+ }
83
+ return "".concat(Strings.getLang("ipc_player_error_common"), "(").concat(videoErrCode, ")");
84
+ }
85
+ return playStateErrorMsg;
86
+ }, [phoneNetworkConnect, onlineStatus, privateState, isLowPowerDevice, lowPowerDeviceOnlineState, lowPrivateOutTimeFlag, device4GIsFreeze, deviceFreezeReason, limitFlow, autoPlay, videoErrCode, playStateErrorMsg]);
87
+
88
+ /**
89
+ * 根据自定义类型获取错误码展示内容
90
+ */
91
+ const getErrorContentByType = useCallback((errCode, type) => {
92
+ const errContent = getErrCodeDetailDataByCode(String(errCode));
93
+ const contentEmpty = _isEmpty(errContent);
94
+ switch (type) {
95
+ // 是否展示建议文案
96
+ case 'suggestedFlag':
97
+ if (hideSuggestedText) {
98
+ return false;
99
+ }
100
+ if (contentEmpty) {
101
+ return false;
102
+ }
103
+ return errContent.suggestedText !== '';
104
+
105
+ // 建议文案
106
+ case 'suggestedText':
107
+ if (contentEmpty || privateState) {
108
+ return '';
109
+ }
110
+ return errContent.suggestedText;
111
+ // 是否展示点我重试
112
+ case 'retry':
113
+ if (limitFlow) {
114
+ return true;
115
+ }
116
+ if (!phoneNetworkConnect) {
117
+ return false;
118
+ }
119
+ if (!isLowPowerDevice && !onlineStatus) {
120
+ return false;
121
+ }
122
+ if (isLowPowerDevice && !lowPowerDeviceOnlineState) {
123
+ return false;
124
+ }
125
+ if (privateState && !isShare && !device4GIsFreeze) {
126
+ return true;
127
+ }
128
+ if (privateState && isShare) {
129
+ return false;
130
+ }
131
+
132
+ // 设备4G冻结,冻结原因为特殊情况下,展示retry
133
+ if (device4GIsFreeze && onlineStatus && !privateState && deviceFreezeReason === 1) {
134
+ return true;
135
+ }
136
+ if (contentEmpty || privateState) {
137
+ return true;
138
+ }
139
+ return errContent.try;
140
+ // 是否展示点我重试
141
+ case 'retryText':
142
+ if (limitFlow) {
143
+ return Strings.getLang('ipc_player_recharge_flow_btn');
144
+ }
145
+ if (!autoPlay) {
146
+ return Strings.getLang('ipc_player_open_sleep_mode');
147
+ }
148
+ if (privateState) {
149
+ return Strings.getLang('ipc_player_re_wake_camera');
150
+ }
151
+ return Strings.getLang('ipc_player_retry');
152
+ case 'help':
153
+ if (hideHelpButton) {
154
+ return false;
155
+ }
156
+ if (!phoneNetworkConnect || privateState) {
157
+ return false;
158
+ }
159
+ if (isLowPowerDevice && lowPowerDeviceOnlineState) {
160
+ return false;
161
+ }
162
+ if (isLowPowerDevice && !lowPowerDeviceOnlineState) {
163
+ return true;
164
+ }
165
+ if (!isLowPowerDevice && !onlineStatus) {
166
+ return true;
167
+ }
168
+ if (privateState && isShare) {
169
+ return false;
170
+ }
171
+ if (contentEmpty) {
172
+ return false;
173
+ }
174
+ return errContent.help;
175
+ case 'helpNum':
176
+ if (privateState && isShare) {
177
+ return false;
178
+ }
179
+ return errContent.helpNum;
180
+ case 'feedBack':
181
+ if (hideFeedBackButton) {
182
+ return false;
183
+ }
184
+ if (!phoneNetworkConnect) {
185
+ return true;
186
+ }
187
+ if (privateState) {
188
+ return false;
189
+ }
190
+ if (contentEmpty) {
191
+ return false;
192
+ }
193
+ return errContent.feedBack;
194
+ default:
195
+ return false;
196
+ }
197
+ }, [hideSuggestedText, privateState, limitFlow, phoneNetworkConnect, isLowPowerDevice, onlineStatus, lowPowerDeviceOnlineState, isShare, device4GIsFreeze, deviceFreezeReason, hideHelpButton, hideFeedBackButton]);
198
+
199
+ /**
200
+ * 跳转4G流量充值页面
201
+ */
202
+ const handleGotoTrafficRecharge = useCallback(async () => {
203
+ const result = await getServiceUrl(devId, 'traffic_service', {}, true);
204
+ console.log('result', result);
205
+ }, [devId]);
206
+
207
+ /**
208
+ * 跳转帮助小程序
209
+ */
210
+ const handleGotoHelpMini = useCallback(async () => {
211
+ if (isLowPowerDevice && !lowPowerDeviceOnlineState || !onlineStatus) {
212
+ const realLanguage = await getLanguage();
213
+ const url = "godzilla://".concat(miniIdLabs.helpMini, "/pages/commonDetails/index?answer=/app-helpcenter/").concat(realLanguage, "/K94ow0gwu9bg2");
214
+ openTargetMinByShortLink(url);
215
+ return false;
216
+ }
217
+ const helpNum = getErrorContentByType(videoErrCode, 'helpNum');
218
+ const helpFeedBack = getErrorContentByType(videoErrCode, 'helpFeedBack');
219
+ const homeInfo = await getHomeInfo();
220
+ const devInfo = await getDeviceInfo(devId);
221
+ const url = "godzilla://".concat(miniIdLabs.ipcHelpMini, "?errCode=").concat(videoErrCode, "&deviceId=").concat(devId, "&homeId=").concat(homeInfo === null || homeInfo === void 0 ? void 0 : homeInfo.homeId, "&instanceId=").concat(devInfo === null || devInfo === void 0 ? void 0 : devInfo.uuid, "&helpNum=").concat(helpNum, "&helpFeedBack=").concat(helpFeedBack, "&themeColor=").concat(brandColor);
222
+ openTargetMinByShortLink(url);
223
+ return false;
224
+ }, [isLowPowerDevice, lowPowerDeviceOnlineState, onlineStatus, videoErrCode, devId, brandColor, getErrorContentByType]);
225
+
226
+ /**
227
+ * 跳转反馈小程序
228
+ */
229
+ const handleGotoFeedBackMini = useCallback(() => {
230
+ const url = "godzilla://".concat(miniIdLabs.helpMini, "/pages/v2/problemSubmit/index");
231
+ openTargetMinByShortLink(url);
232
+ }, []);
233
+
234
+ // 自定义处理点击重试逻辑
235
+ const handleCustomRetry = useCallback(() => {
236
+ if (limitFlow) {
237
+ // 流量不足时的处理逻辑,跳转到充值页面
238
+ handleGotoTrafficRecharge();
239
+ } else {
240
+ onRetry();
241
+ }
242
+ }, [limitFlow, onRetry, handleGotoTrafficRecharge, onlineStatus]);
243
+
244
+ /**
245
+ * 获取错误图标 className
246
+ */
247
+ const getErrorIconClassName = useCallback(() => {
248
+ if (limitFlow && onlineStatus) {
249
+ return 'err-icon-flow-limit';
250
+ }
251
+ if (!autoPlay) {
252
+ return 'err-icon-sleep';
253
+ }
254
+ return 'err-icon';
255
+ }, [autoPlay, limitFlow, onlineStatus]);
256
+ if (!isError) return null;
257
+ return /*#__PURE__*/React.createElement(CoverView, {
258
+ style: {
259
+ borderRadius: "".concat(borderRadius)
260
+ },
261
+ className: clsx(getClassName('bg-center'), getClassName('error-container'), !isError && getClassName('hide')),
262
+ onClick: () => {
263
+ return false;
264
+ }
265
+ }, /*#__PURE__*/React.createElement(View, {
266
+ className: clsx(getClassName('err-icon-container'))
267
+ }, renderErrIcon ? renderErrIcon() : /*#__PURE__*/React.createElement(View, {
268
+ className: clsx(getClassName(getErrorIconClassName()))
269
+ })), /*#__PURE__*/React.createElement(View, {
270
+ className: clsx(getClassName('err-text-container'))
271
+ }, /*#__PURE__*/React.createElement(View, {
272
+ className: clsx(getClassName('err-content'))
273
+ }, getErrorContent), getErrorContentByType(videoErrCode, 'suggestedFlag') && /*#__PURE__*/React.createElement(View, {
274
+ className: clsx(getClassName('err-desc'))
275
+ }, getErrorContentByType(videoErrCode, 'suggestedText'))), /*#__PURE__*/React.createElement(View, {
276
+ className: clsx(getClassName('err-operator-container'))
277
+ }, getErrorContentByType(videoErrCode, 'retry') && /*#__PURE__*/React.createElement(View, {
278
+ className: clsx(getClassName('operator-btn'), getClassName('operator-retry')),
279
+ style: {
280
+ backgroundColor: "".concat(brandColor)
281
+ },
282
+ onClick: handleCustomRetry
283
+ }, getErrorContentByType(videoErrCode, 'retryText'), limitFlow && /*#__PURE__*/React.createElement(View, {
284
+ className: clsx(getClassName('btn-right-arrow'))
285
+ })), getErrorContentByType(videoErrCode, 'help') && /*#__PURE__*/React.createElement(View, {
286
+ className: clsx(getClassName('operator-btn'), getClassName('operator-help')),
287
+ onClick: handleGotoHelpMini
288
+ }, Strings.getLang('ipc_player_help')), getErrorContentByType(videoErrCode, 'feedBack') && /*#__PURE__*/React.createElement(View, {
289
+ className: clsx(getClassName('operator-btn'), getClassName('operator-feedback')),
290
+ onClick: handleGotoFeedBackMini
291
+ }, Strings.getLang('ipc_player_feedback'))));
292
+ };
293
+ export default ErrorOverlay;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ interface FullScreenBackButtonProps {
3
+ isVisible: boolean;
4
+ getClassName: (className: string) => string;
5
+ onBackFullScreen: () => void;
6
+ }
7
+ declare const FullScreenBackButton: React.FC<FullScreenBackButtonProps>;
8
+ export default FullScreenBackButton;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { CoverView } from '@ray-js/components';
3
+ import clsx from 'clsx';
4
+ const FullScreenBackButton = _ref => {
5
+ let {
6
+ isVisible,
7
+ getClassName,
8
+ onBackFullScreen
9
+ } = _ref;
10
+ if (!isVisible) return null;
11
+ return /*#__PURE__*/React.createElement(CoverView, {
12
+ className: clsx(getClassName('load-full-back-container')),
13
+ onClick: onBackFullScreen
14
+ });
15
+ };
16
+ export default FullScreenBackButton;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface LoadingOverlayProps {
3
+ isLoading: boolean;
4
+ loadingText?: string;
5
+ borderRadius: number;
6
+ getClassName: (className: string) => string;
7
+ }
8
+ declare const LoadingOverlay: React.FC<LoadingOverlayProps>;
9
+ export default LoadingOverlay;
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { View, CoverView } from '@ray-js/components';
3
+ import clsx from 'clsx';
4
+ import Strings from '../i18n';
5
+ const LoadingOverlay = _ref => {
6
+ let {
7
+ isLoading,
8
+ loadingText,
9
+ borderRadius,
10
+ getClassName
11
+ } = _ref;
12
+ if (!isLoading) return null;
13
+ return /*#__PURE__*/React.createElement(CoverView, {
14
+ style: {
15
+ borderRadius: "".concat(borderRadius)
16
+ },
17
+ className: clsx(getClassName('load-box'), getClassName('bg-center'), !isLoading && getClassName('hide')),
18
+ onClick: () => {
19
+ return false;
20
+ }
21
+ }, /*#__PURE__*/React.createElement(View, {
22
+ className: getClassName('load-icon')
23
+ }), /*#__PURE__*/React.createElement(View, {
24
+ className: getClassName('load-des')
25
+ }, loadingText || Strings.getLang('ipc_player_get_video_stream')));
26
+ };
27
+ export default LoadingOverlay;
@@ -0,0 +1,3 @@
1
+ export { default as LoadingOverlay } from './LoadingOverlay';
2
+ export { default as ErrorOverlay } from './ErrorOverlay';
3
+ export { default as FullScreenBackButton } from './FullScreenBackButton';
@@ -0,0 +1,3 @@
1
+ export { default as LoadingOverlay } from './LoadingOverlay';
2
+ export { default as ErrorOverlay } from './ErrorOverlay';
3
+ export { default as FullScreenBackButton } from './FullScreenBackButton';
@@ -4,4 +4,5 @@ interface UseWakeUpDeviceOptions {
4
4
  intervalTime?: number;
5
5
  }
6
6
  export declare const useWakeUpDevice: ({ deviceId, enabled, intervalTime, }: UseWakeUpDeviceOptions) => void;
7
- export {};
7
+ export { usePlayerProps } from './usePlayerProps';
8
+ export { usePlayerConnection } from './usePlayerConnection';
@@ -31,4 +31,6 @@ export const useWakeUpDevice = _ref => {
31
31
  }
32
32
  };
33
33
  }, [enabled, deviceId, intervalTime]);
34
- };
34
+ };
35
+ export { usePlayerProps } from './usePlayerProps';
36
+ export { usePlayerConnection } from './usePlayerConnection';
@@ -0,0 +1,40 @@
1
+ /// <reference types="react" />
2
+ /// <reference types="node" />
3
+ interface UsePlayerConnectionOptions {
4
+ devId: string;
5
+ ipcCtx: React.MutableRefObject<any>;
6
+ playState: any;
7
+ setPlayState: (updater: (draft: any) => void) => void;
8
+ setVideoErrCode: (code: string | number) => void;
9
+ onChangeStreamStatus?: (status: number) => void;
10
+ onInitPreview?: (devId: string) => void;
11
+ playerRoute: string;
12
+ privateState: boolean;
13
+ isLowPowerDevice: boolean;
14
+ awakeStatus?: boolean;
15
+ wirelessFlag: boolean;
16
+ setEnableWakeUpInterval: (enabled: boolean) => void;
17
+ setLowPrivateOutTimeFlag: (flag: boolean) => void;
18
+ setMqttPrivateFlag: (flag: boolean) => void;
19
+ privateLowPowerDeviceTimeOutRef: React.MutableRefObject<NodeJS.Timeout | null>;
20
+ privateWakeOutTimeRef: React.MutableRefObject<NodeJS.Timeout | null>;
21
+ firstPreviewTimeRef: React.MutableRefObject<boolean>;
22
+ retryCount: React.MutableRefObject<number>;
23
+ muteRef: React.MutableRefObject<boolean>;
24
+ setMuted: (val: boolean) => void;
25
+ }
26
+ /**
27
+ * 播放器连接相关逻辑的自定义 hook
28
+ */
29
+ export declare const usePlayerConnection: ({ devId, ipcCtx, playState, setPlayState, setVideoErrCode, onChangeStreamStatus, onInitPreview, playerRoute, privateState, isLowPowerDevice, awakeStatus, wirelessFlag, setEnableWakeUpInterval, setLowPrivateOutTimeFlag, setMqttPrivateFlag, privateLowPowerDeviceTimeOutRef, privateWakeOutTimeRef, firstPreviewTimeRef, retryCount, muteRef, setMuted, }: UsePlayerConnectionOptions) => {
30
+ _retry: () => Promise<void>;
31
+ _reConnect: () => void;
32
+ createConnect: (this: unknown, params?: string | undefined) => Promise<void>;
33
+ startPreview: (this: any, params: any) => void;
34
+ stopPreview: () => void;
35
+ disconnect: () => Promise<unknown>;
36
+ handleReWakeCamera: () => Promise<void>;
37
+ handleReWakeCameraLowPowerDevice: (this: unknown) => void;
38
+ getPlayerRoute: () => string;
39
+ };
40
+ export {};