@realsee/live 0.5.0-alpha.1 → 0.5.0-alpha.4
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/realsee-live.cjs.development.js +46 -30
- 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 +35 -19
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +63 -31
- 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/typings/live/index.d.ts +1 -0
- package/dist/utils/RobustWebSocket.d.ts +4 -0
- package/docs/assets/search.js +1 -1
- package/docs/enums/LiveState.html +7 -0
- package/docs/index.html +1 -1
- package/docs/modules.html +8 -8
- package/package.json +2 -2
|
@@ -795,6 +795,23 @@ function parseLiveMsg(jsonTxt) {
|
|
|
795
795
|
}
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
+
exports.LiveState = void 0;
|
|
799
|
+
(function (LiveState) {
|
|
800
|
+
LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
|
|
801
|
+
/**
|
|
802
|
+
* 正在链接中
|
|
803
|
+
*/
|
|
804
|
+
LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
|
|
805
|
+
/**
|
|
806
|
+
* 已经链接并且可以通讯
|
|
807
|
+
*/
|
|
808
|
+
LiveState[LiveState["OPEN"] = 1] = "OPEN";
|
|
809
|
+
/**
|
|
810
|
+
* 连接已关闭或者链接失败
|
|
811
|
+
*/
|
|
812
|
+
LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
|
|
813
|
+
})(exports.LiveState || (exports.LiveState = {}));
|
|
814
|
+
|
|
798
815
|
/**
|
|
799
816
|
* 用户当前状态枚举。
|
|
800
817
|
*/
|
|
@@ -952,23 +969,6 @@ exports.default = LogLevel;
|
|
|
952
969
|
|
|
953
970
|
var LogLevel = /*@__PURE__*/getDefaultExportFromCjs(LogLevel_1);
|
|
954
971
|
|
|
955
|
-
var LiveState;
|
|
956
|
-
(function (LiveState) {
|
|
957
|
-
LiveState[LiveState["NOTINITIALIZED"] = -1] = "NOTINITIALIZED";
|
|
958
|
-
/**
|
|
959
|
-
* 正在链接中
|
|
960
|
-
*/
|
|
961
|
-
LiveState[LiveState["CONNECTING"] = 0] = "CONNECTING";
|
|
962
|
-
/**
|
|
963
|
-
* 已经链接并且可以通讯
|
|
964
|
-
*/
|
|
965
|
-
LiveState[LiveState["OPEN"] = 1] = "OPEN";
|
|
966
|
-
/**
|
|
967
|
-
* 连接已关闭或者链接失败
|
|
968
|
-
*/
|
|
969
|
-
LiveState[LiveState["CLOSED"] = 3] = "CLOSED";
|
|
970
|
-
})(LiveState || (LiveState = {}));
|
|
971
|
-
|
|
972
972
|
function appendUri(uri, query) {
|
|
973
973
|
const hasQuery = uri.indexOf('?') !== -1;
|
|
974
974
|
const newQuery = Object.keys(query).reduce((accu, curr, idx) => `${accu}${(idx === 0 && !hasQuery) ? '?' : '&'}${curr}=${query[curr]}`, '');
|
|
@@ -1238,7 +1238,12 @@ class RobustWebSocket extends Subscribe {
|
|
|
1238
1238
|
* @param data
|
|
1239
1239
|
* @returns
|
|
1240
1240
|
*/
|
|
1241
|
-
this.send = (data) => {
|
|
1241
|
+
this.send = (data) => {
|
|
1242
|
+
var _a, _b, _c;
|
|
1243
|
+
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
|
|
1244
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1242
1247
|
/**
|
|
1243
1248
|
* 关闭连接
|
|
1244
1249
|
* @param code 代码
|
|
@@ -1282,6 +1287,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1282
1287
|
if (!newUrl)
|
|
1283
1288
|
return;
|
|
1284
1289
|
this._pendingReconnect = undefined;
|
|
1290
|
+
this._removeWebSocketEvent();
|
|
1285
1291
|
this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
|
|
1286
1292
|
this._attempts = this._attempts + 1;
|
|
1287
1293
|
this.emit('connecting', new CustomEvent('connecting', {
|
|
@@ -1303,6 +1309,16 @@ class RobustWebSocket extends Subscribe {
|
|
|
1303
1309
|
this._attachConnectivityEvents();
|
|
1304
1310
|
}
|
|
1305
1311
|
};
|
|
1312
|
+
/**
|
|
1313
|
+
* 断开ws事件
|
|
1314
|
+
*/
|
|
1315
|
+
this._removeWebSocketEvent = () => {
|
|
1316
|
+
var _a, _b, _c, _d;
|
|
1317
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
|
|
1318
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
|
|
1319
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
|
|
1320
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
|
|
1321
|
+
};
|
|
1306
1322
|
/**
|
|
1307
1323
|
* 分发ws事件
|
|
1308
1324
|
*/
|
|
@@ -1410,7 +1426,7 @@ class LiveController extends Subscribe {
|
|
|
1410
1426
|
/**
|
|
1411
1427
|
* 带看连接状态
|
|
1412
1428
|
*/
|
|
1413
|
-
this._state = LiveState.NOTINITIALIZED;
|
|
1429
|
+
this._state = exports.LiveState.NOTINITIALIZED;
|
|
1414
1430
|
/**
|
|
1415
1431
|
* 添加事件监听
|
|
1416
1432
|
*/
|
|
@@ -1439,7 +1455,7 @@ class LiveController extends Subscribe {
|
|
|
1439
1455
|
*/
|
|
1440
1456
|
this._handleCloseEvent = (event) => {
|
|
1441
1457
|
logger$1.info(`live room closed bacause of ${event.code}-${event.reason || parseWSClsErr(event.code)}`);
|
|
1442
|
-
this.state = LiveState.CLOSED;
|
|
1458
|
+
this.state = exports.LiveState.CLOSED;
|
|
1443
1459
|
};
|
|
1444
1460
|
/**
|
|
1445
1461
|
* 连接中
|
|
@@ -1447,7 +1463,7 @@ class LiveController extends Subscribe {
|
|
|
1447
1463
|
*/
|
|
1448
1464
|
this._handleConnectingEvent = (event) => {
|
|
1449
1465
|
logger$1.info(`live room is connecting`, event.detail);
|
|
1450
|
-
this.state = LiveState.CONNECTING;
|
|
1466
|
+
this.state = exports.LiveState.CONNECTING;
|
|
1451
1467
|
};
|
|
1452
1468
|
/**
|
|
1453
1469
|
* 连接发送异常
|
|
@@ -1455,7 +1471,7 @@ class LiveController extends Subscribe {
|
|
|
1455
1471
|
*/
|
|
1456
1472
|
this._handleErrorEvent = (event) => {
|
|
1457
1473
|
logger$1.error(`live room error`, event);
|
|
1458
|
-
this.state = LiveState.CLOSED;
|
|
1474
|
+
this.state = exports.LiveState.CLOSED;
|
|
1459
1475
|
};
|
|
1460
1476
|
/**
|
|
1461
1477
|
* 接收到消息
|
|
@@ -1479,7 +1495,7 @@ class LiveController extends Subscribe {
|
|
|
1479
1495
|
*/
|
|
1480
1496
|
this._handleOpenEvent = (event) => {
|
|
1481
1497
|
logger$1.info('live room open', event.detail);
|
|
1482
|
-
this.state = LiveState.OPEN;
|
|
1498
|
+
this.state = exports.LiveState.OPEN;
|
|
1483
1499
|
};
|
|
1484
1500
|
/**
|
|
1485
1501
|
* 处理超时
|
|
@@ -1487,7 +1503,7 @@ class LiveController extends Subscribe {
|
|
|
1487
1503
|
*/
|
|
1488
1504
|
this._handleTimeoutEvent = (event) => {
|
|
1489
1505
|
logger$1.error('live room connect timeout!', event.detail);
|
|
1490
|
-
this.state = LiveState.CLOSED;
|
|
1506
|
+
this.state = exports.LiveState.CLOSED;
|
|
1491
1507
|
};
|
|
1492
1508
|
/**
|
|
1493
1509
|
* 释放资源,释放之后需要重新实例化
|
|
@@ -1530,7 +1546,7 @@ class LiveController extends Subscribe {
|
|
|
1530
1546
|
if (data === undefined || data === null || data === '') {
|
|
1531
1547
|
throw new Error('live message is empty!');
|
|
1532
1548
|
}
|
|
1533
|
-
if (this.state === LiveState.OPEN) {
|
|
1549
|
+
if (this.state === exports.LiveState.OPEN) {
|
|
1534
1550
|
return this._ws.send(JSON.stringify(data));
|
|
1535
1551
|
}
|
|
1536
1552
|
else {
|
|
@@ -1583,7 +1599,7 @@ class Live extends Subscribe {
|
|
|
1583
1599
|
* @returns
|
|
1584
1600
|
*/
|
|
1585
1601
|
this.sendKeyframe = (key, frame) => {
|
|
1586
|
-
if (this.state !== LiveState.OPEN)
|
|
1602
|
+
if (this.state !== exports.LiveState.OPEN)
|
|
1587
1603
|
return false;
|
|
1588
1604
|
this._buildInData.keyframes = Object.assign(Object.assign({}, this._buildInData.keyframes), { [key]: frame });
|
|
1589
1605
|
const liveMsg = createLiveMsg(exports.Command.KeyframeSync, this.snapshot);
|
|
@@ -1793,8 +1809,8 @@ class Live extends Subscribe {
|
|
|
1793
1809
|
const { force = false } = options;
|
|
1794
1810
|
// 检查是否已有实例在使用
|
|
1795
1811
|
const currentState = this.state;
|
|
1796
|
-
if (currentState === LiveState.CONNECTING ||
|
|
1797
|
-
currentState === LiveState.OPEN) {
|
|
1812
|
+
if (currentState === exports.LiveState.CONNECTING ||
|
|
1813
|
+
currentState === exports.LiveState.OPEN) {
|
|
1798
1814
|
if (force) {
|
|
1799
1815
|
try {
|
|
1800
1816
|
yield this._controller.close('force close by connect');
|
|
@@ -2080,7 +2096,7 @@ class Live extends Subscribe {
|
|
|
2080
2096
|
*/
|
|
2081
2097
|
updateStatus(evtType, atnType, status, toUserIds) {
|
|
2082
2098
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2083
|
-
if (this.state !== LiveState.OPEN)
|
|
2099
|
+
if (this.state !== exports.LiveState.OPEN)
|
|
2084
2100
|
return false;
|
|
2085
2101
|
const data = Object.assign({ event_type: evtType, action: atnType }, { data: status });
|
|
2086
2102
|
const liveMsg = createLiveMsg(exports.Command.BuiltinMsg, data, toUserIds);
|
|
@@ -2102,7 +2118,7 @@ class Live extends Subscribe {
|
|
|
2102
2118
|
* @returns
|
|
2103
2119
|
*/
|
|
2104
2120
|
broadcast(request, toUserIds, timeout) {
|
|
2105
|
-
if (this.state !== LiveState.OPEN)
|
|
2121
|
+
if (this.state !== exports.LiveState.OPEN)
|
|
2106
2122
|
return false;
|
|
2107
2123
|
return new Promise((resolve, reject) => {
|
|
2108
2124
|
const customEvent = createLiveMsg(exports.Command.CustomEvent, request, toUserIds);
|