@realsee/live 0.5.0-alpha.2 → 0.5.0-alpha.5
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 +2 -0
- package/dist/live/live.d.ts +14 -1
- package/dist/realsee-live.cjs.development.js +68 -16
- 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 +68 -16
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +85 -17
- 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 +4 -0
- package/package.json +2 -2
package/dist/realsee-live.esm.js
CHANGED
|
@@ -1228,7 +1228,12 @@ class RobustWebSocket extends Subscribe {
|
|
|
1228
1228
|
* @param data
|
|
1229
1229
|
* @returns
|
|
1230
1230
|
*/
|
|
1231
|
-
this.send = (data) => {
|
|
1231
|
+
this.send = (data) => {
|
|
1232
|
+
var _a, _b, _c;
|
|
1233
|
+
if (((_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ((_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.OPEN)) {
|
|
1234
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.send(data);
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1232
1237
|
/**
|
|
1233
1238
|
* 关闭连接
|
|
1234
1239
|
* @param code 代码
|
|
@@ -1272,6 +1277,7 @@ class RobustWebSocket extends Subscribe {
|
|
|
1272
1277
|
if (!newUrl)
|
|
1273
1278
|
return;
|
|
1274
1279
|
this._pendingReconnect = undefined;
|
|
1280
|
+
this._removeWebSocketEvent();
|
|
1275
1281
|
this._realWebSocket = new WebSocket(newUrl, this._protocols || undefined);
|
|
1276
1282
|
this._attempts = this._attempts + 1;
|
|
1277
1283
|
this.emit('connecting', new CustomEvent('connecting', {
|
|
@@ -1293,6 +1299,16 @@ class RobustWebSocket extends Subscribe {
|
|
|
1293
1299
|
this._attachConnectivityEvents();
|
|
1294
1300
|
}
|
|
1295
1301
|
};
|
|
1302
|
+
/**
|
|
1303
|
+
* 断开ws事件
|
|
1304
|
+
*/
|
|
1305
|
+
this._removeWebSocketEvent = () => {
|
|
1306
|
+
var _a, _b, _c, _d;
|
|
1307
|
+
(_a = this._realWebSocket) === null || _a === void 0 ? void 0 : _a.removeEventListener('open', this._webSocketOpenHandler);
|
|
1308
|
+
(_b = this._realWebSocket) === null || _b === void 0 ? void 0 : _b.removeEventListener('close', this._webSocketCloseHandler);
|
|
1309
|
+
(_c = this._realWebSocket) === null || _c === void 0 ? void 0 : _c.removeEventListener('error', this._webSocketErrorHandler);
|
|
1310
|
+
(_d = this._realWebSocket) === null || _d === void 0 ? void 0 : _d.removeEventListener('message', this._webSocketMessageHandler);
|
|
1311
|
+
};
|
|
1296
1312
|
/**
|
|
1297
1313
|
* 分发ws事件
|
|
1298
1314
|
*/
|
|
@@ -1470,6 +1486,9 @@ class LiveController extends Subscribe {
|
|
|
1470
1486
|
this._handleOpenEvent = (event) => {
|
|
1471
1487
|
logger$1.info('live room open', event.detail);
|
|
1472
1488
|
this.state = LiveState.OPEN;
|
|
1489
|
+
if (event.detail.reconnects > 0) {
|
|
1490
|
+
this.emit('reconnected', event.detail);
|
|
1491
|
+
}
|
|
1473
1492
|
};
|
|
1474
1493
|
/**
|
|
1475
1494
|
* 处理超时
|
|
@@ -1596,6 +1615,7 @@ class Live extends Subscribe {
|
|
|
1596
1615
|
this._addLiveControllerEventListeners = () => {
|
|
1597
1616
|
this._controller.on('stateChange', this._handleStateChange);
|
|
1598
1617
|
this._controller.on('message', this._handleMessage);
|
|
1618
|
+
this._controller.on('reconnected', this._handleReconnected);
|
|
1599
1619
|
};
|
|
1600
1620
|
/**
|
|
1601
1621
|
* 移除带看控制的事件监听
|
|
@@ -1603,6 +1623,7 @@ class Live extends Subscribe {
|
|
|
1603
1623
|
this._removeLiveControllerEventListeners = () => {
|
|
1604
1624
|
this._controller.off('stateChange', this._handleStateChange);
|
|
1605
1625
|
this._controller.off('message', this._handleMessage);
|
|
1626
|
+
this._controller.off('reconnected', this._handleReconnected);
|
|
1606
1627
|
};
|
|
1607
1628
|
/**
|
|
1608
1629
|
* 带看状态变化
|
|
@@ -1610,6 +1631,10 @@ class Live extends Subscribe {
|
|
|
1610
1631
|
* @returns
|
|
1611
1632
|
*/
|
|
1612
1633
|
this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
|
|
1634
|
+
/**
|
|
1635
|
+
* 消息接收
|
|
1636
|
+
* @param liveMsg
|
|
1637
|
+
*/
|
|
1613
1638
|
this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
1614
1639
|
var _b, _c, _d, _e, _f, _g;
|
|
1615
1640
|
if (typeof liveMsg === 'object') {
|
|
@@ -1641,6 +1666,7 @@ class Live extends Subscribe {
|
|
|
1641
1666
|
*/
|
|
1642
1667
|
case Command.RTCInfo: {
|
|
1643
1668
|
const { voice_id: voiceId, type } = data;
|
|
1669
|
+
this._buildInData.rtcInfo = { voiceId, type };
|
|
1644
1670
|
if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
|
|
1645
1671
|
const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
|
|
1646
1672
|
voiceId,
|
|
@@ -1752,6 +1778,32 @@ class Live extends Subscribe {
|
|
|
1752
1778
|
}
|
|
1753
1779
|
}
|
|
1754
1780
|
});
|
|
1781
|
+
/**
|
|
1782
|
+
* 处理重连
|
|
1783
|
+
* @param detail
|
|
1784
|
+
*/
|
|
1785
|
+
this._handleReconnected = (detail) => __awaiter(this, void 0, void 0, function* () {
|
|
1786
|
+
var _h, _j, _k, _l, _m, _o, _p;
|
|
1787
|
+
// 已经重连上ws,尝试重连语音
|
|
1788
|
+
this.$RTC.joined = false;
|
|
1789
|
+
const { rtcInfo } = this._buildInData;
|
|
1790
|
+
if (rtcInfo) {
|
|
1791
|
+
const { voiceId, type } = rtcInfo;
|
|
1792
|
+
const result = yield ((_h = this.$RTC) === null || _h === void 0 ? void 0 : _h.join({
|
|
1793
|
+
voiceId,
|
|
1794
|
+
userId: ((_j = this.selfInfo) === null || _j === void 0 ? void 0 : _j.id) || '',
|
|
1795
|
+
roomId: (_k = this.roomInfo) === null || _k === void 0 ? void 0 : _k.info.room_code,
|
|
1796
|
+
type,
|
|
1797
|
+
}));
|
|
1798
|
+
if (result) {
|
|
1799
|
+
const status = (_o = (_m = (_l = this.selfInfo) === null || _l === void 0 ? void 0 : _l.micro_status) !== null && _m !== void 0 ? _m : this._options.initialMicroStatus) !== null && _o !== void 0 ? _o : MicroStatus.OPEN;
|
|
1800
|
+
yield ((_p = this.$RTC) === null || _p === void 0 ? void 0 : _p.toggleMicro(status === MicroStatus.OPEN));
|
|
1801
|
+
}
|
|
1802
|
+
else {
|
|
1803
|
+
logger$1.error('加入语音房间失败');
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
});
|
|
1755
1807
|
/**
|
|
1756
1808
|
* 清理带看缓存的数据
|
|
1757
1809
|
*/
|
|
@@ -1764,12 +1816,12 @@ class Live extends Subscribe {
|
|
|
1764
1816
|
* @returns
|
|
1765
1817
|
*/
|
|
1766
1818
|
this.connect = (options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
1767
|
-
var
|
|
1819
|
+
var _q, _r, _s, _t;
|
|
1768
1820
|
// 检查 url 和 票据获取接口实现
|
|
1769
|
-
this._options.url = (
|
|
1770
|
-
this._options.getTicket = (
|
|
1821
|
+
this._options.url = (_r = (_q = options.url) !== null && _q !== void 0 ? _q : this._options.url) !== null && _r !== void 0 ? _r : '';
|
|
1822
|
+
this._options.getTicket = (_s = options.getTicket) !== null && _s !== void 0 ? _s : this._options.getTicket;
|
|
1771
1823
|
this._options.initialMicroStatus =
|
|
1772
|
-
(
|
|
1824
|
+
(_t = options.rtcMicStatus) !== null && _t !== void 0 ? _t : this._options.initialMicroStatus;
|
|
1773
1825
|
if (!/^ws(s):\/\//.test(this._options.url) ||
|
|
1774
1826
|
typeof this._options.getTicket !== 'function') {
|
|
1775
1827
|
if (!/^ws(s):\/\//.test(this._options.url)) {
|
|
@@ -1811,11 +1863,11 @@ class Live extends Subscribe {
|
|
|
1811
1863
|
* @returns
|
|
1812
1864
|
*/
|
|
1813
1865
|
this.exit = () => __awaiter(this, void 0, void 0, function* () {
|
|
1814
|
-
var
|
|
1866
|
+
var _u;
|
|
1815
1867
|
this._clearLiveData();
|
|
1816
1868
|
try {
|
|
1817
1869
|
/** 退出强制关闭语音 */
|
|
1818
|
-
(
|
|
1870
|
+
(_u = this.$RTC) === null || _u === void 0 ? void 0 : _u.quit();
|
|
1819
1871
|
yield this.updateStatus(BuiltinEventType.RoomChange, BuiltinActionType.RoomClose, {});
|
|
1820
1872
|
}
|
|
1821
1873
|
catch (e) {
|
|
@@ -1842,10 +1894,10 @@ class Live extends Subscribe {
|
|
|
1842
1894
|
});
|
|
1843
1895
|
// 仅用于用户自己的麦克风控制
|
|
1844
1896
|
this.toggleMicro = (microStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
1845
|
-
var
|
|
1846
|
-
if (!((
|
|
1897
|
+
var _v, _w, _x;
|
|
1898
|
+
if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.control_own_micro))
|
|
1847
1899
|
return false;
|
|
1848
|
-
const result = yield ((
|
|
1900
|
+
const result = yield ((_x = this.$RTC) === null || _x === void 0 ? void 0 : _x.toggleMicro(microStatus));
|
|
1849
1901
|
if (result) {
|
|
1850
1902
|
yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
1851
1903
|
status: microStatus ? MicroStatus.OPEN : MicroStatus.CLOSE,
|
|
@@ -1860,12 +1912,12 @@ class Live extends Subscribe {
|
|
|
1860
1912
|
* @returns
|
|
1861
1913
|
*/
|
|
1862
1914
|
this.forbidMicro = (microStatus, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1863
|
-
var
|
|
1915
|
+
var _y, _z;
|
|
1864
1916
|
if (typeof this._options.canForbidUserMicro === 'function' &&
|
|
1865
1917
|
!this._options.canForbidUserMicro(toUserIds)) {
|
|
1866
1918
|
return false;
|
|
1867
1919
|
}
|
|
1868
|
-
if (!((
|
|
1920
|
+
if (!((_z = (_y = this.selfInfo) === null || _y === void 0 ? void 0 : _y.permission) === null || _z === void 0 ? void 0 : _z.control_other_micro)) {
|
|
1869
1921
|
return false;
|
|
1870
1922
|
}
|
|
1871
1923
|
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserMicroStatus, {
|
|
@@ -1879,12 +1931,12 @@ class Live extends Subscribe {
|
|
|
1879
1931
|
* @returns
|
|
1880
1932
|
*/
|
|
1881
1933
|
this.forbidSync = (sync, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1882
|
-
var
|
|
1934
|
+
var _0, _1;
|
|
1883
1935
|
if (typeof this._options.canForbidUserSync === 'function' &&
|
|
1884
1936
|
!this._options.canForbidUserSync(toUserIds)) {
|
|
1885
1937
|
return false;
|
|
1886
1938
|
}
|
|
1887
|
-
if (!((
|
|
1939
|
+
if (!((_1 = (_0 = this.selfInfo) === null || _0 === void 0 ? void 0 : _0.permission) === null || _1 === void 0 ? void 0 : _1.control_other_sync)) {
|
|
1888
1940
|
return false;
|
|
1889
1941
|
}
|
|
1890
1942
|
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
|
|
@@ -1895,12 +1947,12 @@ class Live extends Subscribe {
|
|
|
1895
1947
|
* @returns
|
|
1896
1948
|
*/
|
|
1897
1949
|
this.kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1898
|
-
var
|
|
1950
|
+
var _2, _3;
|
|
1899
1951
|
if (typeof this._options.canForbidUserKick === 'function' &&
|
|
1900
1952
|
!this._options.canForbidUserKick(toUserIds)) {
|
|
1901
1953
|
return false;
|
|
1902
1954
|
}
|
|
1903
|
-
if (!((
|
|
1955
|
+
if (!((_3 = (_2 = this.selfInfo) === null || _2 === void 0 ? void 0 : _2.permission) === null || _3 === void 0 ? void 0 : _3.change_other_status)) {
|
|
1904
1956
|
return false;
|
|
1905
1957
|
}
|
|
1906
1958
|
return yield this.updateStatus(BuiltinEventType.UserChange, BuiltinActionType.UserStatus, {
|