@ray-js/ipc-player-integration 0.0.19 → 0.0.20-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.
package/lib/ui/ui.d.ts CHANGED
@@ -26,6 +26,7 @@ type Props = {
26
26
  CSSVariable?: Partial<CSSVariable>;
27
27
  brandColor?: string;
28
28
  verticalMic?: boolean;
29
+ playerRoute?: string;
29
30
  landscapeMode?: 'fill' | 'standard';
30
31
  playerFit: 'contain' | 'cover';
31
32
  awakeStatus?: boolean | undefined;
package/lib/ui/ui.js CHANGED
@@ -3,7 +3,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import "core-js/modules/esnext.iterator.constructor.js";
4
4
  import "core-js/modules/esnext.iterator.map.js";
5
5
  import React, { useContext, useState, useRef, useMemo, useEffect, useImperativeHandle } from 'react';
6
- import { View, CoverView, getSystemInfoSync, usePageEvent, setNavigationBarBack, setPageOrientation } from '@ray-js/ray';
6
+ import { View, CoverView, getSystemInfoSync, usePageEvent, setNavigationBarBack, setPageOrientation, getCurrentPages } from '@ray-js/ray';
7
7
  import clsx from 'clsx';
8
8
  import IPCPlayer from '@ray-js/ray-ipc-player';
9
9
  import { ipcTTTOperatorLog } from '@ray-js/ray-ipc-utils';
@@ -58,6 +58,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
58
58
  playerFit = 'contain',
59
59
  awakeStatus = undefined,
60
60
  onPlayerTap,
61
+ playerRoute = 'pages/home/index',
61
62
  extend = {}
62
63
  } = props;
63
64
  const {
@@ -73,6 +74,8 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
73
74
  setRecording
74
75
  } = instance;
75
76
  const prevTriggerEvent = useRef();
77
+ const hasPlayedRef = useRef(false);
78
+
76
79
  /*
77
80
  player 的UI效果期望有一些控件在初始化的时候都展示,在点击 Player 之后隐藏:
78
81
  在控件显示时,点击播放器期望隐藏控件
@@ -87,6 +90,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
87
90
  }
88
91
  useImperativeHandle(eventRefProp, () => eventRef.current, [eventRef.current]);
89
92
  const timer = useRef();
93
+ const reGetOrientationTimer = useRef(null);
90
94
  const [scaleMultiple, setScaleMultiple] = useState(playerFit === 'contain' ? 1 : -2);
91
95
  const [currentZoomLevel, setCurrentZoomLevel] = useState(playerFit === 'contain' ? 1 : -2);
92
96
  const [createCtx, setCreateCtx] = useState(false);
@@ -94,6 +98,108 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
94
98
  // const [verticalCoverZoom, setVerticalCoverZoom] = useState(-2);
95
99
  // const [verticalZoomLevel, setVerticalZoomLevel] = useState(playerFit === 'contain' ? 1 : -2);
96
100
 
101
+ const handleOrientationChange = useMemoizedFn(data => {
102
+ console.log(data, 'data=============');
103
+ const {
104
+ orientation
105
+ } = data;
106
+ console.log(orientation, 'orientation=-====');
107
+ if (['portrait', 'landscape-left', 'landscape-right'].includes(orientation)) {
108
+ var _ty;
109
+ if (typeof ((_ty = ty) === null || _ty === void 0 ? void 0 : _ty.getDeviceOrientationSync) !== 'function') return;
110
+ if (getPlayerRoute() !== playerRoute) {
111
+ // 不是Player首页的话,禁止以下行为
112
+ return;
113
+ }
114
+ console.log('屏幕方向变化调用吗');
115
+ setPageOrientation({
116
+ pageOrientation: orientation === 'landscape-left' || orientation === 'landscape-right' ? 'landscape' : 'portrait',
117
+ reverse: orientation === 'landscape-left',
118
+ success: () => {
119
+ console.log('set page orientation success');
120
+ },
121
+ fail: err => {
122
+ console.log('set page orientation fail', err);
123
+ }
124
+ });
125
+ }
126
+ });
127
+ useEffect(() => {
128
+ var _ty2;
129
+ console.log('getDeviceOrientationSync =======');
130
+ if (typeof ((_ty2 = ty) === null || _ty2 === void 0 ? void 0 : _ty2.getDeviceOrientationSync) !== 'function') return undefined;
131
+ try {
132
+ ty.onOrientationChange(handleOrientationChange);
133
+ const {
134
+ orientation
135
+ } = ty.getDeviceOrientationSync();
136
+ console.log(orientation, 'initial orientation');
137
+ if (orientation === 'landscape-left' || orientation === 'landscape-right') {
138
+ setScreenType('full');
139
+ }
140
+ if (orientation === 'unknown' || orientation === undefined) {
141
+ // 1秒后重试一次
142
+ const retryGetOrientation = () => {
143
+ const {
144
+ orientation
145
+ } = ty.getDeviceOrientationSync();
146
+ console.log(orientation, 'retry orientation');
147
+ if (orientation !== 'unknown' && orientation !== undefined) {
148
+ // 获取到有效方向,清除定时器并处理
149
+ if (reGetOrientationTimer.current) {
150
+ clearTimeout(reGetOrientationTimer.current);
151
+ reGetOrientationTimer.current = null;
152
+ }
153
+ if (orientation === 'landscape-left' || orientation === 'landscape-right') {
154
+ setScreenType('full');
155
+ }
156
+ handleOrientationChange({
157
+ orientation
158
+ });
159
+ } else {
160
+ // 仍然无效,继续重试
161
+ reGetOrientationTimer.current = setTimeout(retryGetOrientation, 1000);
162
+ }
163
+ };
164
+ reGetOrientationTimer.current = setTimeout(retryGetOrientation, 1000);
165
+ }
166
+ handleOrientationChange(orientation);
167
+ } catch (e) {
168
+ console.log('获取屏幕方向失败', e);
169
+ }
170
+ return () => {
171
+ var _ty3;
172
+ if (typeof ((_ty3 = ty) === null || _ty3 === void 0 ? void 0 : _ty3.offOrientationChange) === 'function') {
173
+ ty.offOrientationChange(handleOrientationChange);
174
+ }
175
+ };
176
+ }, []);
177
+ const getPlayerRoute = () => {
178
+ const pages = getCurrentPages(); // 获取当前页面栈
179
+ const currentPage = pages[pages.length - 1]; // 获取当前页面实例
180
+ return currentPage.route;
181
+ };
182
+ const {
183
+ topLeftContent,
184
+ topRightContent,
185
+ bottomLeftContent,
186
+ bottomRightContent,
187
+ absoluteContent,
188
+ screenType,
189
+ playState,
190
+ resolution,
191
+ mute
192
+ } = useStore({
193
+ topLeftContent: instance.topLeftContent,
194
+ topRightContent: instance.topRightContent,
195
+ bottomLeftContent: instance.bottomLeftContent,
196
+ bottomRightContent: instance.bottomRightContent,
197
+ absoluteContent: instance.absoluteContent,
198
+ screenType: instance.screenType,
199
+ playState: instance.playState,
200
+ resolution: instance.resolution,
201
+ mute: instance.mute
202
+ });
97
203
  useEffect(() => {
98
204
  if (createCtx) {
99
205
  setScaleMultiple(playerFit === 'contain' ? 1 : -2);
@@ -118,13 +224,17 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
118
224
  * 监听屏幕布局变化
119
225
  */
120
226
  usePageEvent('onResize', useMemoizedFn(sizeData => {
227
+ console.log(getPlayerRoute(), 'getPlayerRoute()');
228
+ if (getPlayerRoute() !== playerRoute) {
229
+ // 不是Player首页的话,禁止以下行为
230
+ return;
231
+ }
121
232
  try {
122
233
  const {
123
234
  type
124
235
  } = sizeData;
125
236
  console.log('监听到屏幕布局变化', type);
126
237
  const {
127
- platform,
128
238
  deviceType
129
239
  } = systemInfo.current;
130
240
  // 针对pad 暂不支持横屏,且在ios pad模式下 会触发onResize事件, 待解决
@@ -136,34 +246,16 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
136
246
  }
137
247
  // 若为全屏模式并且要求按宽填充,即横屏时充满,主动设置模式为-1即可
138
248
  if (type === 'landscape' && landscapeMode === 'fill') {
139
- // instance.IPCPlayerInstance.setObjectFit({
140
- // objectFit: 'fillCrop',
141
- // });
142
249
  console.log(scaleMultiple, '===========fill');
143
250
  setScaleMultiple(-1);
144
251
  } else if (type === 'landscape' && landscapeMode === 'standard') {
145
- // instance.IPCPlayerInstance.setObjectFit({
146
- // objectFit: 'contain',
147
- // });
148
- // setTimeout(() => {
149
- // console.log('dsahdjsahjdhsajhdjh==');
150
- // instance.IPCPlayerInstance.setScaleMultiple({
151
- // scaleMultiple: -2,
152
- // });
153
- // }, 3000);
154
252
  console.log(scaleMultiple, '===========landscape');
155
253
  setScaleMultiple(-2);
156
254
  } else {
157
255
  // 竖屏时 将屏幕播放比例设为按宽按高
158
- // console.log(verticalZoomLevel, 'verticalZoomLevel======');
159
- // instance.IPCPlayerInstance.setScaleMultiple({
160
- // scaleMultiple: playerFit === 'contain' ? -1 : -2,
161
- // });
256
+
162
257
  console.log(scaleMultiple, '===========landscape');
163
258
  setScaleMultiple(playerFit === 'contain' ? scaleMultiple === 1 ? -1 : 1 : -2);
164
- // instance.IPCPlayerInstance.setObjectFit({
165
- // objectFit: playerFit === 'contain' ? 'fillCrop' : 'contain',
166
- // });
167
259
  }
168
260
  } catch (err) {
169
261
  console.log(err, 'err');
@@ -200,27 +292,6 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
200
292
  if (!systemInfo.current) {
201
293
  systemInfo.current = getSystemInfoSync();
202
294
  }
203
- const {
204
- topLeftContent,
205
- topRightContent,
206
- bottomLeftContent,
207
- bottomRightContent,
208
- absoluteContent,
209
- screenType,
210
- playState,
211
- resolution,
212
- mute
213
- } = useStore({
214
- topLeftContent: instance.topLeftContent,
215
- topRightContent: instance.topRightContent,
216
- bottomLeftContent: instance.bottomLeftContent,
217
- bottomRightContent: instance.bottomRightContent,
218
- absoluteContent: instance.absoluteContent,
219
- screenType: instance.screenType,
220
- playState: instance.playState,
221
- resolution: instance.resolution,
222
- mute: instance.mute
223
- });
224
295
 
225
296
  // 监听物理返回按键
226
297
  const hackHandle = () => {
@@ -336,7 +407,19 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
336
407
  if (playState !== PlayState.PLAYING) {
337
408
  console.log('非播放状态=======');
338
409
  console.log(currentZoomLevel, 'currentZoomLevel');
339
- setScaleMultiple(currentZoomLevel);
410
+ console.log(scaleMultiple, 'scaleMultiple');
411
+ console.log(hasPlayedRef.current, 'hasPlayedRef.current');
412
+ if (hasPlayedRef.current) {
413
+ setScaleMultiple(currentZoomLevel);
414
+ }
415
+ }
416
+ if (playState === PlayState.PLAYING) {
417
+ // 仅在第一次播放成功时,针对竖屏并且为cover模式时,设置为-2
418
+ console.log('Playing状态');
419
+ if (screenType === 'vertical' && playerFit === 'cover' && !hasPlayedRef.current) {
420
+ setScaleMultiple(-2);
421
+ hasPlayedRef.current = true;
422
+ }
340
423
  }
341
424
  setPlayState(playState);
342
425
  (_props$onPlayStatus = props.onPlayStatus) === null || _props$onPlayStatus === void 0 || _props$onPlayStatus.call(props, {
@@ -397,6 +480,10 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
397
480
  eventRef.current.off(hideAllComponent, listenHideEvent);
398
481
  eventRef.current.off('disablePlayerTap', handDisablePlayerTap);
399
482
  eventRef.current.off('refreshBottomLeft', refreshBottomLeft);
483
+ if (reGetOrientationTimer.current) {
484
+ clearTimeout(reGetOrientationTimer.current);
485
+ reGetOrientationTimer.current = null;
486
+ }
400
487
  };
401
488
  }, []);
402
489
  playState === PlayState.PLAYING;
@@ -427,7 +514,6 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
427
514
  if (scaleMode === -2 && playerFit === 'cover' && screenType === 'vertical' && landscapeMode === 'standard') {
428
515
  console.log('dsadsadsad----', zoomLevel);
429
516
  setScaleMultiple(zoomLevel);
430
- // setVerticalCoverZoom(zoomLevel);
431
517
  }
432
518
  /**
433
519
  * 针对竖屏为contain模式时,横屏为fill模式时,主动设置缩放比例,避免因值不能正常变化
@@ -446,14 +532,6 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
446
532
  setVerticalCoverZoom(zoomLevel);
447
533
  setScaleMultiple(zoomLevel);
448
534
  }
449
-
450
- // if (screenType === 'vertical' && scaleMode === -1) {
451
- // console.log('dsadsadsad----');
452
- // // setVerticalCoverZoom(zoomLevel);
453
- // setScaleMultiple(zoomLevel);
454
- // }
455
- console.log(data === null || data === void 0 ? void 0 : data.detail, 'data?.detail');
456
- console.log(zoomLevel, 'zoomLevel======');
457
535
  setCurrentZoomLevel(zoomLevel);
458
536
  return false;
459
537
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.19",
3
+ "version": "0.0.20-beta-1",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -38,7 +38,7 @@
38
38
  "@ray-js/ipc-ptz-zoom": "^0.0.2",
39
39
  "@ray-js/panel-sdk": "^1.13.1",
40
40
  "@ray-js/direction-control": "^0.0.8",
41
- "@ray-js/ray-ipc-player": "^2.0.25",
41
+ "@ray-js/ray-ipc-player": "2.0.26",
42
42
  "@ray-js/ray-ipc-utils": "^1.1.10",
43
43
  "@ray-js/svg": "0.2.0",
44
44
  "clsx": "^1.2.1",
@@ -48,7 +48,6 @@
48
48
  "@commitlint/cli": "^7.2.1",
49
49
  "@commitlint/config-conventional": "^9.0.1",
50
50
  "@ray-js/cli": "^1.7.14",
51
- "@ray-js/direction-control": "^0.0.7",
52
51
  "@ray-js/ray": "^1.7.14",
53
52
  "@testing-library/react-hooks": "^8.0.1",
54
53
  "@types/jest": "^29.5.14",