@ray-js/ipc-player-integration 0.0.18-beta-4 → 0.0.18-beta-6

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 +78 -64
  2. package/package.json +1 -1
package/lib/ui/ui.js CHANGED
@@ -88,6 +88,7 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
88
88
  }
89
89
  useImperativeHandle(eventRefProp, () => eventRef.current, [eventRef.current]);
90
90
  const timer = useRef();
91
+ const reGetOrientationTimer = useRef(null);
91
92
  const [scaleMultiple, setScaleMultiple] = useState(playerFit === 'contain' ? 1 : -2);
92
93
  const [currentZoomLevel, setCurrentZoomLevel] = useState(playerFit === 'contain' ? 1 : -2);
93
94
  const [createCtx, setCreateCtx] = useState(false);
@@ -116,44 +117,59 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
116
117
  resolution: instance.resolution,
117
118
  mute: instance.mute
118
119
  });
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') {
120
+ const getAndSetOrientation = () => {
121
+ try {
122
+ var _ty;
123
+ if (typeof ((_ty = ty) === null || _ty === void 0 ? void 0 : _ty.getOrientationSync) === 'function') {
124
+ const {
125
+ orientation
126
+ } = ty.getOrientationSync();
127
+ console.log(`同步获取屏幕方向: ${orientation}`);
128
+ ipcTTTOperatorLog(`同步获取屏幕方向: ${orientation}`);
129
+ if (orientation === 'unknown') {
130
+ // 1秒后重试一次
131
+ reGetOrientationTimer.current = setTimeout(getAndSetOrientation, 500);
132
+ return;
133
+ }
134
+ if (['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right', 'landscape'].includes(orientation)) {
126
135
  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';
136
+ deviceType
137
+ } = systemInfo.current;
138
+ if (deviceType === 'pad') {
139
+ setScreenType('vertical');
140
+ return;
141
+ }
142
+ const pageOrientation = orientation === 'landscape-left' || orientation === 'landscape-right' || orientation === 'landscape' ? 'landscape' : 'portrait';
143
+ if (pageOrientation === 'landscape') {
144
+ // 如果为横屏的情况下,直接设置为全屏
140
145
  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
146
  }
147
+
148
+ // setPageOrientation({
149
+ // pageOrientation,
150
+ // success: () => {
151
+ // console.log('success');
152
+ // },
153
+ // fail: err => {
154
+ // console.log('err', err);
155
+ // },
156
+ // });
152
157
  }
153
- } catch (e) {
154
- console.log('获取屏幕方向失败');
155
158
  }
159
+ } catch (e) {
160
+ console.log('获取屏幕方向失败');
156
161
  }
162
+ };
163
+ useEffect(() => {
164
+ // 首次进来强制为竖屏
165
+ if (createCtx) {
166
+ getAndSetOrientation();
167
+ }
168
+ return () => {
169
+ if (reGetOrientationTimer.current) {
170
+ clearTimeout(reGetOrientationTimer.current);
171
+ }
172
+ };
157
173
  }, [createCtx]);
158
174
  useEffect(() => {
159
175
  var _ty2;
@@ -187,23 +203,36 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
187
203
  * 监听播放器实例创建完成
188
204
  */
189
205
 
190
- const handleOrientationChange = data => {
206
+ const handleOrientationChange = useMemoizedFn(data => {
207
+ console.log(data, 'data=====');
191
208
  const {
192
209
  orientation
193
210
  } = data;
194
211
  if (['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right'].includes(orientation)) {
195
- // setScreenType(
196
- // orientation === 'landscape-left' || orientation === 'landscape-right' ? 'full' : 'vertical'
197
- // );
212
+ setScreenType(orientation === 'landscape-left' || orientation === 'landscape-right' ? 'full' : 'vertical');
198
213
  const pageOrientation = orientation === 'landscape-left' || orientation === 'landscape-right' ? 'landscape' : 'portrait';
199
- const {
200
- deviceType
201
- } = systemInfo.current;
202
- // 针对pad 暂不支持横屏,且在ios pad模式下 会触发onResize事件, 待解决
203
- if (deviceType === 'pad') {
204
- setScreenType('vertical');
205
- return;
206
- }
214
+
215
+ // const { deviceType } = systemInfo.current;
216
+ // // 针对pad 暂不支持横屏,且在ios pad模式下 会触发onResize事件, 待解决
217
+ // if (deviceType === 'pad') {
218
+ // setScreenType('vertical');
219
+ // } else {
220
+ // setScreenType(pageOrientation === 'landscape' ? 'full' : 'vertical');
221
+ // triggerEvent(showAllComponent);
222
+ // }
223
+ // // 若为全屏模式并且要求按宽填充,即横屏时充满,主动设置模式为-1即可
224
+ // if (pageOrientation === 'landscape' && landscapeMode === 'fill') {
225
+ // console.log(scaleMultiple, '===========fill');
226
+ // setScaleMultiple(-1);
227
+ // } else if (pageOrientation === 'landscape' && landscapeMode === 'standard') {
228
+ // console.log(scaleMultiple, '===========landscape');
229
+ // setScaleMultiple(-2);
230
+ // } else {
231
+ // // 竖屏时 将屏幕播放比例设为按宽按高
232
+
233
+ // console.log(scaleMultiple, '===========landscape');
234
+ // setScaleMultiple(playerFit === 'contain' ? (scaleMultiple === 1 ? -1 : 1) : -2);
235
+ // }
207
236
  // 强制更改页面转向
208
237
  setPageOrientation({
209
238
  pageOrientation,
@@ -215,12 +244,15 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
215
244
  }
216
245
  });
217
246
  }
218
- };
247
+ });
219
248
 
220
249
  /**
221
250
  * 监听屏幕布局变化
222
251
  */
223
252
  usePageEvent('onResize', useMemoizedFn(sizeData => {
253
+ // if (typeof ty?.onOrientationChange === 'function') {
254
+ // return;
255
+ // }
224
256
  try {
225
257
  const {
226
258
  type
@@ -238,34 +270,16 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
238
270
  }
239
271
  // 若为全屏模式并且要求按宽填充,即横屏时充满,主动设置模式为-1即可
240
272
  if (type === 'landscape' && landscapeMode === 'fill') {
241
- // instance.IPCPlayerInstance.setObjectFit({
242
- // objectFit: 'fillCrop',
243
- // });
244
273
  console.log(scaleMultiple, '===========fill');
245
274
  setScaleMultiple(-1);
246
275
  } else if (type === 'landscape' && landscapeMode === 'standard') {
247
- // instance.IPCPlayerInstance.setObjectFit({
248
- // objectFit: 'contain',
249
- // });
250
- // setTimeout(() => {
251
- // console.log('dsahdjsahjdhsajhdjh==');
252
- // instance.IPCPlayerInstance.setScaleMultiple({
253
- // scaleMultiple: -2,
254
- // });
255
- // }, 3000);
256
276
  console.log(scaleMultiple, '===========landscape');
257
277
  setScaleMultiple(-2);
258
278
  } else {
259
279
  // 竖屏时 将屏幕播放比例设为按宽按高
260
- // console.log(verticalZoomLevel, 'verticalZoomLevel======');
261
- // instance.IPCPlayerInstance.setScaleMultiple({
262
- // scaleMultiple: playerFit === 'contain' ? -1 : -2,
263
- // });
280
+
264
281
  console.log(scaleMultiple, '===========landscape');
265
282
  setScaleMultiple(playerFit === 'contain' ? scaleMultiple === 1 ? -1 : 1 : -2);
266
- // instance.IPCPlayerInstance.setObjectFit({
267
- // objectFit: playerFit === 'contain' ? 'fillCrop' : 'contain',
268
- // });
269
283
  }
270
284
  } catch (err) {
271
285
  console.log(err, 'err');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.18-beta-4",
3
+ "version": "0.0.18-beta-6",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [