@ray-js/ray-ipc-player 2.0.18-beta-beta-1 → 2.0.18-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/constant.d.ts +1 -1
- package/lib/constant.js +7 -10
- package/lib/i18n/index.d.ts +100 -1
- package/lib/i18n/index.js +3 -1
- package/lib/i18n/strings.d.ts +14 -1482
- package/lib/i18n/strings.js +30 -1498
- package/lib/index.config.js +4 -4
- package/lib/index.js +207 -360
- package/lib/index.module.less +2 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/utils.js +16 -22
- package/package.json +28 -27
- package/README-zh_CN.md +0 -209
package/lib/index.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import "core-js/modules/es.array.includes.js";
|
|
5
|
-
import "core-js/modules/es.string.includes.js";
|
|
6
|
-
import "core-js/modules/es.object.to-string.js";
|
|
7
|
-
import "core-js/modules/es.promise.js";
|
|
8
|
-
import "core-js/modules/es.array.concat.js";
|
|
9
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
10
|
-
|
|
2
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
11
3
|
/* eslint-disable no-unneeded-ternary */
|
|
12
4
|
import React, { useEffect, useRef, useCallback } from 'react';
|
|
13
5
|
import { useImmer } from 'use-immer';
|
|
@@ -18,58 +10,46 @@ import locals from './i18n';
|
|
|
18
10
|
import Styles from './index.module.less';
|
|
19
11
|
import { IpcFailCode } from './constant';
|
|
20
12
|
import { putDpData, getIsConnected, getIsOnPreview } from './utils';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
borderRadius
|
|
55
|
-
bgColor
|
|
56
|
-
borderStyle
|
|
57
|
-
borderColor
|
|
58
|
-
borderWidth
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
privateState = _props$privateState === void 0 ? false : _props$privateState,
|
|
62
|
-
_props$objectFit = props.objectFit,
|
|
63
|
-
objectFit = _props$objectFit === void 0 ? 'contain' : _props$objectFit,
|
|
64
|
-
_props$extend = props.extend,
|
|
65
|
-
extend = _props$extend === void 0 ? {} : _props$extend;
|
|
66
|
-
var borderRadius = playerStyle.borderRadius,
|
|
67
|
-
bgColor = playerStyle.bgColor,
|
|
68
|
-
borderStyle = playerStyle.borderStyle,
|
|
69
|
-
borderColor = playerStyle.borderColor,
|
|
70
|
-
borderWidth = playerStyle.borderWidth;
|
|
71
|
-
|
|
72
|
-
var _useImmer = useImmer({
|
|
13
|
+
const Player = props => {
|
|
14
|
+
const {
|
|
15
|
+
updateLayout = '',
|
|
16
|
+
devId = '',
|
|
17
|
+
onChangeStreamStatus,
|
|
18
|
+
onPlayerTap,
|
|
19
|
+
onZoomChange,
|
|
20
|
+
onSessionDidDisconnected,
|
|
21
|
+
onCameraPreviewFailure,
|
|
22
|
+
onCameraNotifyWeakNetwork,
|
|
23
|
+
onInitPreview,
|
|
24
|
+
defaultMute = true,
|
|
25
|
+
onlineStatus = true,
|
|
26
|
+
loadText = '',
|
|
27
|
+
rotateZ = 0,
|
|
28
|
+
scalable = true,
|
|
29
|
+
scaleMultiple = 0,
|
|
30
|
+
ptzControllable = true,
|
|
31
|
+
clarity = 'normal',
|
|
32
|
+
ipcPlayerContext,
|
|
33
|
+
onCtx,
|
|
34
|
+
playerStyle = {
|
|
35
|
+
borderRadius: 0,
|
|
36
|
+
bgColor: '#000000',
|
|
37
|
+
borderStyle: 'solid',
|
|
38
|
+
borderColor: '',
|
|
39
|
+
borderWidth: 0
|
|
40
|
+
},
|
|
41
|
+
privateState = false,
|
|
42
|
+
objectFit = 'contain',
|
|
43
|
+
extend = {}
|
|
44
|
+
} = props;
|
|
45
|
+
const {
|
|
46
|
+
borderRadius,
|
|
47
|
+
bgColor,
|
|
48
|
+
borderStyle,
|
|
49
|
+
borderColor,
|
|
50
|
+
borderWidth
|
|
51
|
+
} = playerStyle;
|
|
52
|
+
const [playState, setPlayState] = useImmer({
|
|
73
53
|
connectState: false,
|
|
74
54
|
// 连接状态
|
|
75
55
|
loadingState: false,
|
|
@@ -81,201 +61,127 @@ var Player = function (props) {
|
|
|
81
61
|
updateLy: '',
|
|
82
62
|
deviceOnlineState: true,
|
|
83
63
|
initLy: false
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
playState = _useImmer2[0],
|
|
87
|
-
setPlayState = _useImmer2[1];
|
|
88
|
-
|
|
89
|
-
var ipcCtx = useRef(null); // ipc实例
|
|
90
|
-
|
|
64
|
+
});
|
|
65
|
+
const ipcCtx = useRef(null); // ipc实例
|
|
91
66
|
if (!ipcCtx.current) {
|
|
92
67
|
var _ty;
|
|
93
|
-
|
|
94
68
|
// @ts-ignore
|
|
95
69
|
ipcCtx.current = ipcPlayerContext || ((_ty = ty) === null || _ty === void 0 ? void 0 : _ty.createIpcPlayerContext(devId));
|
|
96
70
|
}
|
|
71
|
+
const retryCount = useRef(0); // 重试次数
|
|
72
|
+
const muteRef = useRef(defaultMute); // 静音
|
|
97
73
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
case "end":
|
|
114
|
-
return _context.stop();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, _callee);
|
|
118
|
-
})), [playState.connectState, privateState, playState.initLy]));
|
|
119
|
-
usePageEvent('onHide', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
120
|
-
return _regeneratorRuntime.wrap(function (_context2) {
|
|
121
|
-
while (1) {
|
|
122
|
-
switch (_context2.prev = _context2.next) {
|
|
123
|
-
case 0:
|
|
124
|
-
setPlayState(function (d) {
|
|
125
|
-
d.loadingState = true;
|
|
126
|
-
}); // 先停流
|
|
127
|
-
|
|
128
|
-
stopPreview();
|
|
129
|
-
_context2.next = 4;
|
|
130
|
-
return getCurMute();
|
|
131
|
-
|
|
132
|
-
case 4:
|
|
133
|
-
case "end":
|
|
134
|
-
return _context2.stop();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}, _callee2);
|
|
138
|
-
})));
|
|
139
|
-
useEffect(function () {
|
|
74
|
+
usePageEvent('onShow', useCallback(async () => {
|
|
75
|
+
// 视图准备就绪
|
|
76
|
+
if (playState.initLy && ipcCtx.current) {
|
|
77
|
+
retry();
|
|
78
|
+
}
|
|
79
|
+
}, [playState.connectState, privateState, playState.initLy]));
|
|
80
|
+
usePageEvent('onHide', async () => {
|
|
81
|
+
setPlayState(d => {
|
|
82
|
+
d.loadingState = true;
|
|
83
|
+
});
|
|
84
|
+
// 先停流
|
|
85
|
+
stopPreview();
|
|
86
|
+
await getCurMute();
|
|
87
|
+
});
|
|
88
|
+
useEffect(() => {
|
|
140
89
|
onlineStatus && createIpcCtx();
|
|
141
|
-
return
|
|
90
|
+
return () => {
|
|
142
91
|
disconnect();
|
|
143
92
|
ipcCtx.current = null;
|
|
144
93
|
};
|
|
145
94
|
}, [devId, onlineStatus]);
|
|
146
|
-
useEffect(
|
|
95
|
+
useEffect(() => {
|
|
147
96
|
muteRef.current = defaultMute;
|
|
148
97
|
}, [defaultMute]);
|
|
149
|
-
useEffect(
|
|
150
|
-
setPlayState(
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
setPlayState(d => {
|
|
151
100
|
d.updateLy = updateLayout;
|
|
152
101
|
});
|
|
153
|
-
}, [updateLayout]);
|
|
102
|
+
}, [updateLayout]);
|
|
154
103
|
|
|
155
|
-
|
|
156
|
-
|
|
104
|
+
// 设备离线、隐私模式
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
setPlayState(d => {
|
|
157
107
|
d.deviceOnlineState = onlineStatus;
|
|
158
108
|
d.errorState = privateState;
|
|
159
109
|
});
|
|
160
|
-
|
|
161
110
|
if (!onlineStatus) {
|
|
162
|
-
setPlayState(
|
|
111
|
+
setPlayState(d => {
|
|
163
112
|
d.errorState = true;
|
|
164
113
|
d.errorMsg = locals.getLang('ipc_player_no_line');
|
|
165
114
|
});
|
|
166
115
|
} else if (playState.initLy && !privateState) {
|
|
167
116
|
retry();
|
|
168
117
|
}
|
|
169
|
-
}, [onlineStatus, playState.initLy, privateState]);
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
case 5:
|
|
187
|
-
isOnPreview = _context3.sent;
|
|
188
|
-
setPlayState(function (d) {
|
|
189
|
-
d.connectState = connectState ? true : false;
|
|
190
|
-
d.errorMsg = '';
|
|
191
|
-
d.errorState = false;
|
|
192
|
-
d.loadingState = isOnPreview ? false : true;
|
|
193
|
-
}); // !prePlayRef.current && connectState && (await disconnect());
|
|
194
|
-
// console.log(connectState, isOnPreview, '当前链接状态和预览状态');
|
|
195
|
-
|
|
196
|
-
ipcCtx.current && createConnect();
|
|
197
|
-
|
|
198
|
-
case 8:
|
|
199
|
-
case "end":
|
|
200
|
-
return _context3.stop();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}, _callee3);
|
|
204
|
-
}));
|
|
205
|
-
|
|
206
|
-
return function () {
|
|
207
|
-
return _ref3.apply(this, arguments);
|
|
208
|
-
};
|
|
209
|
-
}();
|
|
210
|
-
|
|
211
|
-
var retry = useCallback(function () {
|
|
118
|
+
}, [onlineStatus, playState.initLy, privateState]);
|
|
119
|
+
|
|
120
|
+
// 重试
|
|
121
|
+
const _retry = async () => {
|
|
122
|
+
const connectState = await getIsConnected(ipcCtx.current);
|
|
123
|
+
const isOnPreview = await getIsOnPreview(ipcCtx.current);
|
|
124
|
+
setPlayState(d => {
|
|
125
|
+
d.connectState = connectState ? true : false;
|
|
126
|
+
d.errorMsg = '';
|
|
127
|
+
d.errorState = false;
|
|
128
|
+
d.loadingState = isOnPreview ? false : true;
|
|
129
|
+
});
|
|
130
|
+
// !prePlayRef.current && connectState && (await disconnect());
|
|
131
|
+
// console.log(connectState, isOnPreview, '当前链接状态和预览状态');
|
|
132
|
+
ipcCtx.current && createConnect();
|
|
133
|
+
};
|
|
134
|
+
const retry = useCallback(() => {
|
|
212
135
|
// console.log('retry:', muteRef.current);
|
|
213
136
|
!privateState && _retry();
|
|
214
|
-
}, [playState.connectState, privateState]);
|
|
137
|
+
}, [playState.connectState, privateState]);
|
|
215
138
|
|
|
216
|
-
|
|
139
|
+
// 创建ipc实例
|
|
140
|
+
const createIpcCtx = () => {
|
|
217
141
|
onCtx && onCtx({
|
|
218
142
|
ctx: ipcCtx.current,
|
|
219
|
-
retry
|
|
143
|
+
retry
|
|
220
144
|
});
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var createConnect = /*#__PURE__*/function () {
|
|
225
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
|
|
226
|
-
var _ipcCtx$current;
|
|
227
|
-
|
|
228
|
-
return _regeneratorRuntime.wrap(function (_context4) {
|
|
229
|
-
while (1) {
|
|
230
|
-
switch (_context4.prev = _context4.next) {
|
|
231
|
-
case 0:
|
|
232
|
-
// console.log('建立连接前:', devId, Date.now());
|
|
233
|
-
(_ipcCtx$current = ipcCtx.current) === null || _ipcCtx$current === void 0 ? void 0 : _ipcCtx$current.connect({
|
|
234
|
-
success: function success() {
|
|
235
|
-
// console.log('建立连接成功:', devId, Date.now());
|
|
236
|
-
setPlayState(function (d) {
|
|
237
|
-
d.connectState = true;
|
|
238
|
-
d.errorState = false;
|
|
239
|
-
d.errorMsg = '';
|
|
240
|
-
});
|
|
241
|
-
onChangeStreamStatus && onChangeStreamStatus(1001);
|
|
242
|
-
startPreview(params);
|
|
243
|
-
},
|
|
244
|
-
fail: function fail() {
|
|
245
|
-
// console.error('建立连接失败---------:', e, devId, Date.now());
|
|
246
|
-
setPlayState(function (d) {
|
|
247
|
-
d.connectState = false;
|
|
248
|
-
d.errorState = true;
|
|
249
|
-
d.errorMsg = locals.getLang('ipc_player_connect_fail');
|
|
250
|
-
d.loadingState = false;
|
|
251
|
-
});
|
|
252
|
-
onChangeStreamStatus && onChangeStreamStatus(-1001);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
case 1:
|
|
257
|
-
case "end":
|
|
258
|
-
return _context4.stop();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}, _callee4);
|
|
262
|
-
}));
|
|
145
|
+
};
|
|
263
146
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
147
|
+
// 建立连接
|
|
148
|
+
const createConnect = async params => {
|
|
149
|
+
var _ipcCtx$current;
|
|
150
|
+
// console.log('建立连接前:', devId, Date.now());
|
|
151
|
+
(_ipcCtx$current = ipcCtx.current) === null || _ipcCtx$current === void 0 || _ipcCtx$current.connect({
|
|
152
|
+
success: () => {
|
|
153
|
+
// console.log('建立连接成功:', devId, Date.now());
|
|
154
|
+
setPlayState(d => {
|
|
155
|
+
d.connectState = true;
|
|
156
|
+
d.errorState = false;
|
|
157
|
+
d.errorMsg = '';
|
|
158
|
+
});
|
|
159
|
+
onChangeStreamStatus && onChangeStreamStatus(1001);
|
|
160
|
+
startPreview(params);
|
|
161
|
+
},
|
|
162
|
+
fail: () => {
|
|
163
|
+
// console.error('建立连接失败---------:', e, devId, Date.now());
|
|
164
|
+
setPlayState(d => {
|
|
165
|
+
d.connectState = false;
|
|
166
|
+
d.errorState = true;
|
|
167
|
+
d.errorMsg = locals.getLang('ipc_player_connect_fail');
|
|
168
|
+
d.loadingState = false;
|
|
169
|
+
});
|
|
170
|
+
onChangeStreamStatus && onChangeStreamStatus(-1001);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
};
|
|
268
174
|
|
|
175
|
+
// 视图层准备就绪,开始建立连接
|
|
269
176
|
|
|
270
177
|
// 开启预览
|
|
271
|
-
|
|
178
|
+
const startPreview = params => {
|
|
272
179
|
var _ipcCtx$current2;
|
|
273
|
-
|
|
274
180
|
// console.log('开启预览前');
|
|
275
|
-
(_ipcCtx$current2 = ipcCtx.current) === null || _ipcCtx$current2 === void 0
|
|
276
|
-
success:
|
|
181
|
+
(_ipcCtx$current2 = ipcCtx.current) === null || _ipcCtx$current2 === void 0 || _ipcCtx$current2.startPreview({
|
|
182
|
+
success: () => {
|
|
277
183
|
// console.log('开启预览:', devId);
|
|
278
|
-
setPlayState(
|
|
184
|
+
setPlayState(d => {
|
|
279
185
|
d.loadingState = false;
|
|
280
186
|
d.errorState = false;
|
|
281
187
|
d.errorMsg = '';
|
|
@@ -283,149 +189,112 @@ var Player = function (props) {
|
|
|
283
189
|
params && onInitPreview && onInitPreview(devId);
|
|
284
190
|
onChangeStreamStatus && onChangeStreamStatus(1002);
|
|
285
191
|
},
|
|
286
|
-
fail:
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
if (!(!isOnPreview || e !== null && e !== void 0 && e.errorMsg.includes('doing preview'))) {
|
|
300
|
-
_context5.next = 7;
|
|
301
|
-
break;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// 忽略重复预览异常的报错
|
|
305
|
-
setPlayState(function (d) {
|
|
306
|
-
d.loadingState = false;
|
|
307
|
-
d.errorState = false;
|
|
308
|
-
d.errorMsg = '';
|
|
309
|
-
});
|
|
310
|
-
onChangeStreamStatus && onChangeStreamStatus(1002);
|
|
311
|
-
return _context5.abrupt("return");
|
|
312
|
-
|
|
313
|
-
case 7:
|
|
314
|
-
setPlayState(function (d) {
|
|
315
|
-
d.errorState = true;
|
|
316
|
-
d.loadingState = false;
|
|
317
|
-
d.errorMsg = locals.getLang('ipc_player_preview_fail');
|
|
318
|
-
});
|
|
319
|
-
onChangeStreamStatus && onChangeStreamStatus(-1002);
|
|
320
|
-
|
|
321
|
-
case 9:
|
|
322
|
-
case "end":
|
|
323
|
-
return _context5.stop();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}, _callee5);
|
|
327
|
-
}));
|
|
328
|
-
|
|
329
|
-
function fail() {
|
|
330
|
-
return _fail.apply(this, arguments);
|
|
192
|
+
fail: async e => {
|
|
193
|
+
const isOnPreview = await getIsOnPreview(ipcCtx.current);
|
|
194
|
+
// console.error('开启失败:', e, devId, isOnPreview);
|
|
195
|
+
if (!isOnPreview || e !== null && e !== void 0 && e.errorMsg.includes('doing preview')) {
|
|
196
|
+
// 忽略重复预览异常的报错
|
|
197
|
+
setPlayState(d => {
|
|
198
|
+
d.loadingState = false;
|
|
199
|
+
d.errorState = false;
|
|
200
|
+
d.errorMsg = '';
|
|
201
|
+
});
|
|
202
|
+
onChangeStreamStatus && onChangeStreamStatus(1002);
|
|
203
|
+
return;
|
|
331
204
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
205
|
+
setPlayState(d => {
|
|
206
|
+
d.errorState = true;
|
|
207
|
+
d.loadingState = false;
|
|
208
|
+
d.errorMsg = locals.getLang('ipc_player_preview_fail');
|
|
209
|
+
});
|
|
210
|
+
onChangeStreamStatus && onChangeStreamStatus(-1002);
|
|
211
|
+
},
|
|
212
|
+
complete: () => {
|
|
336
213
|
// console.log('startPreview:', muteRef.current);
|
|
337
214
|
setMuted(muteRef.current);
|
|
338
215
|
}
|
|
339
216
|
});
|
|
340
|
-
};
|
|
341
|
-
|
|
217
|
+
};
|
|
342
218
|
|
|
343
|
-
|
|
219
|
+
// 暂停预览
|
|
220
|
+
const stopPreview = () => {
|
|
344
221
|
var _ipcCtx$current3;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
},
|
|
350
|
-
fail: function fail() {
|
|
351
|
-
return null;
|
|
352
|
-
},
|
|
353
|
-
complete: function complete() {
|
|
354
|
-
return setMuted(true);
|
|
355
|
-
}
|
|
222
|
+
(_ipcCtx$current3 = ipcCtx.current) === null || _ipcCtx$current3 === void 0 || _ipcCtx$current3.stopPreview({
|
|
223
|
+
success: () => null,
|
|
224
|
+
fail: () => null,
|
|
225
|
+
complete: () => setMuted(true)
|
|
356
226
|
});
|
|
357
|
-
};
|
|
358
|
-
|
|
227
|
+
};
|
|
359
228
|
|
|
360
|
-
|
|
229
|
+
// 设置静音
|
|
230
|
+
const setMuted = val => {
|
|
361
231
|
var _ipcCtx$current4;
|
|
362
|
-
|
|
363
|
-
(_ipcCtx$current4 = ipcCtx.current) === null || _ipcCtx$current4 === void 0 ? void 0 : _ipcCtx$current4.setMuted({
|
|
232
|
+
(_ipcCtx$current4 = ipcCtx.current) === null || _ipcCtx$current4 === void 0 || _ipcCtx$current4.setMuted({
|
|
364
233
|
mute: val,
|
|
365
|
-
success:
|
|
234
|
+
success: () => {
|
|
235
|
+
// console.log('设置声音成功', val);
|
|
366
236
|
},
|
|
367
|
-
fail:
|
|
237
|
+
fail: () => {
|
|
238
|
+
// console.log('设置声音失败');
|
|
368
239
|
}
|
|
369
240
|
});
|
|
370
|
-
};
|
|
371
|
-
|
|
241
|
+
};
|
|
372
242
|
|
|
373
|
-
|
|
374
|
-
|
|
243
|
+
// 获取当前是否静音
|
|
244
|
+
const getCurMute = () => {
|
|
245
|
+
return new Promise((resolve, reject) => {
|
|
375
246
|
var _ipcCtx$current5;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
success: function success(res) {
|
|
247
|
+
(_ipcCtx$current5 = ipcCtx.current) === null || _ipcCtx$current5 === void 0 || _ipcCtx$current5.isMuted({
|
|
248
|
+
success: res => {
|
|
379
249
|
muteRef.current = res;
|
|
380
250
|
},
|
|
381
|
-
fail:
|
|
382
|
-
reject(e);
|
|
251
|
+
fail: e => {
|
|
252
|
+
reject(e);
|
|
253
|
+
// console.log(e);
|
|
383
254
|
},
|
|
384
|
-
complete:
|
|
255
|
+
complete: d => {
|
|
385
256
|
resolve(d);
|
|
386
257
|
}
|
|
387
258
|
});
|
|
388
259
|
});
|
|
389
|
-
};
|
|
390
|
-
|
|
260
|
+
};
|
|
391
261
|
|
|
392
|
-
|
|
262
|
+
// 异常事件
|
|
263
|
+
const onError = useCallback(e => {
|
|
393
264
|
var _e$detail;
|
|
394
|
-
|
|
395
265
|
if (playState.errorState) {
|
|
396
266
|
return;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
var type = e === null || e === void 0 ? void 0 : (_e$detail = e.detail) === null || _e$detail === void 0 ? void 0 : _e$detail.errCode;
|
|
401
|
-
|
|
267
|
+
}
|
|
268
|
+
// console.error('发生错误:', e);
|
|
269
|
+
const type = e === null || e === void 0 || (_e$detail = e.detail) === null || _e$detail === void 0 ? void 0 : _e$detail.errCode;
|
|
402
270
|
if (IpcFailCode[type]) {
|
|
403
271
|
onChangeStreamStatus && onChangeStreamStatus(type);
|
|
404
|
-
setPlayState(
|
|
272
|
+
setPlayState(d => {
|
|
405
273
|
d.loadingState = false;
|
|
406
274
|
d.errorState = true;
|
|
407
275
|
d.errorMsg = locals.getLang(IpcFailCode[type]);
|
|
408
276
|
d.connectState = false;
|
|
409
277
|
});
|
|
410
278
|
}
|
|
411
|
-
}, [playState.errorState]);
|
|
279
|
+
}, [playState.errorState]);
|
|
280
|
+
|
|
281
|
+
// 连接状态发生变化
|
|
412
282
|
|
|
413
283
|
// 断开连接
|
|
414
|
-
|
|
415
|
-
return new Promise(
|
|
284
|
+
const disconnect = () => {
|
|
285
|
+
return new Promise((resolve, reject) => {
|
|
416
286
|
var _ipcCtx$current6;
|
|
417
|
-
|
|
418
287
|
// console.log('断开连接前');
|
|
419
|
-
(_ipcCtx$current6 = ipcCtx.current) === null || _ipcCtx$current6 === void 0
|
|
420
|
-
success:
|
|
288
|
+
(_ipcCtx$current6 = ipcCtx.current) === null || _ipcCtx$current6 === void 0 || _ipcCtx$current6.disconnect({
|
|
289
|
+
success: res => {
|
|
421
290
|
// console.log('断开连接成功:', devId);
|
|
422
291
|
resolve(res);
|
|
423
|
-
setPlayState(
|
|
292
|
+
setPlayState(d => {
|
|
424
293
|
d.connectState = false;
|
|
425
294
|
});
|
|
426
295
|
onChangeStreamStatus && onChangeStreamStatus(1009);
|
|
427
296
|
},
|
|
428
|
-
fail:
|
|
297
|
+
fail: e => {
|
|
429
298
|
// console.error('断开连接失败:', devId);
|
|
430
299
|
reject(e);
|
|
431
300
|
onChangeStreamStatus && onChangeStreamStatus(-1009);
|
|
@@ -433,66 +302,39 @@ var Player = function (props) {
|
|
|
433
302
|
});
|
|
434
303
|
});
|
|
435
304
|
};
|
|
436
|
-
|
|
437
|
-
var handlePlayerClick = function () {
|
|
305
|
+
const handlePlayerClick = () => {
|
|
438
306
|
// console.log("videoTap:", devId);
|
|
439
307
|
onPlayerTap && onPlayerTap(devId);
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
var handleReWakeCamera = /*#__PURE__*/function () {
|
|
444
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
445
|
-
return _regeneratorRuntime.wrap(function (_context6) {
|
|
446
|
-
while (1) {
|
|
447
|
-
switch (_context6.prev = _context6.next) {
|
|
448
|
-
case 0:
|
|
449
|
-
_context6.next = 2;
|
|
450
|
-
return putDpData({
|
|
451
|
-
105: false
|
|
452
|
-
}, devId);
|
|
453
|
-
|
|
454
|
-
case 2:
|
|
455
|
-
case "end":
|
|
456
|
-
return _context6.stop();
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}, _callee6);
|
|
460
|
-
}));
|
|
308
|
+
};
|
|
461
309
|
|
|
462
|
-
|
|
463
|
-
return _ref5.apply(this, arguments);
|
|
464
|
-
};
|
|
465
|
-
}();
|
|
310
|
+
// 关闭隐私模式,重新拉流
|
|
466
311
|
|
|
467
312
|
return /*#__PURE__*/React.createElement(View, {
|
|
468
313
|
className: Styles.ipc_player,
|
|
469
314
|
onClick: handlePlayerClick
|
|
470
|
-
}, /*#__PURE__*/React.createElement(IpcPlayer
|
|
315
|
+
}, /*#__PURE__*/React.createElement(IpcPlayer
|
|
316
|
+
// @ts-ignore
|
|
471
317
|
, _extends({
|
|
472
318
|
className: "".concat(Styles.player, " ").concat(playState.updateLy),
|
|
473
|
-
onVideotap: handlePlayerClick,
|
|
474
319
|
onVideoTap: handlePlayerClick,
|
|
475
320
|
onZoomChange: onZoomChange,
|
|
476
|
-
onSessionDidDisconnected: onSessionDidDisconnected,
|
|
477
321
|
onCameraPreviewFailure: onCameraPreviewFailure,
|
|
478
322
|
onCameraNotifyWeakNetwork: onCameraNotifyWeakNetwork,
|
|
479
|
-
|
|
323
|
+
onInitDone: () => {
|
|
480
324
|
// console.log('视图层准备就绪:', devId);
|
|
481
|
-
setPlayState(
|
|
325
|
+
setPlayState(d => {
|
|
482
326
|
d.updateLy = Math.random();
|
|
483
327
|
d.initLy = true;
|
|
484
328
|
});
|
|
485
329
|
},
|
|
486
330
|
onError: onError,
|
|
487
|
-
|
|
331
|
+
onConnectChange: e => {
|
|
488
332
|
var _e$detail2;
|
|
489
|
-
|
|
490
333
|
// console.log('连接状态发生变化', e);
|
|
491
|
-
|
|
334
|
+
const code = e === null || e === void 0 || (_e$detail2 = e.detail) === null || _e$detail2 === void 0 ? void 0 : _e$detail2.state;
|
|
492
335
|
onChangeStreamStatus && onChangeStreamStatus(code === 0 ? 1001 : -1001);
|
|
493
|
-
|
|
494
336
|
if (code === 0) {
|
|
495
|
-
setPlayState(
|
|
337
|
+
setPlayState(d => {
|
|
496
338
|
d.connectState = true;
|
|
497
339
|
});
|
|
498
340
|
} else if ((code === -3 || code === -105) && retryCount.current < 1) {
|
|
@@ -500,7 +342,7 @@ var Player = function (props) {
|
|
|
500
342
|
retryCount.current++;
|
|
501
343
|
retry();
|
|
502
344
|
} else {
|
|
503
|
-
setPlayState(
|
|
345
|
+
setPlayState(d => {
|
|
504
346
|
d.connectState = false;
|
|
505
347
|
d.loadingState = false;
|
|
506
348
|
d.errorState = true;
|
|
@@ -532,18 +374,23 @@ var Player = function (props) {
|
|
|
532
374
|
className: Styles.load_icon
|
|
533
375
|
}), /*#__PURE__*/React.createElement(View, {
|
|
534
376
|
className: Styles.load_des
|
|
535
|
-
}, loadText || locals.getLang('
|
|
377
|
+
}, loadText || locals.getLang('ipc_player_get_video_stream'))), /*#__PURE__*/React.createElement(CoverView, {
|
|
536
378
|
style: {
|
|
537
379
|
borderRadius: "".concat(borderRadius)
|
|
538
380
|
},
|
|
539
381
|
className: cx(Styles.bg_center, Styles.state_label, !playState.errorState && Styles.hide)
|
|
540
382
|
}, privateState ? /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
541
383
|
className: Styles.device_sleep
|
|
542
|
-
}, locals.getLang('
|
|
543
|
-
className: Styles.re_wake_camera
|
|
384
|
+
}, locals.getLang('ipc_player_device_sleep')), /*#__PURE__*/React.createElement(View, {
|
|
385
|
+
className: Styles.re_wake_camera
|
|
386
|
+
// @ts-ignore
|
|
544
387
|
,
|
|
545
|
-
onClick:
|
|
546
|
-
|
|
388
|
+
onClick: async () => {
|
|
389
|
+
await putDpData({
|
|
390
|
+
105: false
|
|
391
|
+
}, devId);
|
|
392
|
+
}
|
|
393
|
+
}, locals.getLang('ipc_player_re_wake_camera'))) : /*#__PURE__*/React.createElement(View, {
|
|
547
394
|
style: {
|
|
548
395
|
width: '95%',
|
|
549
396
|
textAlign: 'center'
|
|
@@ -554,11 +401,11 @@ var Player = function (props) {
|
|
|
554
401
|
className: Styles.err_msg
|
|
555
402
|
}, /*#__PURE__*/React.createElement(View, {
|
|
556
403
|
className: cx(Styles.msg, Styles.ellipsis)
|
|
557
|
-
}, playState.errorMsg), /*#__PURE__*/React.createElement(View
|
|
404
|
+
}, playState.errorMsg), /*#__PURE__*/React.createElement(View
|
|
405
|
+
// @ts-ignore
|
|
558
406
|
, {
|
|
559
407
|
onClick: retry,
|
|
560
408
|
className: cx(Styles.retry, !playState.deviceOnlineState && Styles.hide)
|
|
561
409
|
}, locals.getLang('ipc_player_retry'))))));
|
|
562
410
|
};
|
|
563
|
-
|
|
564
411
|
export default Player;
|