@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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { LiveMsg } from '../typings';
|
|
2
2
|
import { LiveState } from '../typings/live/LiveState';
|
|
3
|
+
import { RobustWebSocketEventDetail } from '../utils/RobustWebSocket';
|
|
3
4
|
import { Subscribe } from '../utils/subscribe';
|
|
4
5
|
export declare type LiveControllerEventMap = {
|
|
5
6
|
stateChange: (state: LiveState, prevState: LiveState) => void;
|
|
6
7
|
message: (message: LiveMsg) => void;
|
|
8
|
+
reconnected: (detail: RobustWebSocketEventDetail) => void;
|
|
7
9
|
};
|
|
8
10
|
export declare class LiveController extends Subscribe<LiveControllerEventMap> {
|
|
9
11
|
/**
|
package/dist/live/live.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { JSBridgeProtocol } from '@realsee/jsbridge-x';
|
|
2
2
|
import { RTCProtocol } from '../rtc';
|
|
3
|
-
import { EventType, KeyframeTypes, LiveOptions, RoomInfo, UserInfo, BuiltinEventType, BuiltinActionType, MicroStatus, LiveConnectOptions } from '../typings';
|
|
3
|
+
import { EventType, KeyframeTypes, LiveOptions, RoomInfo, RTCType, UserInfo, BuiltinEventType, BuiltinActionType, MicroStatus, LiveConnectOptions } from '../typings';
|
|
4
4
|
import { LiveState } from '../typings/live/LiveState';
|
|
5
5
|
import { Subscribe } from '../utils/subscribe';
|
|
6
6
|
export declare type LiveBuiltInData<KeyframesSnapshot> = {
|
|
7
7
|
selfInfo?: UserInfo;
|
|
8
8
|
userList?: UserInfo[];
|
|
9
9
|
roomInfo?: RoomInfo;
|
|
10
|
+
rtcInfo?: {
|
|
11
|
+
voiceId: string;
|
|
12
|
+
type: RTCType;
|
|
13
|
+
};
|
|
10
14
|
keyframes: Partial<KeyframesSnapshot>;
|
|
11
15
|
};
|
|
12
16
|
export declare const _clearLiveInstanceIfNeed: () => void;
|
|
@@ -94,7 +98,16 @@ export declare class Live<KeyframesSnapshot extends Record<string, any>> extends
|
|
|
94
98
|
* @returns
|
|
95
99
|
*/
|
|
96
100
|
private _handleStateChange;
|
|
101
|
+
/**
|
|
102
|
+
* 消息接收
|
|
103
|
+
* @param liveMsg
|
|
104
|
+
*/
|
|
97
105
|
private _handleMessage;
|
|
106
|
+
/**
|
|
107
|
+
* 处理重连
|
|
108
|
+
* @param detail
|
|
109
|
+
*/
|
|
110
|
+
private _handleReconnected;
|
|
98
111
|
/**
|
|
99
112
|
* 清理带看缓存的数据
|
|
100
113
|
*/
|
|
@@ -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
|
*/
|
|
@@ -1480,6 +1496,9 @@ class LiveController extends Subscribe {
|
|
|
1480
1496
|
this._handleOpenEvent = (event) => {
|
|
1481
1497
|
logger$1.info('live room open', event.detail);
|
|
1482
1498
|
this.state = exports.LiveState.OPEN;
|
|
1499
|
+
if (event.detail.reconnects > 0) {
|
|
1500
|
+
this.emit('reconnected', event.detail);
|
|
1501
|
+
}
|
|
1483
1502
|
};
|
|
1484
1503
|
/**
|
|
1485
1504
|
* 处理超时
|
|
@@ -1606,6 +1625,7 @@ class Live extends Subscribe {
|
|
|
1606
1625
|
this._addLiveControllerEventListeners = () => {
|
|
1607
1626
|
this._controller.on('stateChange', this._handleStateChange);
|
|
1608
1627
|
this._controller.on('message', this._handleMessage);
|
|
1628
|
+
this._controller.on('reconnected', this._handleReconnected);
|
|
1609
1629
|
};
|
|
1610
1630
|
/**
|
|
1611
1631
|
* 移除带看控制的事件监听
|
|
@@ -1613,6 +1633,7 @@ class Live extends Subscribe {
|
|
|
1613
1633
|
this._removeLiveControllerEventListeners = () => {
|
|
1614
1634
|
this._controller.off('stateChange', this._handleStateChange);
|
|
1615
1635
|
this._controller.off('message', this._handleMessage);
|
|
1636
|
+
this._controller.off('reconnected', this._handleReconnected);
|
|
1616
1637
|
};
|
|
1617
1638
|
/**
|
|
1618
1639
|
* 带看状态变化
|
|
@@ -1620,6 +1641,10 @@ class Live extends Subscribe {
|
|
|
1620
1641
|
* @returns
|
|
1621
1642
|
*/
|
|
1622
1643
|
this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
|
|
1644
|
+
/**
|
|
1645
|
+
* 消息接收
|
|
1646
|
+
* @param liveMsg
|
|
1647
|
+
*/
|
|
1623
1648
|
this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
1624
1649
|
var _b, _c, _d, _e, _f, _g;
|
|
1625
1650
|
if (typeof liveMsg === 'object') {
|
|
@@ -1651,6 +1676,7 @@ class Live extends Subscribe {
|
|
|
1651
1676
|
*/
|
|
1652
1677
|
case exports.Command.RTCInfo: {
|
|
1653
1678
|
const { voice_id: voiceId, type } = data;
|
|
1679
|
+
this._buildInData.rtcInfo = { voiceId, type };
|
|
1654
1680
|
if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
|
|
1655
1681
|
const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
|
|
1656
1682
|
voiceId,
|
|
@@ -1762,6 +1788,32 @@ class Live extends Subscribe {
|
|
|
1762
1788
|
}
|
|
1763
1789
|
}
|
|
1764
1790
|
});
|
|
1791
|
+
/**
|
|
1792
|
+
* 处理重连
|
|
1793
|
+
* @param detail
|
|
1794
|
+
*/
|
|
1795
|
+
this._handleReconnected = (detail) => __awaiter(this, void 0, void 0, function* () {
|
|
1796
|
+
var _h, _j, _k, _l, _m, _o, _p;
|
|
1797
|
+
// 已经重连上ws,尝试重连语音
|
|
1798
|
+
this.$RTC.joined = false;
|
|
1799
|
+
const { rtcInfo } = this._buildInData;
|
|
1800
|
+
if (rtcInfo) {
|
|
1801
|
+
const { voiceId, type } = rtcInfo;
|
|
1802
|
+
const result = yield ((_h = this.$RTC) === null || _h === void 0 ? void 0 : _h.join({
|
|
1803
|
+
voiceId,
|
|
1804
|
+
userId: ((_j = this.selfInfo) === null || _j === void 0 ? void 0 : _j.id) || '',
|
|
1805
|
+
roomId: (_k = this.roomInfo) === null || _k === void 0 ? void 0 : _k.info.room_code,
|
|
1806
|
+
type,
|
|
1807
|
+
}));
|
|
1808
|
+
if (result) {
|
|
1809
|
+
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 : exports.MicroStatus.OPEN;
|
|
1810
|
+
yield ((_p = this.$RTC) === null || _p === void 0 ? void 0 : _p.toggleMicro(status === exports.MicroStatus.OPEN));
|
|
1811
|
+
}
|
|
1812
|
+
else {
|
|
1813
|
+
logger$1.error('加入语音房间失败');
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
});
|
|
1765
1817
|
/**
|
|
1766
1818
|
* 清理带看缓存的数据
|
|
1767
1819
|
*/
|
|
@@ -1774,12 +1826,12 @@ class Live extends Subscribe {
|
|
|
1774
1826
|
* @returns
|
|
1775
1827
|
*/
|
|
1776
1828
|
this.connect = (options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
1777
|
-
var
|
|
1829
|
+
var _q, _r, _s, _t;
|
|
1778
1830
|
// 检查 url 和 票据获取接口实现
|
|
1779
|
-
this._options.url = (
|
|
1780
|
-
this._options.getTicket = (
|
|
1831
|
+
this._options.url = (_r = (_q = options.url) !== null && _q !== void 0 ? _q : this._options.url) !== null && _r !== void 0 ? _r : '';
|
|
1832
|
+
this._options.getTicket = (_s = options.getTicket) !== null && _s !== void 0 ? _s : this._options.getTicket;
|
|
1781
1833
|
this._options.initialMicroStatus =
|
|
1782
|
-
(
|
|
1834
|
+
(_t = options.rtcMicStatus) !== null && _t !== void 0 ? _t : this._options.initialMicroStatus;
|
|
1783
1835
|
if (!/^ws(s):\/\//.test(this._options.url) ||
|
|
1784
1836
|
typeof this._options.getTicket !== 'function') {
|
|
1785
1837
|
if (!/^ws(s):\/\//.test(this._options.url)) {
|
|
@@ -1821,11 +1873,11 @@ class Live extends Subscribe {
|
|
|
1821
1873
|
* @returns
|
|
1822
1874
|
*/
|
|
1823
1875
|
this.exit = () => __awaiter(this, void 0, void 0, function* () {
|
|
1824
|
-
var
|
|
1876
|
+
var _u;
|
|
1825
1877
|
this._clearLiveData();
|
|
1826
1878
|
try {
|
|
1827
1879
|
/** 退出强制关闭语音 */
|
|
1828
|
-
(
|
|
1880
|
+
(_u = this.$RTC) === null || _u === void 0 ? void 0 : _u.quit();
|
|
1829
1881
|
yield this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {});
|
|
1830
1882
|
}
|
|
1831
1883
|
catch (e) {
|
|
@@ -1852,10 +1904,10 @@ class Live extends Subscribe {
|
|
|
1852
1904
|
});
|
|
1853
1905
|
// 仅用于用户自己的麦克风控制
|
|
1854
1906
|
this.toggleMicro = (microStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
1855
|
-
var
|
|
1856
|
-
if (!((
|
|
1907
|
+
var _v, _w, _x;
|
|
1908
|
+
if (!((_w = (_v = this.selfInfo) === null || _v === void 0 ? void 0 : _v.permission) === null || _w === void 0 ? void 0 : _w.control_own_micro))
|
|
1857
1909
|
return false;
|
|
1858
|
-
const result = yield ((
|
|
1910
|
+
const result = yield ((_x = this.$RTC) === null || _x === void 0 ? void 0 : _x.toggleMicro(microStatus));
|
|
1859
1911
|
if (result) {
|
|
1860
1912
|
yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
1861
1913
|
status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
|
|
@@ -1870,12 +1922,12 @@ class Live extends Subscribe {
|
|
|
1870
1922
|
* @returns
|
|
1871
1923
|
*/
|
|
1872
1924
|
this.forbidMicro = (microStatus, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1873
|
-
var
|
|
1925
|
+
var _y, _z;
|
|
1874
1926
|
if (typeof this._options.canForbidUserMicro === 'function' &&
|
|
1875
1927
|
!this._options.canForbidUserMicro(toUserIds)) {
|
|
1876
1928
|
return false;
|
|
1877
1929
|
}
|
|
1878
|
-
if (!((
|
|
1930
|
+
if (!((_z = (_y = this.selfInfo) === null || _y === void 0 ? void 0 : _y.permission) === null || _z === void 0 ? void 0 : _z.control_other_micro)) {
|
|
1879
1931
|
return false;
|
|
1880
1932
|
}
|
|
1881
1933
|
return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
@@ -1889,12 +1941,12 @@ class Live extends Subscribe {
|
|
|
1889
1941
|
* @returns
|
|
1890
1942
|
*/
|
|
1891
1943
|
this.forbidSync = (sync, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1892
|
-
var
|
|
1944
|
+
var _0, _1;
|
|
1893
1945
|
if (typeof this._options.canForbidUserSync === 'function' &&
|
|
1894
1946
|
!this._options.canForbidUserSync(toUserIds)) {
|
|
1895
1947
|
return false;
|
|
1896
1948
|
}
|
|
1897
|
-
if (!((
|
|
1949
|
+
if (!((_1 = (_0 = this.selfInfo) === null || _0 === void 0 ? void 0 : _0.permission) === null || _1 === void 0 ? void 0 : _1.control_other_sync)) {
|
|
1898
1950
|
return false;
|
|
1899
1951
|
}
|
|
1900
1952
|
return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
|
|
@@ -1905,12 +1957,12 @@ class Live extends Subscribe {
|
|
|
1905
1957
|
* @returns
|
|
1906
1958
|
*/
|
|
1907
1959
|
this.kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1908
|
-
var
|
|
1960
|
+
var _2, _3;
|
|
1909
1961
|
if (typeof this._options.canForbidUserKick === 'function' &&
|
|
1910
1962
|
!this._options.canForbidUserKick(toUserIds)) {
|
|
1911
1963
|
return false;
|
|
1912
1964
|
}
|
|
1913
|
-
if (!((
|
|
1965
|
+
if (!((_3 = (_2 = this.selfInfo) === null || _2 === void 0 ? void 0 : _2.permission) === null || _3 === void 0 ? void 0 : _3.change_other_status)) {
|
|
1914
1966
|
return false;
|
|
1915
1967
|
}
|
|
1916
1968
|
return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {
|