@ray-js/ray-ipc-player 2.0.25 → 2.0.26-beta-2

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { IProps } from './typings';
3
+ import './index.less';
3
4
  declare const Player: (props: IProps) => JSX.Element;
4
5
  export default Player;
package/lib/index.js CHANGED
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import "core-js/modules/es.json.stringify.js";
3
3
  import "core-js/modules/web.dom-collections.iterator.js";
4
4
  /* eslint-disable no-unneeded-ternary */
5
- import React, { useState, useEffect, useRef, useCallback } from 'react';
5
+ import React, { useState, useEffect, useRef } from 'react';
6
6
  import { useImmer } from 'use-immer';
7
7
  import _isEmpty from 'lodash/isEmpty';
8
8
  import { IpcPlayer, View, CoverView } from '@ray-js/components';
@@ -10,12 +10,16 @@ import { useMount, useUnmount, useMemoizedFn } from 'ahooks';
10
10
  import { setPageOrientation, usePageEvent, getNetworkType, offNetworkStatusChange, onNetworkStatusChange, publishDps, showToast, getSystemInfoSync, onMqttMessageReceived, registerMQTTProtocolListener, offMqttMessageReceived, unregisterMQTTProtocolListener, registerDeviceListListener, onDpDataChange, onDeviceOnlineStatusUpdate, performanceEvent } from '@ray-js/ray';
11
11
  import clsx from 'clsx';
12
12
  import Strings from './i18n';
13
- import Styles from './index.module.less';
14
13
  import { IpcFailCode } from './constant';
15
14
  import { useWakeUpDevice } from './hooks';
16
15
  import { getIsConnected, getIsOnPreview, openTargetMinByShortLink, getLanguage, getHomeInfo, getDeviceInfo, getDpIdByDpCode, ipcTTTOperatorLog } from './utils';
17
16
  import { getErrCodeDetailDataByCode, codeCoverToInt } from './config/errCodeConfig';
18
17
  import { deviceFreezeReasonStore, miniIdLabs } from './config';
18
+ import './index.less';
19
+ const CSS_PREFIX = 'ray-ipc-player';
20
+
21
+ // 生成带前缀的类名
22
+ const getClassName = className => "".concat(CSS_PREFIX, "-").concat(className);
19
23
  const Player = props => {
20
24
  const {
21
25
  updateLayout = '',
@@ -118,13 +122,13 @@ const Player = props => {
118
122
  const retryCount = useRef(0); // 重试次数
119
123
  const muteRef = useRef(defaultMute); // 静音
120
124
 
121
- usePageEvent('onShow', useCallback(async () => {
125
+ usePageEvent('onShow', useMemoizedFn(async () => {
122
126
  // 视图准备就绪
123
127
  if (phoneNetworkConnect && playState.initLy && ipcCtx.current && onlineStatus && !privateState) {
124
128
  ipcTTTOperatorLog('VID: onShow_event_to_retry');
125
129
  retry();
126
130
  }
127
- }, [phoneNetworkConnect, onlineStatus && playState.connectState, privateState, playState.initLy]));
131
+ }));
128
132
  usePageEvent('onShow', () => {
129
133
  getNetworkType({
130
134
  success: res => {
@@ -188,6 +192,7 @@ const Player = props => {
188
192
  }));
189
193
  useMount(() => {
190
194
  onNetworkStatusChange(res => {
195
+ console.log(res, 'res==========onNetworkStatusChange');
191
196
  setPhoneNetworkConnect(res.isConnected);
192
197
  if (!res.isConnected) {
193
198
  // 断网,需要主动调用断流以及断开P2P
@@ -330,6 +335,7 @@ const Player = props => {
330
335
  d.errorMsg = Strings.getLang('ipc_player_device_offline');
331
336
  });
332
337
  } else if (playState.initLy && !privateState) {
338
+ console.log('sdhjsahdjshajdh');
333
339
  ipcTTTOperatorLog("VID: privateState_status_change: ".concat(privateState));
334
340
  retry();
335
341
  } else if (playState.initLy && privateState) {
@@ -342,8 +348,11 @@ const Player = props => {
342
348
 
343
349
  // 重试
344
350
  const _retry = async () => {
351
+ console.log('调用了重试');
345
352
  const connectState = await getIsConnected(ipcCtx.current);
353
+ console.log('调用了重试--connectState');
346
354
  const isOnPreview = await getIsOnPreview(ipcCtx.current);
355
+ console.log('调用了重试--isOnPreview');
347
356
  setPlayState(d => {
348
357
  d.connectState = connectState ? true : false;
349
358
  d.errorMsg = '';
@@ -455,8 +464,7 @@ const Player = props => {
455
464
  }, 15000);
456
465
  }
457
466
  });
458
- const retry = useCallback(() => {
459
- // console.log('retry:', muteRef.current);
467
+ const retry = useMemoizedFn(() => {
460
468
  console.log('重新拉流启动');
461
469
  // 任何重试拉流时, 将播放器状态还原为loading状态
462
470
  setVideoErrCode('');
@@ -470,7 +478,8 @@ const Player = props => {
470
478
  // 低功耗设备隐私模式需单独处理,先进行下发唤醒, 唤醒后再进行下发DP
471
479
  phoneNetworkConnect && onlineStatus && privateState && isLowPowerDevice && !isVirtualDevice && handleReWakeCameraLowPowerDevice();
472
480
  phoneNetworkConnect && onlineStatus && !privateState && _retry();
473
- }, [isLowPowerDevice, phoneNetworkConnect && playState.connectState, privateState, onlineStatus]);
481
+ // }, [isLowPowerDevice, phoneNetworkConnect && playState.connectState, privateState, onlineStatus]);
482
+ });
474
483
 
475
484
  // 创建ipc实例
476
485
  const createIpcCtx = () => {
@@ -625,7 +634,7 @@ const Player = props => {
625
634
  */
626
635
 
627
636
  // 异常事件
628
- const onError = useCallback(e => {
637
+ const onError = useMemoizedFn(e => {
629
638
  ipcTTTOperatorLog("VID: player_event_on_error: ".concat(JSON.stringify(e)));
630
639
  if (playState.errorState) {
631
640
  return;
@@ -644,7 +653,7 @@ const Player = props => {
644
653
  d.connectState = false;
645
654
  });
646
655
  }
647
- }, [playState.errorState]);
656
+ });
648
657
 
649
658
  // 连接状态发生变化
650
659
  const connectChange = useMemoizedFn(e => {
@@ -717,14 +726,14 @@ const Player = props => {
717
726
  /**
718
727
  * 播放器画面点击事件
719
728
  */
720
- const handleVideoTap = useCallback(() => {
729
+ const handleVideoTap = useMemoizedFn(() => {
721
730
  if (!playState.loadingState && !playState.errorState && onlineStatus && !privateState) {
722
731
  ipcTTTOperatorLog('VID: onVideoTap_event_send');
723
732
  onPlayerTap && onPlayerTap(devId);
724
733
  } else {
725
734
  ipcTTTOperatorLog('VID: onVideoTap_event_trigger_not_send');
726
735
  }
727
- }, [onPlayerTap, playState.loadingState, playState.errorState, onlineStatus, privateState]);
736
+ });
728
737
 
729
738
  /**
730
739
  * 退出横屏
@@ -757,7 +766,7 @@ const Player = props => {
757
766
  /**
758
767
  * 获取错误展示内容
759
768
  */
760
- const getErrorContent = useCallback(() => {
769
+ const getErrorContent = useMemoizedFn(() => {
761
770
  if (!phoneNetworkConnect) {
762
771
  return Strings.getLang('ipc_player_network_fail');
763
772
  }
@@ -801,12 +810,12 @@ const Player = props => {
801
810
  return "".concat(Strings.getLang("ipc_player_error_common"), "(").concat(videoErrCode, ")");
802
811
  }
803
812
  return playState.errorMsg;
804
- }, [phoneNetworkConnect, playState, videoErrCode, privateState, onlineStatus, isLowPowerDevice, lowPowerDeviceOnlineState, device4GIsFreeze, deviceFreezeReason, lowPrivateOutTimeFlag]);
813
+ });
805
814
 
806
815
  /**
807
816
  * 根据自定义类型获取错误码展示内容
808
817
  */
809
- const getErrorContentByType = useCallback((errCode, type) => {
818
+ const getErrorContentByType = useMemoizedFn((errCode, type) => {
810
819
  const errContent = getErrCodeDetailDataByCode(String(errCode));
811
820
  const contentEmpty = _isEmpty(errContent);
812
821
  switch (type) {
@@ -893,12 +902,12 @@ const Player = props => {
893
902
  default:
894
903
  return false;
895
904
  }
896
- }, [phoneNetworkConnect, privateState, onlineStatus, isLowPowerDevice, lowPowerDeviceOnlineState, device4GIsFreeze, deviceFreezeReason]);
905
+ });
897
906
 
898
907
  /**
899
908
  * 跳转帮助小程序
900
909
  */
901
- const handleGotoHelpMini = useCallback(async () => {
910
+ const handleGotoHelpMini = useMemoizedFn(async () => {
902
911
  if (isLowPowerDevice && !lowPowerDeviceOnlineState || !onlineStatus) {
903
912
  const realLanguage = await getLanguage();
904
913
  const url = "godzilla://".concat(miniIdLabs.helpMini, "/pages/commonDetails/index?answer=/app-helpcenter/").concat(realLanguage, "/K94ow0gwu9bg2");
@@ -912,19 +921,19 @@ const Player = props => {
912
921
  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);
913
922
  openTargetMinByShortLink(url);
914
923
  return false;
915
- }, [onlineStatus, isLowPowerDevice, lowPowerDeviceOnlineState]);
924
+ });
916
925
 
917
926
  /**
918
927
  * 跳转反馈小程序
919
928
  */
920
929
 
921
930
  return /*#__PURE__*/React.createElement(View, {
922
- className: Styles.ipc_player,
931
+ className: getClassName('ipc-player'),
923
932
  onClick: () => {
924
933
  onPlayerContainerTap && onPlayerContainerTap(devId);
925
934
  }
926
935
  }, /*#__PURE__*/React.createElement(IpcPlayer, _extends({
927
- className: "".concat(Styles.player, " ").concat(playState.updateLy),
936
+ className: "".concat(getClassName('player'), " ").concat(playState.updateLy),
928
937
  objectFit: objectFit,
929
938
  onVideoTap: handleVideoTap,
930
939
  onZoomChange: onZoomChange,
@@ -958,51 +967,51 @@ const Player = props => {
958
967
  style: {
959
968
  borderRadius: "".concat(borderRadius)
960
969
  },
961
- className: clsx(Styles.load_box, Styles.bg_center, !playState.loadingState && Styles.hide),
970
+ className: clsx(getClassName('load-box'), getClassName('bg-center'), !playState.loadingState && getClassName('hide')),
962
971
  onClick: () => {
963
972
  return false;
964
973
  }
965
974
  }, /*#__PURE__*/React.createElement(View, {
966
- className: Styles.load_icon
975
+ className: getClassName('load-icon')
967
976
  }), /*#__PURE__*/React.createElement(View, {
968
- className: Styles.load_des
977
+ className: getClassName('load-des')
969
978
  }, loadText || playState.loadingText || Strings.getLang('ipc_player_get_video_stream'))), /*#__PURE__*/React.createElement(CoverView, {
970
979
  style: {
971
980
  borderRadius: "".concat(borderRadius)
972
981
  },
973
- className: clsx(Styles.bg_center, Styles.errorContainer, !playState.errorState && Styles.hide),
982
+ className: clsx(getClassName('bg-center'), getClassName('error-container'), !playState.errorState && getClassName('hide')),
974
983
  onClick: () => {
975
984
  return false;
976
985
  }
977
986
  }, /*#__PURE__*/React.createElement(View, {
978
- className: clsx(Styles.errIconContainer)
987
+ className: clsx(getClassName('err-icon-container'))
979
988
  }, renderErrIcon ? renderErrIcon() : /*#__PURE__*/React.createElement(View, {
980
- className: clsx(Styles.errIcon)
989
+ className: clsx(getClassName('err-icon'))
981
990
  })), /*#__PURE__*/React.createElement(View, {
982
- className: clsx(Styles.errTextContainer)
991
+ className: clsx(getClassName('err-text-container'))
983
992
  }, /*#__PURE__*/React.createElement(View, {
984
- className: clsx(Styles.errContent)
993
+ className: clsx(getClassName('err-content'))
985
994
  }, getErrorContent()), getErrorContentByType(videoErrCode, 'suggestedFlag') && /*#__PURE__*/React.createElement(View, {
986
- className: clsx(Styles.errDesc)
995
+ className: clsx(getClassName('err-desc'))
987
996
  }, getErrorContentByType(videoErrCode, 'suggestedText'))), /*#__PURE__*/React.createElement(View, {
988
- className: clsx(Styles.errOperatorContainer)
997
+ className: clsx(getClassName('err-operator-container'))
989
998
  }, getErrorContentByType(videoErrCode, 'retry') && /*#__PURE__*/React.createElement(View, {
990
- className: clsx(Styles.operatorBtn, Styles.operatorRetry),
999
+ className: clsx(getClassName('operator-btn'), getClassName('operator-retry')),
991
1000
  style: {
992
1001
  backgroundColor: "".concat(brandColor)
993
1002
  },
994
1003
  onClick: retry
995
1004
  }, getErrorContentByType(videoErrCode, 'retryText')), getErrorContentByType(videoErrCode, 'help') && /*#__PURE__*/React.createElement(View, {
996
- className: clsx(Styles.operatorBtn, Styles.operatorHelp),
1005
+ className: clsx(getClassName('operator-btn'), getClassName('operator-help')),
997
1006
  onClick: handleGotoHelpMini
998
1007
  }, Strings.getLang('ipc_player_help')), getErrorContentByType(videoErrCode, 'feedBack') && /*#__PURE__*/React.createElement(View, {
999
- className: clsx(Styles.operatorBtn, Styles.operatorFeedBack),
1008
+ className: clsx(getClassName('operator-btn'), getClassName('operator-feedback')),
1000
1009
  onClick: () => {
1001
1010
  const url = "godzilla://".concat(miniIdLabs.helpMini, "/pages/v2/problemSubmit/index");
1002
1011
  openTargetMinByShortLink(url);
1003
1012
  }
1004
1013
  }, Strings.getLang('ipc_player_feedback')))), screenType === 'landscape' && (playState.loadingState || playState.errorState) && /*#__PURE__*/React.createElement(CoverView, {
1005
- className: clsx(Styles.load_full_back_container),
1014
+ className: clsx(getClassName('load-full-back-container')),
1006
1015
  onClick: () => {
1007
1016
  setScreenType('portrait');
1008
1017
  setPageOrientation({
@@ -1,21 +1,23 @@
1
- .player {
1
+ @prefix: ray-ipc-player;
2
+
3
+ .@{prefix}-player {
2
4
  width: 100%;
3
5
  height: 100%;
4
6
  }
5
7
 
6
- .ipc_player {
8
+ .@{prefix}-ipc-player {
7
9
  width: 100%;
8
10
  height: 100%;
9
11
  position: relative;
10
12
  }
11
13
 
12
- .load_box {
14
+ .@{prefix}-load-box {
13
15
  color: #ffffff;
14
- font-size: 0.3rem;
16
+ font-size: 24px;
15
17
  z-index: 350;
16
18
  }
17
19
 
18
- .bg_center {
20
+ .@{prefix}-bg-center {
19
21
  position: absolute;
20
22
  top: 0;
21
23
  width: 100%;
@@ -36,10 +38,10 @@
36
38
  --video-bg: #0d0d0d;
37
39
  }
38
40
 
39
- .load_icon {
41
+ .@{prefix}-load-icon {
40
42
  display: block;
41
- height: 0.38rem;
42
- width: 0.38rem;
43
+ height: 20px;
44
+ width: 20px;
43
45
  vertical-align: middle;
44
46
  animation: spin 1s linear 0s infinite;
45
47
  background: #ffffff;
@@ -48,8 +50,9 @@
48
50
  -webkit-mask-repeat: no-repeat;
49
51
  }
50
52
 
51
- .load_des {
52
- margin-top: 0.34rem;
53
+ .@{prefix}-load-des {
54
+ margin-top: 16px;
55
+ font-size: 14px;
53
56
  }
54
57
 
55
58
  @keyframes spin {
@@ -61,7 +64,7 @@
61
64
  }
62
65
  }
63
66
 
64
- .hide {
67
+ .@{prefix}-hide {
65
68
  display: none !important;
66
69
  }
67
70
 
@@ -76,11 +79,11 @@
76
79
 
77
80
  .iconfont {
78
81
  font-family: 'iconfont' !important;
79
- font-size: 0.44rem;
82
+ font-size: 30px;
80
83
  font-style: normal;
81
84
  -webkit-font-smoothing: antialiased;
82
85
  -moz-osx-font-smoothing: grayscale;
83
- margin-bottom: 0.3rem;
86
+ margin-bottom: 10px;
84
87
  }
85
88
 
86
89
  .icon_tishi:before {
@@ -88,56 +91,56 @@
88
91
  color: #fff;
89
92
  }
90
93
 
91
- .msg {
94
+ .@{prefix}-msg {
92
95
  width: 100%;
93
96
  }
94
97
 
95
- .msg,
96
- .retry,
97
- .device_sleep,
98
- .re_wake_camera {
99
- font-size: 0.25rem;
98
+ .@{prefix}-msg,
99
+ .@{prefix}-retry,
100
+ .@{prefix}-device-sleep,
101
+ .@{prefix}-re-wake-camera {
102
+ font-size: 12px;
100
103
  display: inline-block;
101
104
  color: #fff;
102
105
  }
103
106
 
104
- .retry,
105
- .re_wake_camera {
107
+ .@{prefix}-retry,
108
+ .@{prefix}-re-wake-camera {
106
109
  color: #5583f5;
107
110
  }
108
111
 
109
- .retry {
112
+ .@{prefix}-retry {
110
113
  display: block;
111
114
  }
112
115
 
113
- .err_container {
116
+ .@{prefix}-err-container {
114
117
  width: 100%;
115
118
  text-align: center;
116
119
  padding: 0 30px;
117
120
  }
118
121
 
119
- .device_sleep,
120
- .re_wake_camera {
122
+ .@{prefix}-device-sleep,
123
+ .@{prefix}-re-wake-camera {
121
124
  width: 100%;
122
125
  }
123
126
 
124
- .re_wake_camera {
125
- margin-top: 0.05rem;
127
+ .@{prefix}-re-wake-camera {
128
+ margin-top: 2px;
126
129
  text-decoration: underline;
127
130
  }
128
131
 
129
- .ellipsis {
132
+ .@{prefix}-ellipsis {
130
133
  white-space: nowrap;
131
134
  overflow: hidden;
132
135
  text-overflow: ellipsis;
133
136
  }
134
137
 
135
- .err_msg {
138
+ .@{prefix}-err-msg {
136
139
  text-align: center;
137
140
  width: 100%;
138
141
  }
139
142
 
140
- .load_full_back_container {
143
+ .@{prefix}-load-full-back-container {
141
144
  position: absolute;
142
145
  left: 25px;
143
146
  top: 16px;
@@ -150,13 +153,13 @@
150
153
  -webkit-mask-repeat: no-repeat;
151
154
  }
152
155
 
153
- .errorContainer {
156
+ .@{prefix}-error-container {
154
157
  text-align: center;
155
158
  font-size: 12px;
156
159
  padding: 0 16px;
157
160
 
158
- .errIconContainer {
159
- .errIcon {
161
+ .@{prefix}-err-icon-container {
162
+ .@{prefix}-err-icon {
160
163
  background-image: url('./svg/errIcon.svg');
161
164
  width: 38px;
162
165
  height: 38px;
@@ -173,13 +176,13 @@
173
176
  }
174
177
  }
175
178
 
176
- .errTextContainer {
177
- .errContent {
179
+ .@{prefix}-err-text-container {
180
+ .@{prefix}-err-content {
178
181
  color: #ffffff;
179
182
  font-size: 12px;
180
183
  font-weight: 400;
181
184
  }
182
- .errDesc {
185
+ .@{prefix}-err-desc {
183
186
  margin-top: 5px;
184
187
  color: rgba(255, 255, 255, 0.7);
185
188
  font-size: 12px;
@@ -187,12 +190,12 @@
187
190
  }
188
191
  }
189
192
 
190
- .errOperatorContainer {
193
+ .@{prefix}-err-operator-container {
191
194
  display: flex;
192
195
  flex-direction: row;
193
196
  flex-wrap: wrap;
194
197
  margin-top: 15px;
195
- .operatorBtn {
198
+ .@{prefix}-operator-btn {
196
199
  font-size: 14px;
197
200
  font-weight: 400;
198
201
  min-height: 36px;
@@ -209,30 +212,30 @@
209
212
  text-overflow: ellipsis;
210
213
  padding: 8px 16px;
211
214
  }
212
- .operatorBtn:hover {
215
+ .@{prefix}-operator-btn:hover {
213
216
  opacity: 0.9;
214
217
  }
215
- .operatorBtn:active {
218
+ .@{prefix}-operator-btn:active {
216
219
  opacity: 1;
217
220
  }
218
- .operatorBtn:first-of-type {
221
+ .@{prefix}-operator-btn:first-of-type {
219
222
  margin-right: 4px;
220
223
  margin-left: 0;
221
224
  }
222
- .operatorBtn:last-of-type {
225
+ .@{prefix}-operator-btn:last-of-type {
223
226
  margin-left: 4px;
224
227
  margin-right: 0;
225
228
  }
226
- .operatorBtn:only-of-type {
229
+ .@{prefix}-operator-btn:only-of-type {
227
230
  margin: 0;
228
231
  }
229
- .operatorRetry {
232
+ .@{prefix}-operator-retry {
230
233
  background-color: #ff592a;
231
234
  }
232
- .operatorHelp {
235
+ .@{prefix}-operator-help {
233
236
  background-color: #252525;
234
237
  }
235
- .operatorFeedBack {
238
+ .@{prefix}-operator-feedback {
236
239
  background-color: #252525;
237
240
  }
238
241
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ray-ipc-player",
3
- "version": "2.0.25",
3
+ "version": "2.0.26-beta-2",
4
4
  "description": "ray小程序播放器",
5
5
  "keywords": [
6
6
  "tuya-miniapp",