@ray-js/ray-ipc-player 2.0.11-beta-1 → 2.0.12
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.js +100 -72
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +48 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import "core-js/modules/es.object.to-string.js";
|
|
|
5
5
|
import "core-js/modules/es.promise.js";
|
|
6
6
|
import "core-js/modules/es.array.concat.js";
|
|
7
7
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-unneeded-ternary */
|
|
8
10
|
import React, { useEffect, useRef, useCallback } from 'react';
|
|
9
11
|
import { useImmer } from 'use-immer';
|
|
10
12
|
import { IpcPlayer, View, CoverView } from '@ray-js/components';
|
|
@@ -13,7 +15,7 @@ import { usePageEvent } from 'ray';
|
|
|
13
15
|
import locals from './i18n';
|
|
14
16
|
import Styles from './index.module.less';
|
|
15
17
|
import { IpcFailCode } from './constant';
|
|
16
|
-
import { putDpData } from './utils';
|
|
18
|
+
import { putDpData, getIsConnected, getIsOnPreview } from './utils';
|
|
17
19
|
|
|
18
20
|
var Player = function (props) {
|
|
19
21
|
var _props$updateLayout = props.updateLayout,
|
|
@@ -83,24 +85,33 @@ var Player = function (props) {
|
|
|
83
85
|
|
|
84
86
|
var muteRef = useRef(defaultMute); // 静音
|
|
85
87
|
|
|
86
|
-
usePageEvent('onShow', useCallback(function () {
|
|
87
|
-
// console.log('show');
|
|
88
|
-
if (ipcCtx.current && playState.connectState) {
|
|
89
|
-
startPreview('');
|
|
90
|
-
} else if (ipcCtx.current) {
|
|
91
|
-
retry();
|
|
92
|
-
}
|
|
93
|
-
}, [playState.connectState, privateState]));
|
|
94
|
-
usePageEvent('onHide', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
88
|
+
usePageEvent('onShow', useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
95
89
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
96
90
|
while (1) {
|
|
97
91
|
switch (_context.prev = _context.next) {
|
|
92
|
+
case 0:
|
|
93
|
+
// 视图准备就绪
|
|
94
|
+
if (playState.initLy && ipcCtx.current) {
|
|
95
|
+
retry();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
case 1:
|
|
99
|
+
case "end":
|
|
100
|
+
return _context.stop();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}, _callee);
|
|
104
|
+
})), [playState.connectState, privateState, playState.initLy]));
|
|
105
|
+
usePageEvent('onHide', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
106
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
107
|
+
while (1) {
|
|
108
|
+
switch (_context2.prev = _context2.next) {
|
|
98
109
|
case 0:
|
|
99
110
|
// console.log('hide');
|
|
100
111
|
setPlayState(function (d) {
|
|
101
112
|
d.loadingState = true;
|
|
102
113
|
});
|
|
103
|
-
|
|
114
|
+
_context2.next = 3;
|
|
104
115
|
return getCurMute();
|
|
105
116
|
|
|
106
117
|
case 3:
|
|
@@ -108,10 +119,10 @@ var Player = function (props) {
|
|
|
108
119
|
|
|
109
120
|
case 4:
|
|
110
121
|
case "end":
|
|
111
|
-
return
|
|
122
|
+
return _context2.stop();
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
|
-
},
|
|
125
|
+
}, _callee2);
|
|
115
126
|
})));
|
|
116
127
|
useEffect(function () {
|
|
117
128
|
onlineStatus && createIpcCtx(devId);
|
|
@@ -146,46 +157,47 @@ var Player = function (props) {
|
|
|
146
157
|
}, [onlineStatus, playState.initLy, privateState]); // 重试
|
|
147
158
|
|
|
148
159
|
var _retry = /*#__PURE__*/function () {
|
|
149
|
-
var
|
|
150
|
-
|
|
160
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
161
|
+
var connectState, isOnPreview;
|
|
162
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
151
163
|
while (1) {
|
|
152
|
-
switch (
|
|
164
|
+
switch (_context3.prev = _context3.next) {
|
|
153
165
|
case 0:
|
|
166
|
+
_context3.next = 2;
|
|
167
|
+
return getIsConnected(ipcCtx.current);
|
|
168
|
+
|
|
169
|
+
case 2:
|
|
170
|
+
connectState = _context3.sent;
|
|
171
|
+
_context3.next = 5;
|
|
172
|
+
return getIsOnPreview(ipcCtx.current);
|
|
173
|
+
|
|
174
|
+
case 5:
|
|
175
|
+
isOnPreview = _context3.sent;
|
|
154
176
|
setPlayState(function (d) {
|
|
155
|
-
d.connectState = false;
|
|
177
|
+
d.connectState = connectState ? true : false;
|
|
156
178
|
d.errorMsg = '';
|
|
157
179
|
d.errorState = false;
|
|
158
|
-
d.loadingState = true;
|
|
159
|
-
});
|
|
160
|
-
_context2.t0 = connectState;
|
|
161
|
-
|
|
162
|
-
if (!_context2.t0) {
|
|
163
|
-
_context2.next = 5;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
_context2.next = 5;
|
|
168
|
-
return disconnect();
|
|
180
|
+
d.loadingState = isOnPreview ? false : true;
|
|
181
|
+
}); // !prePlayRef.current && connectState && (await disconnect());
|
|
169
182
|
|
|
170
|
-
case 5:
|
|
171
183
|
ipcCtx.current && createConnect();
|
|
172
184
|
|
|
173
|
-
case
|
|
185
|
+
case 8:
|
|
174
186
|
case "end":
|
|
175
|
-
return
|
|
187
|
+
return _context3.stop();
|
|
176
188
|
}
|
|
177
189
|
}
|
|
178
|
-
},
|
|
190
|
+
}, _callee3);
|
|
179
191
|
}));
|
|
180
192
|
|
|
181
193
|
return function () {
|
|
182
|
-
return
|
|
194
|
+
return _ref3.apply(this, arguments);
|
|
183
195
|
};
|
|
184
196
|
}();
|
|
185
197
|
|
|
186
198
|
var retry = useCallback(function () {
|
|
187
199
|
// console.log('retry:', muteRef.current);
|
|
188
|
-
!privateState && _retry(
|
|
200
|
+
!privateState && _retry();
|
|
189
201
|
}, [playState.connectState, privateState]); // 创建ipc实例
|
|
190
202
|
|
|
191
203
|
var createIpcCtx = function (id) {
|
|
@@ -201,42 +213,57 @@ var Player = function (props) {
|
|
|
201
213
|
}; // 建立连接
|
|
202
214
|
|
|
203
215
|
|
|
204
|
-
var createConnect = function (
|
|
205
|
-
var
|
|
216
|
+
var createConnect = /*#__PURE__*/function () {
|
|
217
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
|
|
218
|
+
var _ipcCtx$current;
|
|
206
219
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
220
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
221
|
+
while (1) {
|
|
222
|
+
switch (_context4.prev = _context4.next) {
|
|
223
|
+
case 0:
|
|
224
|
+
// console.log('建立连接前:', devId, Date.now());
|
|
225
|
+
(_ipcCtx$current = ipcCtx.current) === null || _ipcCtx$current === void 0 ? void 0 : _ipcCtx$current.connect({
|
|
226
|
+
success: function success() {
|
|
227
|
+
// console.log('建立连接成功:', devId, Date.now());
|
|
228
|
+
setPlayState(function (d) {
|
|
229
|
+
d.connectState = true;
|
|
230
|
+
d.errorState = false;
|
|
231
|
+
d.errorMsg = '';
|
|
232
|
+
});
|
|
233
|
+
onChangeStreamStatus && onChangeStreamStatus(1001);
|
|
234
|
+
startPreview(params);
|
|
235
|
+
},
|
|
236
|
+
fail: function fail() {
|
|
237
|
+
// console.error('建立连接失败---------:', e, devId, Date.now());
|
|
238
|
+
setPlayState(function (d) {
|
|
239
|
+
d.connectState = false;
|
|
240
|
+
d.errorState = true;
|
|
241
|
+
d.errorMsg = locals.getLang('ipc_player_connect_fail');
|
|
242
|
+
d.loadingState = false;
|
|
243
|
+
});
|
|
244
|
+
onChangeStreamStatus && onChangeStreamStatus(-1001);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
case 1:
|
|
249
|
+
case "end":
|
|
250
|
+
return _context4.stop();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, _callee4);
|
|
254
|
+
}));
|
|
255
|
+
|
|
256
|
+
return function () {
|
|
257
|
+
return _ref4.apply(this, arguments);
|
|
258
|
+
};
|
|
259
|
+
}(); // 视图层准备就绪,开始建立连接
|
|
234
260
|
|
|
235
261
|
|
|
236
262
|
// 开启预览
|
|
237
263
|
var startPreview = function (params) {
|
|
238
264
|
var _ipcCtx$current2;
|
|
239
265
|
|
|
266
|
+
// console.log('开启预览前');
|
|
240
267
|
(_ipcCtx$current2 = ipcCtx.current) === null || _ipcCtx$current2 === void 0 ? void 0 : _ipcCtx$current2.startPreview({
|
|
241
268
|
success: function success() {
|
|
242
269
|
// console.log('开启预览:', devId);
|
|
@@ -249,7 +276,7 @@ var Player = function (props) {
|
|
|
249
276
|
onChangeStreamStatus && onChangeStreamStatus(1002);
|
|
250
277
|
},
|
|
251
278
|
fail: function fail() {
|
|
252
|
-
// console.
|
|
279
|
+
// console.error('开启失败:', devId);
|
|
253
280
|
setPlayState(function (d) {
|
|
254
281
|
d.errorState = true;
|
|
255
282
|
d.loadingState = false;
|
|
@@ -340,6 +367,7 @@ var Player = function (props) {
|
|
|
340
367
|
return new Promise(function (resolve, reject) {
|
|
341
368
|
var _ipcCtx$current6;
|
|
342
369
|
|
|
370
|
+
// console.log('断开连接前');
|
|
343
371
|
(_ipcCtx$current6 = ipcCtx.current) === null || _ipcCtx$current6 === void 0 ? void 0 : _ipcCtx$current6.disconnect({
|
|
344
372
|
success: function success(res) {
|
|
345
373
|
// console.log('断开连接成功:', devId);
|
|
@@ -350,7 +378,7 @@ var Player = function (props) {
|
|
|
350
378
|
onChangeStreamStatus && onChangeStreamStatus(1009);
|
|
351
379
|
},
|
|
352
380
|
fail: function fail(e) {
|
|
353
|
-
// console.
|
|
381
|
+
// console.error('断开连接失败:', devId);
|
|
354
382
|
reject(e);
|
|
355
383
|
onChangeStreamStatus && onChangeStreamStatus(-1009);
|
|
356
384
|
}
|
|
@@ -365,26 +393,26 @@ var Player = function (props) {
|
|
|
365
393
|
|
|
366
394
|
|
|
367
395
|
var handleReWakeCamera = /*#__PURE__*/function () {
|
|
368
|
-
var
|
|
369
|
-
return _regeneratorRuntime.wrap(function (
|
|
396
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
397
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
370
398
|
while (1) {
|
|
371
|
-
switch (
|
|
399
|
+
switch (_context5.prev = _context5.next) {
|
|
372
400
|
case 0:
|
|
373
|
-
|
|
401
|
+
_context5.next = 2;
|
|
374
402
|
return putDpData({
|
|
375
403
|
105: false
|
|
376
404
|
}, devId);
|
|
377
405
|
|
|
378
406
|
case 2:
|
|
379
407
|
case "end":
|
|
380
|
-
return
|
|
408
|
+
return _context5.stop();
|
|
381
409
|
}
|
|
382
410
|
}
|
|
383
|
-
},
|
|
411
|
+
}, _callee5);
|
|
384
412
|
}));
|
|
385
413
|
|
|
386
414
|
return function () {
|
|
387
|
-
return
|
|
415
|
+
return _ref5.apply(this, arguments);
|
|
388
416
|
};
|
|
389
417
|
}();
|
|
390
418
|
|
package/lib/utils.d.ts
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
1
|
export declare const putDpData: (dpIds: Record<number, boolean>, deviceId?: string) => Promise<unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* 获取当前是否Connected (p2p连接状态)
|
|
4
|
+
* @param ipcCtx
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const getIsConnected: (ipcCtx: any) => Promise<unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* 获取当前是否已经在拉流状态
|
|
10
|
+
* @param ipcCtx
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const getIsOnPreview: (ipcCtx: any) => Promise<unknown>;
|
package/lib/utils.js
CHANGED
|
@@ -16,4 +16,52 @@ export var putDpData = function (dpIds, deviceId) {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 获取当前是否Connected (p2p连接状态)
|
|
22
|
+
* @param ipcCtx
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export var getIsConnected = function (ipcCtx) {
|
|
27
|
+
return new Promise(function (resolve) {
|
|
28
|
+
if (typeof (ipcCtx === null || ipcCtx === void 0 ? void 0 : ipcCtx.isConnected) === 'function') {
|
|
29
|
+
ipcCtx === null || ipcCtx === void 0 ? void 0 : ipcCtx.isConnected({
|
|
30
|
+
success: function success(res) {
|
|
31
|
+
// console.log(res, 'getIsConnected---');
|
|
32
|
+
resolve(res);
|
|
33
|
+
},
|
|
34
|
+
fail: function fail() {
|
|
35
|
+
// console.error(e, 'getIsConnected---');
|
|
36
|
+
resolve(false);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
resolve(false);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 获取当前是否已经在拉流状态
|
|
46
|
+
* @param ipcCtx
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
export var getIsOnPreview = function (ipcCtx) {
|
|
51
|
+
return new Promise(function (resolve) {
|
|
52
|
+
if (typeof (ipcCtx === null || ipcCtx === void 0 ? void 0 : ipcCtx.isOnPreview) === 'function') {
|
|
53
|
+
ipcCtx === null || ipcCtx === void 0 ? void 0 : ipcCtx.isOnPreview({
|
|
54
|
+
success: function success(res) {
|
|
55
|
+
// console.log(res, 'getIsOnPreview---');
|
|
56
|
+
resolve(res);
|
|
57
|
+
},
|
|
58
|
+
fail: function fail() {
|
|
59
|
+
// console.error(e, 'getIsOnPreview---');
|
|
60
|
+
resolve(false);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
resolve(false);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
19
67
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/ray-ipc-player",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.12",
|
|
4
4
|
"description": "ray小程序播放器",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tuya-miniapp",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ray-js/ray": "latest",
|
|
29
28
|
"@ray-js/panel-sdk": "latest",
|
|
30
29
|
"immer": "^9.0.15",
|
|
31
30
|
"use-immer": "^0.5.1",
|
|
32
31
|
"classnames": "^2.3.1"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
34
|
+
"@ray-js/ray": "latest",
|
|
35
35
|
"@commitlint/cli": "^7.2.1",
|
|
36
36
|
"@commitlint/config-conventional": "^9.0.1",
|
|
37
37
|
"@ray-js/babel-preset-standard": "latest",
|