@realsee/live 0.5.0-alpha.4 → 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 +51 -15
- 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 +51 -15
- package/dist/realsee-live.esm.js.map +1 -1
- package/dist/realsee-live.umd.development.js +51 -15
- 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/package.json +1 -1
|
@@ -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
|
*/
|
|
@@ -1496,6 +1496,9 @@ class LiveController extends Subscribe {
|
|
|
1496
1496
|
this._handleOpenEvent = (event) => {
|
|
1497
1497
|
logger$1.info('live room open', event.detail);
|
|
1498
1498
|
this.state = exports.LiveState.OPEN;
|
|
1499
|
+
if (event.detail.reconnects > 0) {
|
|
1500
|
+
this.emit('reconnected', event.detail);
|
|
1501
|
+
}
|
|
1499
1502
|
};
|
|
1500
1503
|
/**
|
|
1501
1504
|
* 处理超时
|
|
@@ -1622,6 +1625,7 @@ class Live extends Subscribe {
|
|
|
1622
1625
|
this._addLiveControllerEventListeners = () => {
|
|
1623
1626
|
this._controller.on('stateChange', this._handleStateChange);
|
|
1624
1627
|
this._controller.on('message', this._handleMessage);
|
|
1628
|
+
this._controller.on('reconnected', this._handleReconnected);
|
|
1625
1629
|
};
|
|
1626
1630
|
/**
|
|
1627
1631
|
* 移除带看控制的事件监听
|
|
@@ -1629,6 +1633,7 @@ class Live extends Subscribe {
|
|
|
1629
1633
|
this._removeLiveControllerEventListeners = () => {
|
|
1630
1634
|
this._controller.off('stateChange', this._handleStateChange);
|
|
1631
1635
|
this._controller.off('message', this._handleMessage);
|
|
1636
|
+
this._controller.off('reconnected', this._handleReconnected);
|
|
1632
1637
|
};
|
|
1633
1638
|
/**
|
|
1634
1639
|
* 带看状态变化
|
|
@@ -1636,6 +1641,10 @@ class Live extends Subscribe {
|
|
|
1636
1641
|
* @returns
|
|
1637
1642
|
*/
|
|
1638
1643
|
this._handleStateChange = (state, prevState) => this.emit('stateChange', state, prevState);
|
|
1644
|
+
/**
|
|
1645
|
+
* 消息接收
|
|
1646
|
+
* @param liveMsg
|
|
1647
|
+
*/
|
|
1639
1648
|
this._handleMessage = (liveMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
1640
1649
|
var _b, _c, _d, _e, _f, _g;
|
|
1641
1650
|
if (typeof liveMsg === 'object') {
|
|
@@ -1667,6 +1676,7 @@ class Live extends Subscribe {
|
|
|
1667
1676
|
*/
|
|
1668
1677
|
case exports.Command.RTCInfo: {
|
|
1669
1678
|
const { voice_id: voiceId, type } = data;
|
|
1679
|
+
this._buildInData.rtcInfo = { voiceId, type };
|
|
1670
1680
|
if (!((_b = this.$RTC) === null || _b === void 0 ? void 0 : _b.joined)) {
|
|
1671
1681
|
const result = yield ((_c = this.$RTC) === null || _c === void 0 ? void 0 : _c.join({
|
|
1672
1682
|
voiceId,
|
|
@@ -1778,6 +1788,32 @@ class Live extends Subscribe {
|
|
|
1778
1788
|
}
|
|
1779
1789
|
}
|
|
1780
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
|
+
});
|
|
1781
1817
|
/**
|
|
1782
1818
|
* 清理带看缓存的数据
|
|
1783
1819
|
*/
|
|
@@ -1790,12 +1826,12 @@ class Live extends Subscribe {
|
|
|
1790
1826
|
* @returns
|
|
1791
1827
|
*/
|
|
1792
1828
|
this.connect = (options = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
1793
|
-
var
|
|
1829
|
+
var _q, _r, _s, _t;
|
|
1794
1830
|
// 检查 url 和 票据获取接口实现
|
|
1795
|
-
this._options.url = (
|
|
1796
|
-
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;
|
|
1797
1833
|
this._options.initialMicroStatus =
|
|
1798
|
-
(
|
|
1834
|
+
(_t = options.rtcMicStatus) !== null && _t !== void 0 ? _t : this._options.initialMicroStatus;
|
|
1799
1835
|
if (!/^ws(s):\/\//.test(this._options.url) ||
|
|
1800
1836
|
typeof this._options.getTicket !== 'function') {
|
|
1801
1837
|
if (!/^ws(s):\/\//.test(this._options.url)) {
|
|
@@ -1837,11 +1873,11 @@ class Live extends Subscribe {
|
|
|
1837
1873
|
* @returns
|
|
1838
1874
|
*/
|
|
1839
1875
|
this.exit = () => __awaiter(this, void 0, void 0, function* () {
|
|
1840
|
-
var
|
|
1876
|
+
var _u;
|
|
1841
1877
|
this._clearLiveData();
|
|
1842
1878
|
try {
|
|
1843
1879
|
/** 退出强制关闭语音 */
|
|
1844
|
-
(
|
|
1880
|
+
(_u = this.$RTC) === null || _u === void 0 ? void 0 : _u.quit();
|
|
1845
1881
|
yield this.updateStatus(exports.BuiltinEventType.RoomChange, exports.BuiltinActionType.RoomClose, {});
|
|
1846
1882
|
}
|
|
1847
1883
|
catch (e) {
|
|
@@ -1868,10 +1904,10 @@ class Live extends Subscribe {
|
|
|
1868
1904
|
});
|
|
1869
1905
|
// 仅用于用户自己的麦克风控制
|
|
1870
1906
|
this.toggleMicro = (microStatus) => __awaiter(this, void 0, void 0, function* () {
|
|
1871
|
-
var
|
|
1872
|
-
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))
|
|
1873
1909
|
return false;
|
|
1874
|
-
const result = yield ((
|
|
1910
|
+
const result = yield ((_x = this.$RTC) === null || _x === void 0 ? void 0 : _x.toggleMicro(microStatus));
|
|
1875
1911
|
if (result) {
|
|
1876
1912
|
yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
1877
1913
|
status: microStatus ? exports.MicroStatus.OPEN : exports.MicroStatus.CLOSE,
|
|
@@ -1886,12 +1922,12 @@ class Live extends Subscribe {
|
|
|
1886
1922
|
* @returns
|
|
1887
1923
|
*/
|
|
1888
1924
|
this.forbidMicro = (microStatus, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1889
|
-
var
|
|
1925
|
+
var _y, _z;
|
|
1890
1926
|
if (typeof this._options.canForbidUserMicro === 'function' &&
|
|
1891
1927
|
!this._options.canForbidUserMicro(toUserIds)) {
|
|
1892
1928
|
return false;
|
|
1893
1929
|
}
|
|
1894
|
-
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)) {
|
|
1895
1931
|
return false;
|
|
1896
1932
|
}
|
|
1897
1933
|
return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserMicroStatus, {
|
|
@@ -1905,12 +1941,12 @@ class Live extends Subscribe {
|
|
|
1905
1941
|
* @returns
|
|
1906
1942
|
*/
|
|
1907
1943
|
this.forbidSync = (sync, toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1908
|
-
var
|
|
1944
|
+
var _0, _1;
|
|
1909
1945
|
if (typeof this._options.canForbidUserSync === 'function' &&
|
|
1910
1946
|
!this._options.canForbidUserSync(toUserIds)) {
|
|
1911
1947
|
return false;
|
|
1912
1948
|
}
|
|
1913
|
-
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)) {
|
|
1914
1950
|
return false;
|
|
1915
1951
|
}
|
|
1916
1952
|
return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserPermission, { sync_frame: sync }, toUserIds);
|
|
@@ -1921,12 +1957,12 @@ class Live extends Subscribe {
|
|
|
1921
1957
|
* @returns
|
|
1922
1958
|
*/
|
|
1923
1959
|
this.kick = (toUserIds) => __awaiter(this, void 0, void 0, function* () {
|
|
1924
|
-
var
|
|
1960
|
+
var _2, _3;
|
|
1925
1961
|
if (typeof this._options.canForbidUserKick === 'function' &&
|
|
1926
1962
|
!this._options.canForbidUserKick(toUserIds)) {
|
|
1927
1963
|
return false;
|
|
1928
1964
|
}
|
|
1929
|
-
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)) {
|
|
1930
1966
|
return false;
|
|
1931
1967
|
}
|
|
1932
1968
|
return yield this.updateStatus(exports.BuiltinEventType.UserChange, exports.BuiltinActionType.UserStatus, {
|