@realsee/live 0.5.0-alpha.3 → 0.5.0-alpha.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.
- package/dist/live/controller.d.ts +6 -0
- package/dist/live/live.d.ts +9 -1
- package/dist/realsee-live.cjs.development.js +79 -6
- 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 +79 -6
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +90 -6
- 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 +23 -0
- package/docs/classes/VRWebViewRTC.html +5 -5
- package/package.json +2 -2
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
|
* 解除网络监听事件
|
|
@@ -1277,6 +1318,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1277
1318
|
if (!newUrl)
|
|
1278
1319
|
return;
|
|
1279
1320
|
this._pendingReconnect = undefined;
|
|
1321
|
+
this._removeWebSocketEvent();
|
|
1280
1322
|
this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
|
|
1281
1323
|
this._attempts = this._attempts + 1;
|
|
1282
1324
|
this.emit('connecting', new CustomEvent('connecting', {
|
|
@@ -1298,6 +1340,16 @@ class RobustWebSocket extends Subscribe {
|
|
|
1298
1340
|
this._attachConnectivityEvents();
|
|
1299
1341
|
}
|
|
1300
1342
|
};
|
|
1343
|
+
/**
|
|
1344
|
+
* 断开ws事件
|
|
1345
|
+
*/
|
|
1346
|
+
this._removeWebSocketEvent = () => {
|
|
1347
|
+
var _a, _b, _c, _d;
|
|
1348
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
|
|
1349
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
|
|
1350
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
|
|
1351
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
|
|
1352
|
+
};
|
|
1301
1353
|
/**
|
|
1302
1354
|
* 分发ws事件
|
|
1303
1355
|
*/
|
|
@@ -1321,6 +1373,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1321
1373
|
const attempts = this._attempts;
|
|
1322
1374
|
this._attempts = 0;
|
|
1323
1375
|
this._reconnectWhenOnlineAgain = false;
|
|
1376
|
+
this._startHealthCheck();
|
|
1324
1377
|
return this.emit('open', Object.assign(event, { detail: { reconnects, attempts } }));
|
|
1325
1378
|
};
|
|
1326
1379
|
/**
|
|
@@ -1330,6 +1383,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1330
1383
|
*/
|
|
1331
1384
|
this._webSocketCloseHandler = (event) => {
|
|
1332
1385
|
this._reconnect(event);
|
|
1386
|
+
this._stopHealthCheck();
|
|
1333
1387
|
return this.emit('close', event);
|
|
1334
1388
|
};
|
|
1335
1389
|
/**
|
|
@@ -1351,6 +1405,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1351
1405
|
if (options) {
|
|
1352
1406
|
this.setOptions(options);
|
|
1353
1407
|
}
|
|
1408
|
+
this._startHealthCheck();
|
|
1354
1409
|
}
|
|
1355
1410
|
get attempts() {
|
|
1356
1411
|
return this._attempts;
|
|
@@ -1411,6 +1466,7 @@ class LiveController extends Subscribe {
|
|
|
1411
1466
|
*/
|
|
1412
1467
|
this._addWebSocketEventListeners = () => {
|
|
1413
1468
|
this._ws.on('close', this._handleCloseEvent);
|
|
1469
|
+
this._ws.on('closing', this._handleClosingEvent);
|
|
1414
1470
|
this._ws.on('connecting', this._handleConnectingEvent);
|
|
1415
1471
|
this._ws.on('error', this._handleErrorEvent);
|
|
1416
1472
|
this._ws.on('message', this._handleMessageEvent);
|
|
@@ -1422,6 +1478,7 @@ class LiveController extends Subscribe {
|
|
|
1422
1478
|
*/
|
|
1423
1479
|
this._removeWebSocketEventListeners = () => {
|
|
1424
1480
|
this._ws.off('close', this._handleCloseEvent);
|
|
1481
|
+
this._ws.off('closing', this._handleClosingEvent);
|
|
1425
1482
|
this._ws.off('connecting', this._handleConnectingEvent);
|
|
1426
1483
|
this._ws.off('error', this._handleErrorEvent);
|
|
1427
1484
|
this._ws.off('message', this._handleMessageEvent);
|
|
@@ -1436,12 +1493,20 @@ class LiveController extends Subscribe {
|
|
|
1436
1493
|
logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
|
|
1437
1494
|
this.state = LiveState.CLOSED;
|
|
1438
1495
|
};
|
|
1496
|
+
/**
|
|
1497
|
+
* 处理房间正在关闭事件(这个时候可能是断网了)
|
|
1498
|
+
*/
|
|
1499
|
+
this._handleClosingEvent = () => {
|
|
1500
|
+
var _a;
|
|
1501
|
+
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);
|
|
1502
|
+
this.state = LiveState.CLOSED;
|
|
1503
|
+
};
|
|
1439
1504
|
/**
|
|
1440
1505
|
* 连接中
|
|
1441
1506
|
* @param event
|
|
1442
1507
|
*/
|
|
1443
|
-
this._handleConnectingEvent = (
|
|
1444
|
-
logger$1.info(`live room is connecting
|
|
1508
|
+
this._handleConnectingEvent = () => {
|
|
1509
|
+
logger$1.info(`live room is connecting`);
|
|
1445
1510
|
this.state = LiveState.CONNECTING;
|
|
1446
1511
|
};
|
|
1447
1512
|
/**
|
|
@@ -1475,6 +1540,9 @@ class LiveController extends Subscribe {
|
|
|
1475
1540
|
this._handleOpenEvent = (event) => {
|
|
1476
1541
|
logger$1.info('live room open', event.detail);
|
|
1477
1542
|
this.state = LiveState.OPEN;
|
|
1543
|
+
if (event.detail.reconnects > 0) {
|
|
1544
|
+
this.emit('reconnected', event.detail);
|
|
1545
|
+
}
|
|
1478
1546
|
};
|
|
1479
1547
|
/**
|
|
1480
1548
|
* 处理超时
|
|
@@ -1615,6 +1683,10 @@ class Live extends Subscribe {
|
|
|
1615
1683
|
* @returns
|
|
1616
1684
|
*/
|
|
1617
1685
|
this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
|
|
1686
|
+
/**
|
|
1687
|
+
* 消息接收
|
|
1688
|
+
* @param liveMsg
|
|
1689
|
+
*/
|
|
1618
1690
|
this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
1619
1691
|
var _b, _c, _d, _e, _f, _g;
|
|
1620
1692
|
if (typeof liveMsg === 'object') {
|
|
@@ -1646,6 +1718,7 @@ class Live extends Subscribe {
|
|
|
1646
1718
|
*/
|
|
1647
1719
|
case Command.RTCInfo: {
|
|
1648
1720
|
const { voice_id: voiceId, type } = data;
|
|
1721
|
+
this._buildInData.rtcInfo = { voiceId, type };
|
|
1649
1722
|
if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
|
|
1650
1723
|
const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
|
|
1651
1724
|
voiceId,
|