@realsee/live 0.5.0-alpha.4 → 0.5.0-alpha.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.
- package/dist/live/controller.d.ts +6 -0
- package/dist/live/live.d.ts +9 -1
- package/dist/realsee-live.cjs.development.js +72 -7
- package/dist/realsee-live.cjs.development.js.map +1 -1
- package/dist/realsee-live.cjs.production.js +1 -1
- package/dist/realsee-live.cjs.production.js.map +1 -1
- package/dist/realsee-live.esm.js +72 -7
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +72 -7
- package/dist/realsee-live.umd.development.js.map +1 -1
- package/dist/realsee-live.umd.production.js +1 -1
- package/dist/realsee-live.umd.production.js.map +1 -1
- package/dist/utils/RobustWebSocket.d.ts +19 -0
- package/docs/classes/VRWebViewRTC.html +5 -5
- package/package.json +1 -1
package/dist/realsee-live.esm.js
CHANGED
|
@@ -608,9 +608,12 @@ class VRWebViewRTC extends CoreRTC {
|
|
|
608
608
|
this.micro = false;
|
|
609
609
|
this.voiceId = '';
|
|
610
610
|
this.options = { jsBridge, getVoiceSign };
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
611
|
+
// TO-DO: 在微信小程序下有个音量上报的BUG会导致消息体过大从而jsbridge异常断开
|
|
612
|
+
if (this.jsBridge.webViewType !== "WxMiniProgramWebView") {
|
|
613
|
+
this.jsBridge.callAndListen('live/userVolumes', (userVolumes) => {
|
|
614
|
+
this.emit('userVolumes', userVolumes);
|
|
615
|
+
});
|
|
616
|
+
}
|
|
614
617
|
this.jsBridge.callAndListen('live/weakNetwork', (weakNetwork) => {
|
|
615
618
|
if (weakNetwork)
|
|
616
619
|
this.emit('weakNetwork');
|
|
@@ -1160,6 +1163,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1160
1163
|
constructor(options) {
|
|
1161
1164
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
1162
1165
|
super();
|
|
1166
|
+
this._readyState = WebSocketState.NOTINITIALIZED;
|
|
1163
1167
|
this._options = {
|
|
1164
1168
|
timeout: 10000,
|
|
1165
1169
|
shouldReconnect: (event, ws) => {
|
|
@@ -1176,6 +1180,43 @@ class RobustWebSocket extends Subscribe {
|
|
|
1176
1180
|
this._reconnectWhenOnlineAgain = false;
|
|
1177
1181
|
this._explicitlyClosed = false;
|
|
1178
1182
|
this._connectivityEventsAttached = false;
|
|
1183
|
+
/**
|
|
1184
|
+
* 做一个健康检查
|
|
1185
|
+
*/
|
|
1186
|
+
this._healthCheck = () => __awaiter(this, void 0, void 0, function* () {
|
|
1187
|
+
if (this._realWebSocket &&
|
|
1188
|
+
this._realWebSocket.readyState !== this._readyState) {
|
|
1189
|
+
this._readyState = this._realWebSocket.readyState;
|
|
1190
|
+
// 太惨了,断网的时候,ws不会直接closed,而是处于closing的状态
|
|
1191
|
+
if (this._readyState === WebSocketState.CLOSING) {
|
|
1192
|
+
this.emit('closing');
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
1196
|
+
this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
|
|
1197
|
+
});
|
|
1198
|
+
/**
|
|
1199
|
+
* 清理健康检查
|
|
1200
|
+
*/
|
|
1201
|
+
this._clearHeathCheckIfNeed = () => {
|
|
1202
|
+
if (this._heathCheckTimer) {
|
|
1203
|
+
cancelAnimationFrame(this._heathCheckTimer);
|
|
1204
|
+
this._heathCheckTimer = undefined;
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
/**
|
|
1208
|
+
* 开启健康检查
|
|
1209
|
+
*/
|
|
1210
|
+
this._startHealthCheck = () => {
|
|
1211
|
+
this._clearHeathCheckIfNeed();
|
|
1212
|
+
this._heathCheckTimer = requestAnimationFrame(this._healthCheck);
|
|
1213
|
+
};
|
|
1214
|
+
/**
|
|
1215
|
+
* 停止健康检查
|
|
1216
|
+
*/
|
|
1217
|
+
this._stopHealthCheck = () => {
|
|
1218
|
+
this._clearHeathCheckIfNeed();
|
|
1219
|
+
};
|
|
1179
1220
|
/**
|
|
1180
1221
|
* 清理连接中的请求
|
|
1181
1222
|
*/
|
|
@@ -1201,7 +1242,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1201
1242
|
this._offline = () => {
|
|
1202
1243
|
var _a;
|
|
1203
1244
|
this._reconnectWhenOnlineAgain = true;
|
|
1204
|
-
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000);
|
|
1245
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.close(1000, 'offline');
|
|
1205
1246
|
};
|
|
1206
1247
|
/**
|
|
1207
1248
|
* 解除网络监听事件
|
|
@@ -1332,6 +1373,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1332
1373
|
const attempts = this._attempts;
|
|
1333
1374
|
this._attempts = 0;
|
|
1334
1375
|
this._reconnectWhenOnlineAgain = false;
|
|
1376
|
+
this._startHealthCheck();
|
|
1335
1377
|
return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
|
|
1336
1378
|
};
|
|
1337
1379
|
/**
|
|
@@ -1341,6 +1383,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1341
1383
|
*/
|
|
1342
1384
|
this._webSocketCloseHandler = (event) => {
|
|
1343
1385
|
this._reconnect(event);
|
|
1386
|
+
this._stopHealthCheck();
|
|
1344
1387
|
return this.emit('close', event);
|
|
1345
1388
|
};
|
|
1346
1389
|
/**
|
|
@@ -1362,6 +1405,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1362
1405
|
if (options) {
|
|
1363
1406
|
this.setOptions(options);
|
|
1364
1407
|
}
|
|
1408
|
+
this._startHealthCheck();
|
|
1365
1409
|
}
|
|
1366
1410
|
get attempts() {
|
|
1367
1411
|
return this._attempts;
|
|
@@ -1412,7 +1456,10 @@ class LiveController extends Subscribe {
|
|
|
1412
1456
|
/**
|
|
1413
1457
|
* ws代理器
|
|
1414
1458
|
*/
|
|
1415
|
-
this._ws = new RobustWebSocket(
|
|
1459
|
+
this._ws = new RobustWebSocket({
|
|
1460
|
+
url: '',
|
|
1461
|
+
robustOptions: { timeout: 180000 },
|
|
1462
|
+
});
|
|
1416
1463
|
/**
|
|
1417
1464
|
* 带看连接状态
|
|
1418
1465
|
*/
|
|
@@ -1422,6 +1469,7 @@ class LiveController extends Subscribe {
|
|
|
1422
1469
|
*/
|
|
1423
1470
|
this._addWebSocketEventListeners = () => {
|
|
1424
1471
|
this._ws.on('close', this._handleCloseEvent);
|
|
1472
|
+
this._ws.on('closing', this._handleClosingEvent);
|
|
1425
1473
|
this._ws.on('connecting', this._handleConnectingEvent);
|
|
1426
1474
|
this._ws.on('error', this._handleErrorEvent);
|
|
1427
1475
|
this._ws.on('message', this._handleMessageEvent);
|
|
@@ -1433,6 +1481,7 @@ class LiveController extends Subscribe {
|
|
|
1433
1481
|
*/
|
|
1434
1482
|
this._removeWebSocketEventListeners = () => {
|
|
1435
1483
|
this._ws.off('close', this._handleCloseEvent);
|
|
1484
|
+
this._ws.off('closing', this._handleClosingEvent);
|
|
1436
1485
|
this._ws.off('connecting', this._handleConnectingEvent);
|
|
1437
1486
|
this._ws.off('error', this._handleErrorEvent);
|
|
1438
1487
|
this._ws.off('message', this._handleMessageEvent);
|
|
@@ -1447,12 +1496,20 @@ class LiveController extends Subscribe {
|
|
|
1447
1496
|
logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
|
|
1448
1497
|
this.state = LiveState.CLOSED;
|
|
1449
1498
|
};
|
|
1499
|
+
/**
|
|
1500
|
+
* 处理房间正在关闭事件(这个时候可能是断网了)
|
|
1501
|
+
*/
|
|
1502
|
+
this._handleClosingEvent = () => {
|
|
1503
|
+
var _a;
|
|
1504
|
+
logger$1.info(`live room is closing, onLine:`, (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator) === null || _a === void 0 ? void 0 : _a.onLine);
|
|
1505
|
+
this.state = LiveState.CLOSED;
|
|
1506
|
+
};
|
|
1450
1507
|
/**
|
|
1451
1508
|
* 连接中
|
|
1452
1509
|
* @param event
|
|
1453
1510
|
*/
|
|
1454
|
-
this._handleConnectingEvent = (
|
|
1455
|
-
logger$1.info(`live room is connecting
|
|
1511
|
+
this._handleConnectingEvent = () => {
|
|
1512
|
+
logger$1.info(`live room is connecting`);
|
|
1456
1513
|
this.state = LiveState.CONNECTING;
|
|
1457
1514
|
};
|
|
1458
1515
|
/**
|
|
@@ -1486,6 +1543,9 @@ class LiveController extends Subscribe {
|
|
|
1486
1543
|
this._handleOpenEvent = (event) => {
|
|
1487
1544
|
logger$1.info('live room open', event.detail);
|
|
1488
1545
|
this.state = LiveState.OPEN;
|
|
1546
|
+
if (event.detail.reconnects > 0) {
|
|
1547
|
+
this.emit('reconnected', event.detail);
|
|
1548
|
+
}
|
|
1489
1549
|
};
|
|
1490
1550
|
/**
|
|
1491
1551
|
* 处理超时
|
|
@@ -1626,6 +1686,10 @@ class Live extends Subscribe {
|
|
|
1626
1686
|
* @returns
|
|
1627
1687
|
*/
|
|
1628
1688
|
this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
|
|
1689
|
+
/**
|
|
1690
|
+
* 消息接收
|
|
1691
|
+
* @param liveMsg
|
|
1692
|
+
*/
|
|
1629
1693
|
this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
1630
1694
|
var _b, _c, _d, _e, _f, _g;
|
|
1631
1695
|
if (typeof liveMsg === 'object') {
|
|
@@ -1657,6 +1721,7 @@ class Live extends Subscribe {
|
|
|
1657
1721
|
*/
|
|
1658
1722
|
case Command.RTCInfo: {
|
|
1659
1723
|
const { voice_id: voiceId, type } = data;
|
|
1724
|
+
this._buildInData.rtcInfo = { voiceId, type };
|
|
1660
1725
|
if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
|
|
1661
1726
|
const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
|
|
1662
1727
|
voiceId,
|