@ray-js/ray-ipc-player 2.1.1-beta.2 → 2.1.1-beta.3
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.
|
@@ -22,7 +22,8 @@ interface ErrorOverlayProps {
|
|
|
22
22
|
hideFeedBackButton: boolean;
|
|
23
23
|
isShare: boolean;
|
|
24
24
|
limitFlow: boolean;
|
|
25
|
-
|
|
25
|
+
/** 是否开启预览拉流,与 Player 内 previewOn 一致(previewEnabled ?? true) */
|
|
26
|
+
previewOn: boolean;
|
|
26
27
|
}
|
|
27
28
|
declare const ErrorOverlay: React.FC<ErrorOverlayProps>;
|
|
28
29
|
export default ErrorOverlay;
|
|
@@ -31,7 +31,7 @@ const ErrorOverlay = _ref => {
|
|
|
31
31
|
hideFeedBackButton,
|
|
32
32
|
isShare,
|
|
33
33
|
limitFlow,
|
|
34
|
-
|
|
34
|
+
previewOn
|
|
35
35
|
} = _ref;
|
|
36
36
|
/**
|
|
37
37
|
* 获取错误展示内容
|
|
@@ -54,8 +54,8 @@ const ErrorOverlay = _ref => {
|
|
|
54
54
|
return Strings.getLang('ipc_player_traffic_load_online_zero_tip');
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
//
|
|
58
|
-
if (!
|
|
57
|
+
// 未开启预览拉流(休眠态提示)
|
|
58
|
+
if (!previewOn) {
|
|
59
59
|
return Strings.getLang('ipc_player_sleep_tip');
|
|
60
60
|
}
|
|
61
61
|
if (!isLowPowerDevice && onlineStatus && privateState) {
|
|
@@ -83,7 +83,7 @@ const ErrorOverlay = _ref => {
|
|
|
83
83
|
return "".concat(Strings.getLang("ipc_player_error_common"), "(").concat(videoErrCode, ")");
|
|
84
84
|
}
|
|
85
85
|
return playStateErrorMsg;
|
|
86
|
-
}, [phoneNetworkConnect, onlineStatus, privateState, isLowPowerDevice, lowPowerDeviceOnlineState, lowPrivateOutTimeFlag, device4GIsFreeze, deviceFreezeReason, limitFlow,
|
|
86
|
+
}, [phoneNetworkConnect, onlineStatus, privateState, isLowPowerDevice, lowPowerDeviceOnlineState, lowPrivateOutTimeFlag, device4GIsFreeze, deviceFreezeReason, limitFlow, previewOn, videoErrCode, playStateErrorMsg]);
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* 根据自定义类型获取错误码展示内容
|
|
@@ -142,7 +142,7 @@ const ErrorOverlay = _ref => {
|
|
|
142
142
|
if (limitFlow) {
|
|
143
143
|
return Strings.getLang('ipc_player_recharge_flow_btn');
|
|
144
144
|
}
|
|
145
|
-
if (!
|
|
145
|
+
if (!previewOn) {
|
|
146
146
|
return Strings.getLang('ipc_player_open_sleep_mode');
|
|
147
147
|
}
|
|
148
148
|
if (privateState) {
|
|
@@ -194,7 +194,7 @@ const ErrorOverlay = _ref => {
|
|
|
194
194
|
default:
|
|
195
195
|
return false;
|
|
196
196
|
}
|
|
197
|
-
}, [hideSuggestedText, privateState, limitFlow, phoneNetworkConnect, isLowPowerDevice, onlineStatus, lowPowerDeviceOnlineState, isShare, device4GIsFreeze, deviceFreezeReason, hideHelpButton, hideFeedBackButton]);
|
|
197
|
+
}, [hideSuggestedText, privateState, limitFlow, phoneNetworkConnect, isLowPowerDevice, onlineStatus, lowPowerDeviceOnlineState, isShare, device4GIsFreeze, deviceFreezeReason, hideHelpButton, hideFeedBackButton, previewOn]);
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
200
|
* 跳转4G流量充值页面
|
|
@@ -248,11 +248,11 @@ const ErrorOverlay = _ref => {
|
|
|
248
248
|
if (limitFlow && onlineStatus) {
|
|
249
249
|
return 'err-icon-flow-limit';
|
|
250
250
|
}
|
|
251
|
-
if (!
|
|
251
|
+
if (!previewOn) {
|
|
252
252
|
return 'err-icon-sleep';
|
|
253
253
|
}
|
|
254
254
|
return 'err-icon';
|
|
255
|
-
}, [
|
|
255
|
+
}, [previewOn, limitFlow, onlineStatus]);
|
|
256
256
|
if (!isError) return null;
|
|
257
257
|
return /*#__PURE__*/React.createElement(CoverView, {
|
|
258
258
|
style: {
|
package/lib/index.js
CHANGED
|
@@ -99,15 +99,13 @@ const Player = props => {
|
|
|
99
99
|
/** 传入 previewEnabled 为受控;未传时 previewOn 为 true(自动拉流) */
|
|
100
100
|
const isPreviewControlled = previewEnabled !== undefined;
|
|
101
101
|
const previewOn = previewEnabled !== null && previewEnabled !== void 0 ? previewEnabled : true;
|
|
102
|
-
|
|
103
|
-
// connectChangeRef
|
|
104
102
|
useRef(null);
|
|
105
103
|
const firstPreviewTimeRef = useRef(false);
|
|
106
104
|
|
|
107
105
|
// 标记是否进入内存缓存/后台(onPause、onHide 设为 true,onShow 还原为 false),拉流时若为 true 则拦截
|
|
108
106
|
const isInBackgroundRef = useRef(false);
|
|
109
|
-
/**
|
|
110
|
-
const
|
|
107
|
+
/** 网络/在线等早于 onShow 触发拉流时 isInBackgroundRef 仍为 true,记一次待回到前台后补拉 */
|
|
108
|
+
const pendingForegroundPullRef = useRef(false);
|
|
111
109
|
|
|
112
110
|
// 自定义计时老低功耗方案设备在线状态, 用于短暂时间报上下线的UI展示兼容 待实现
|
|
113
111
|
const [lowPowerDeviceOnlineState, setLowPowerDeviceOnlineState] = useState(onlineStatus);
|
|
@@ -203,8 +201,10 @@ const Player = props => {
|
|
|
203
201
|
if (isInBackgroundRef.current) {
|
|
204
202
|
console.log('处于后台/内存缓存,拦截拉流');
|
|
205
203
|
ipcTTTOperatorLog('VID: isInBackground, block retry');
|
|
204
|
+
pendingForegroundPullRef.current = true;
|
|
206
205
|
return;
|
|
207
206
|
}
|
|
207
|
+
pendingForegroundPullRef.current = false;
|
|
208
208
|
if (isPreviewControlled) {
|
|
209
209
|
onPreviewEnabledChange === null || onPreviewEnabledChange === void 0 || onPreviewEnabledChange(true);
|
|
210
210
|
if (previewEnabled) {
|
|
@@ -215,6 +215,29 @@ const Player = props => {
|
|
|
215
215
|
runPullStream();
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
+
/** 回到前台后补拉:解决 onNetworkStatusChange 等早于 onShow 触发 retry 被拦的问题 */
|
|
219
|
+
const flushPendingForegroundPull = useMemoizedFn(() => {
|
|
220
|
+
if (!pendingForegroundPullRef.current) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!previewOn) {
|
|
224
|
+
pendingForegroundPullRef.current = false;
|
|
225
|
+
ipcTTTOperatorLog('VID: flush_pending_cleared_preview_off');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (!phoneNetworkConnect || !playState.initLy || !ipcCtx.current || !onlineStatus || privateState || limitFlow || !previewOn) {
|
|
229
|
+
ipcTTTOperatorLog('VID: flush_pending_skip_not_ready');
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
pendingForegroundPullRef.current = false;
|
|
233
|
+
ipcTTTOperatorLog('VID: flush_pending_foreground_pull');
|
|
234
|
+
if (isPreviewControlled) {
|
|
235
|
+
runPullStream();
|
|
236
|
+
} else {
|
|
237
|
+
retry();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
218
241
|
/**
|
|
219
242
|
* 命令式开关:受控走 onPreviewEnabledChange;未传 previewEnabled 时 previewOn 恒为 true,仅支持开启拉流(retry)
|
|
220
243
|
*/
|
|
@@ -237,7 +260,18 @@ const Player = props => {
|
|
|
237
260
|
});
|
|
238
261
|
};
|
|
239
262
|
usePageEvent('onShow', useMemoizedFn(async () => {
|
|
263
|
+
const wasBackground = isInBackgroundRef.current;
|
|
240
264
|
isInBackgroundRef.current = false;
|
|
265
|
+
if (wasBackground && !ignoreHideStopPreview) {
|
|
266
|
+
setVideoErrCode('');
|
|
267
|
+
if (previewOn) {
|
|
268
|
+
setPlayState(d => {
|
|
269
|
+
d.loadingState = true;
|
|
270
|
+
d.errorState = false;
|
|
271
|
+
d.errorMsg = '';
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
241
275
|
getNetworkType({
|
|
242
276
|
success: res => {
|
|
243
277
|
console.log('网络类型', res);
|
|
@@ -252,21 +286,12 @@ const Player = props => {
|
|
|
252
286
|
onChangeIgnoreHideStopPreview && onChangeIgnoreHideStopPreview(false);
|
|
253
287
|
return;
|
|
254
288
|
}
|
|
255
|
-
// 受控 preview:后台/隐藏时已把父级置为 false,前台先恢复意图再拉流(不依赖同一帧 previewOn)
|
|
256
|
-
if (previewPausedByLifecycleRef.current && isPreviewControlled) {
|
|
257
|
-
previewPausedByLifecycleRef.current = false;
|
|
258
|
-
onPreviewEnabledChange === null || onPreviewEnabledChange === void 0 || onPreviewEnabledChange(true);
|
|
259
|
-
if (phoneNetworkConnect && playState.initLy && ipcCtx.current && onlineStatus && !privateState && !limitFlow) {
|
|
260
|
-
ipcTTTOperatorLog('VID: onShow_resume_after_hide_pause');
|
|
261
|
-
runPullStream();
|
|
262
|
-
}
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
289
|
// 视图准备就绪
|
|
266
290
|
if (phoneNetworkConnect && playState.initLy && ipcCtx.current && onlineStatus && !privateState && !limitFlow && previewOn) {
|
|
267
291
|
ipcTTTOperatorLog('VID: onShow_event_to_retry');
|
|
268
292
|
retry();
|
|
269
293
|
}
|
|
294
|
+
flushPendingForegroundPull();
|
|
270
295
|
}));
|
|
271
296
|
usePageEvent('onResize', sizeData => {
|
|
272
297
|
const {
|
|
@@ -283,21 +308,22 @@ const Player = props => {
|
|
|
283
308
|
}
|
|
284
309
|
});
|
|
285
310
|
|
|
286
|
-
// 针对limitFlow
|
|
311
|
+
// 针对limitFlow / 未拉流:休眠态 UI
|
|
287
312
|
useEffect(() => {
|
|
288
|
-
if (limitFlow || !previewOn) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
313
|
+
if (!(limitFlow || !previewOn)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
setPlayState(d => {
|
|
317
|
+
return _objectSpread(_objectSpread({}, d), {}, {
|
|
318
|
+
loadingState: false,
|
|
319
|
+
errorState: true,
|
|
320
|
+
errorMessage: ''
|
|
295
321
|
});
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
322
|
+
});
|
|
323
|
+
ipcTTTOperatorLog("limitFlow ~~~~ ".concat(limitFlow, " previewOn ~~~ ").concat(previewOn));
|
|
324
|
+
if (playState.initLy && ipcCtx.current) {
|
|
325
|
+
stopPreview();
|
|
326
|
+
disconnect();
|
|
301
327
|
}
|
|
302
328
|
}, [limitFlow, previewOn, playState.initLy, ipcCtx.current]);
|
|
303
329
|
useEffect(() => {
|
|
@@ -335,10 +361,6 @@ const Player = props => {
|
|
|
335
361
|
if (ignoreHideStopPreview) {
|
|
336
362
|
return;
|
|
337
363
|
}
|
|
338
|
-
if (isPreviewControlled && previewOn) {
|
|
339
|
-
previewPausedByLifecycleRef.current = true;
|
|
340
|
-
onPreviewEnabledChange === null || onPreviewEnabledChange === void 0 || onPreviewEnabledChange(false);
|
|
341
|
-
}
|
|
342
364
|
setPlayState(d => {
|
|
343
365
|
d.loadingState = true;
|
|
344
366
|
});
|
|
@@ -350,10 +372,6 @@ const Player = props => {
|
|
|
350
372
|
isInBackgroundRef.current = true;
|
|
351
373
|
console.log('onPause, 重新拉流');
|
|
352
374
|
ipcTTTOperatorLog('VID: onPause stopPreview');
|
|
353
|
-
if (!ignoreHideStopPreview && isPreviewControlled && previewOn) {
|
|
354
|
-
previewPausedByLifecycleRef.current = true;
|
|
355
|
-
onPreviewEnabledChange === null || onPreviewEnabledChange === void 0 || onPreviewEnabledChange(false);
|
|
356
|
-
}
|
|
357
375
|
stopPreview();
|
|
358
376
|
disconnect();
|
|
359
377
|
}));
|
|
@@ -578,6 +596,12 @@ const Player = props => {
|
|
|
578
596
|
});
|
|
579
597
|
} else if (playState.initLy && !privateState) {
|
|
580
598
|
ipcTTTOperatorLog("VID: privateState_status_change: ".concat(privateState));
|
|
599
|
+
// 网络/在线等回调可能早于页面 onShow,此时 isInBackgroundRef 仍为 true,避免 retry 被误拦;等 onShow 再拉流
|
|
600
|
+
if (isInBackgroundRef.current) {
|
|
601
|
+
ipcTTTOperatorLog('VID: skip_pull_in_status_effect_while_background');
|
|
602
|
+
pendingForegroundPullRef.current = true;
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
581
605
|
if (isPreviewControlled) {
|
|
582
606
|
runPullStream();
|
|
583
607
|
} else {
|
|
@@ -767,7 +791,7 @@ const Player = props => {
|
|
|
767
791
|
hideFeedBackButton: hideFeedBackButton,
|
|
768
792
|
isShare: isShare,
|
|
769
793
|
limitFlow: limitFlow,
|
|
770
|
-
|
|
794
|
+
previewOn: previewOn
|
|
771
795
|
}), /*#__PURE__*/React.createElement(FullScreenBackButton, {
|
|
772
796
|
isVisible: screenType === 'landscape' && (playState.loadingState || playState.errorState),
|
|
773
797
|
getClassName: getClassName,
|