@ray-js/ipc-player-integration 0.0.18-beta-5 → 0.0.18-beta-7

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 (2) hide show
  1. package/lib/ui/ui.js +87 -57
  2. package/package.json +1 -1
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';
@@ -74,6 +74,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
74
74
  } = instance;
75
75
  const prevTriggerEvent = useRef();
76
76
  const hasPlayedRef = useRef(false);
77
+
77
78
  /*
78
79
  player 的UI效果期望有一些控件在初始化的时候都展示,在点击 Player 之后隐藏:
79
80
  在控件显示时,点击播放器期望隐藏控件
@@ -88,6 +89,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
88
89
  }
89
90
  useImperativeHandle(eventRefProp, () => eventRef.current, [eventRef.current]);
90
91
  const timer = useRef();
92
+ const reGetOrientationTimer = useRef(null);
91
93
  const [scaleMultiple, setScaleMultiple] = useState(playerFit === 'contain' ? 1 : -2);
92
94
  const [currentZoomLevel, setCurrentZoomLevel] = useState(playerFit === 'contain' ? 1 : -2);
93
95
  const [createCtx, setCreateCtx] = useState(false);
@@ -95,6 +97,11 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
95
97
  // const [verticalCoverZoom, setVerticalCoverZoom] = useState(-2);
96
98
  // const [verticalZoomLevel, setVerticalZoomLevel] = useState(playerFit === 'contain' ? 1 : -2);
97
99
 
100
+ const getPlayerRoute = () => {
101
+ const pages = getCurrentPages(); // 获取当前页面栈
102
+ const currentPage = pages[pages.length - 1]; // 获取当前页面实例
103
+ return currentPage.route;
104
+ };
98
105
  const {
99
106
  topLeftContent,
100
107
  topRightContent,
@@ -116,44 +123,59 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
116
123
  resolution: instance.resolution,
117
124
  mute: instance.mute
118
125
  });
119
- useEffect(() => {
120
- // 首次进来强制为竖屏
121
- if (createCtx) {
122
- // 获取屏幕方向比例
123
- try {
124
- var _ty;
125
- if (typeof ((_ty = ty) === null || _ty === void 0 ? void 0 : _ty.getOrientationSync) === 'function') {
126
+ const getAndSetOrientation = () => {
127
+ try {
128
+ var _ty;
129
+ if (typeof ((_ty = ty) === null || _ty === void 0 ? void 0 : _ty.getOrientationSync) === 'function') {
130
+ const {
131
+ orientation
132
+ } = ty.getOrientationSync();
133
+ console.log(`同步获取屏幕方向: ${orientation}`);
134
+ ipcTTTOperatorLog(`同步获取屏幕方向: ${orientation}`);
135
+ if (orientation === 'unknown') {
136
+ // 1秒后重试一次
137
+ reGetOrientationTimer.current = setTimeout(getAndSetOrientation, 500);
138
+ return;
139
+ }
140
+ if (['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right', 'landscape'].includes(orientation)) {
126
141
  const {
127
- orientation
128
- } = ty.getOrientationSync();
129
- console.log(`同步获取屏幕方向: ${orientation}`);
130
- ipcTTTOperatorLog(`同步获取屏幕方向: ${orientation}`);
131
- if (['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right', 'landscape'].includes(orientation)) {
132
- const {
133
- deviceType
134
- } = systemInfo.current;
135
- if (deviceType === 'pad') {
136
- setScreenType('vertical');
137
- return;
138
- }
139
- const pageOrientation = orientation === 'landscape-left' || orientation === 'landscape-right' || orientation === 'landscape' ? 'landscape' : 'portrait';
142
+ deviceType
143
+ } = systemInfo.current;
144
+ if (deviceType === 'pad') {
145
+ setScreenType('vertical');
146
+ return;
147
+ }
148
+ const pageOrientation = orientation === 'landscape-left' || orientation === 'landscape-right' || orientation === 'landscape' ? 'landscape' : 'portrait';
149
+ if (pageOrientation === 'landscape') {
150
+ // 如果为横屏的情况下,直接设置为全屏
140
151
  setScreenType(pageOrientation === 'landscape' ? 'full' : 'vertical');
141
- // 强制更改页面转向
142
- setPageOrientation({
143
- pageOrientation,
144
- success: () => {
145
- console.log('success');
146
- },
147
- fail: err => {
148
- console.log('err', err);
149
- }
150
- });
151
152
  }
153
+
154
+ // setPageOrientation({
155
+ // pageOrientation,
156
+ // success: () => {
157
+ // console.log('success');
158
+ // },
159
+ // fail: err => {
160
+ // console.log('err', err);
161
+ // },
162
+ // });
152
163
  }
153
- } catch (e) {
154
- console.log('获取屏幕方向失败');
155
164
  }
165
+ } catch (e) {
166
+ console.log('获取屏幕方向失败');
167
+ }
168
+ };
169
+ useEffect(() => {
170
+ // 首次进来强制为竖屏
171
+ if (createCtx) {
172
+ getAndSetOrientation();
156
173
  }
174
+ return () => {
175
+ if (reGetOrientationTimer.current) {
176
+ clearTimeout(reGetOrientationTimer.current);
177
+ }
178
+ };
157
179
  }, [createCtx]);
158
180
  useEffect(() => {
159
181
  var _ty2;
@@ -189,35 +211,39 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
189
211
 
190
212
  const handleOrientationChange = useMemoizedFn(data => {
191
213
  console.log(data, 'data=====');
214
+ console.log(getPlayerRoute(), 'getPlayerRoute()');
215
+ if (getPlayerRoute() !== 'pages/home/index') {
216
+ // 不是首页的话,禁止以下行为
217
+ return;
218
+ }
192
219
  const {
193
220
  orientation
194
221
  } = data;
195
222
  if (['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right'].includes(orientation)) {
196
223
  setScreenType(orientation === 'landscape-left' || orientation === 'landscape-right' ? 'full' : 'vertical');
197
224
  const pageOrientation = orientation === 'landscape-left' || orientation === 'landscape-right' ? 'landscape' : 'portrait';
198
- const {
199
- deviceType
200
- } = systemInfo.current;
201
- // 针对pad 暂不支持横屏,且在ios pad模式下 会触发onResize事件, 待解决
202
- if (deviceType === 'pad') {
203
- setScreenType('vertical');
204
- } else {
205
- setScreenType(pageOrientation === 'landscape' ? 'full' : 'vertical');
206
- triggerEvent(showAllComponent);
207
- }
208
- // 若为全屏模式并且要求按宽填充,即横屏时充满,主动设置模式为-1即可
209
- if (pageOrientation === 'landscape' && landscapeMode === 'fill') {
210
- console.log(scaleMultiple, '===========fill');
211
- setScaleMultiple(-1);
212
- } else if (pageOrientation === 'landscape' && landscapeMode === 'standard') {
213
- console.log(scaleMultiple, '===========landscape');
214
- setScaleMultiple(-2);
215
- } else {
216
- // 竖屏时 将屏幕播放比例设为按宽按高
217
225
 
218
- console.log(scaleMultiple, '===========landscape');
219
- setScaleMultiple(playerFit === 'contain' ? scaleMultiple === 1 ? -1 : 1 : -2);
220
- }
226
+ // const { deviceType } = systemInfo.current;
227
+ // // 针对pad 暂不支持横屏,且在ios pad模式下 会触发onResize事件, 待解决
228
+ // if (deviceType === 'pad') {
229
+ // setScreenType('vertical');
230
+ // } else {
231
+ // setScreenType(pageOrientation === 'landscape' ? 'full' : 'vertical');
232
+ // triggerEvent(showAllComponent);
233
+ // }
234
+ // // 若为全屏模式并且要求按宽填充,即横屏时充满,主动设置模式为-1即可
235
+ // if (pageOrientation === 'landscape' && landscapeMode === 'fill') {
236
+ // console.log(scaleMultiple, '===========fill');
237
+ // setScaleMultiple(-1);
238
+ // } else if (pageOrientation === 'landscape' && landscapeMode === 'standard') {
239
+ // console.log(scaleMultiple, '===========landscape');
240
+ // setScaleMultiple(-2);
241
+ // } else {
242
+ // // 竖屏时 将屏幕播放比例设为按宽按高
243
+
244
+ // console.log(scaleMultiple, '===========landscape');
245
+ // setScaleMultiple(playerFit === 'contain' ? (scaleMultiple === 1 ? -1 : 1) : -2);
246
+ // }
221
247
  // 强制更改页面转向
222
248
  setPageOrientation({
223
249
  pageOrientation,
@@ -235,8 +261,12 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
235
261
  * 监听屏幕布局变化
236
262
  */
237
263
  usePageEvent('onResize', useMemoizedFn(sizeData => {
238
- var _ty4;
239
- if (typeof ((_ty4 = ty) === null || _ty4 === void 0 ? void 0 : _ty4.onOrientationChange) === 'function') {
264
+ // if (typeof ty?.onOrientationChange === 'function') {
265
+ // return;
266
+ // }
267
+ console.log(getPlayerRoute(), 'getPlayerRoute()');
268
+ if (getPlayerRoute() !== 'pages/home/index') {
269
+ // 不是Player首页的话,禁止以下行为
240
270
  return;
241
271
  }
242
272
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.18-beta-5",
3
+ "version": "0.0.18-beta-7",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [