@realsee/live 0.7.3-alpha.0 → 0.7.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/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +687 -130
- package/dist/index.es.js.map +1 -1
- package/dist/live/controller.d.ts +163 -42
- package/dist/live/createLive.d.ts +35 -3
- package/dist/live/createLiveReact.d.ts +51 -3
- package/dist/live/live.d.ts +501 -50
- package/dist/rtc/BrowserRTC.d.ts +63 -0
- package/dist/rtc/BrowserRTC4Chime.d.ts +38 -2
- package/dist/rtc/CoreRTC.d.ts +65 -1
- package/dist/rtc/VRWebViewRTC.d.ts +56 -6
- package/dist/typings/live/EventType.d.ts +58 -10
- package/dist/typings/live/GetVoiceSign.d.ts +27 -7
- package/dist/typings/live/UserInfo.d.ts +70 -0
- package/dist/typings/rtc/eventType.d.ts +55 -8
- package/dist/utils/appendUri.d.ts +17 -0
- package/dist/utils/uuid.d.ts +11 -1
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +127 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1493 -0
- package/docs/classes/BrowserRTC.html +88 -0
- package/docs/classes/BrowserRTC4Chime.html +100 -0
- package/docs/classes/CoreRTC.html +65 -0
- package/docs/classes/Live.html +249 -0
- package/docs/classes/Subscribe.html +36 -0
- package/docs/classes/VRWebViewRTC.html +72 -0
- package/docs/enums/BuiltInRTCType.html +3 -0
- package/docs/enums/BuiltinActionType.html +14 -0
- package/docs/enums/BuiltinEventType.html +6 -0
- package/docs/enums/Command.html +22 -0
- package/docs/enums/LiveState.html +8 -0
- package/docs/enums/MemUserStatus.html +15 -0
- package/docs/enums/MicroStatus.html +6 -0
- package/docs/enums/RTCJoinedInfoCodeEnum.html +12 -0
- package/docs/enums/RTCType.html +5 -0
- package/docs/enums/UserStatus.html +8 -0
- package/docs/enums/WebSocketCloseError.html +20 -0
- package/docs/enums/WebSocketErrorType.html +8 -0
- package/docs/enums/WebSocketState.html +12 -0
- package/docs/functions/GetVoiceSignFn.html +20 -0
- package/docs/functions/_clearLiveInstanceIfNeed.html +1 -0
- package/docs/functions/createLive.html +9 -0
- package/docs/functions/createLiveReact.html +110 -0
- package/docs/functions/parseLiveMsg.html +4 -0
- package/docs/functions/parseWSClsErr.html +1 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +336 -0
- package/docs/interfaces/AttendeeResponse.html +4 -0
- package/docs/interfaces/LiveOptions.html +56 -0
- package/docs/interfaces/MeetingResponse.html +3 -0
- package/docs/interfaces/MeetingSessionConfigurationOptions.html +8 -0
- package/docs/interfaces/Permission.html +31 -0
- package/docs/interfaces/RTCJoinedInfo.html +7 -0
- package/docs/interfaces/RTCProtocol.html +65 -0
- package/docs/interfaces/SubscribeMixinType.emit.html +1 -0
- package/docs/interfaces/SubscribeMixinType.hasListener.html +1 -0
- package/docs/interfaces/SubscribeMixinType.off.html +1 -0
- package/docs/interfaces/SubscribeMixinType.on.html +1 -0
- package/docs/interfaces/SubscribeMixinType.once.html +1 -0
- package/docs/interfaces/VRWebViewRTCOptions.html +22 -0
- package/docs/modules/SubscribeMixinType.html +6 -0
- package/docs/modules.html +55 -0
- package/docs/types/BuiltinMsg.html +2 -0
- package/docs/types/EventMap.html +1 -0
- package/docs/types/EventType.html +2 -0
- package/docs/types/GetVoiceSign.html +3 -0
- package/docs/types/GetVoiceSignParams.html +5 -0
- package/docs/types/GetVoiceSignReturnType.html +6 -0
- package/docs/types/KeyframeEventType.html +2 -0
- package/docs/types/LiveBuiltInData.html +1 -0
- package/docs/types/LiveConnectOptions.html +8 -0
- package/docs/types/LiveEventType.html +41 -0
- package/docs/types/LiveMsg.html +2 -0
- package/docs/types/LiveProviderPropTypes.html +5 -0
- package/docs/types/RTCActionReactCallback.html +1 -0
- package/docs/types/RTCEventType.html +29 -0
- package/docs/types/ReqLiveMsg.html +6 -0
- package/docs/types/RoomInfo.html +1 -0
- package/docs/types/UserInfo.html +12 -0
- package/docs/types/UserInfoExt.html +5 -0
- package/docs/types/UserVolume.html +2 -0
- package/docs/types/WebSocketError.html +1 -0
- package/package.json +1 -2
- package/docs/README.md +0 -437
- package/docs/classes/BrowserRTC.md +0 -436
- package/docs/classes/BrowserRTC4Chime.md +0 -558
- package/docs/classes/CoreRTC.md +0 -448
- package/docs/classes/Live.md +0 -770
- package/docs/classes/VRWebViewRTC.md +0 -436
- package/docs/enumerations/BuiltInRTCType.md +0 -27
- package/docs/enumerations/BuiltinActionType.md +0 -81
- package/docs/enumerations/BuiltinEventType.md +0 -33
- package/docs/enumerations/Command.md +0 -107
- package/docs/enumerations/LiveState.md +0 -53
- package/docs/enumerations/MemUserStatus.md +0 -67
- package/docs/enumerations/MicroStatus.md +0 -33
- package/docs/enumerations/RTCJoinedInfoCodeEnum.md +0 -69
- package/docs/enumerations/RTCType.md +0 -39
- package/docs/enumerations/UserStatus.md +0 -45
- package/docs/enumerations/WebSocketCloseError.md +0 -117
- package/docs/enumerations/WebSocketErrorType.md +0 -77
- package/docs/enumerations/WebSocketState.md +0 -69
- package/docs/functions/GetVoiceSignFn.md +0 -27
- package/docs/functions/clearLiveInstanceIfNeed.md +0 -17
- package/docs/functions/createLive.md +0 -27
- package/docs/functions/createLiveReact.md +0 -449
- package/docs/functions/parseLiveMsg.md +0 -27
- package/docs/functions/parseWSClsErr.md +0 -21
- package/docs/globals.md +0 -71
- package/docs/interfaces/AttendeeResponse.md +0 -37
- package/docs/interfaces/LiveOptions.md +0 -246
- package/docs/interfaces/MeetingResponse.md +0 -55
- package/docs/interfaces/MeetingSessionConfigurationOptions.md +0 -93
- package/docs/interfaces/Permission.md +0 -147
- package/docs/interfaces/RTCJoinedInfo.md +0 -67
- package/docs/interfaces/RTCProtocol.md +0 -404
- package/docs/interfaces/VRWebViewRTCOptions.md +0 -41
- package/docs/type-aliases/BuiltinMsg.md +0 -41
- package/docs/type-aliases/EventType.md +0 -19
- package/docs/type-aliases/GetVoiceSign.md +0 -15
- package/docs/type-aliases/GetVoiceSignParams.md +0 -35
- package/docs/type-aliases/GetVoiceSignReturnType.md +0 -41
- package/docs/type-aliases/KeyframeEventType.md +0 -19
- package/docs/type-aliases/LiveBuiltInData.md +0 -47
- package/docs/type-aliases/LiveConnectOptions.md +0 -47
- package/docs/type-aliases/LiveEventType.md +0 -165
- package/docs/type-aliases/LiveMsg.md +0 -53
- package/docs/type-aliases/LiveProviderPropTypes.md +0 -27
- package/docs/type-aliases/RTCActionReactCallback.md +0 -13
- package/docs/type-aliases/RTCEventType.md +0 -65
- package/docs/type-aliases/ReqLiveMsg.md +0 -45
- package/docs/type-aliases/RoomInfo.md +0 -55
- package/docs/type-aliases/UserInfo.md +0 -77
- package/docs/type-aliases/UserInfoExt.md +0 -33
- package/docs/type-aliases/UserVolume.md +0 -25
- package/docs/type-aliases/WebSocketError.md +0 -31
package/dist/index.es.js
CHANGED
|
@@ -4,12 +4,12 @@ var a = (i, t, e) => cn(i, typeof t != "symbol" ? t + "" : t, e);
|
|
|
4
4
|
import le from "trtc-js-sdk";
|
|
5
5
|
import { ConsoleLogger as ln, LogLevel as an, DefaultDeviceController as hn, MeetingSessionConfiguration as un, DefaultMeetingSession as dn, DefaultModality as Fe, MeetingSessionStatusCode as fn } from "amazon-chime-sdk-js";
|
|
6
6
|
import gn from "@realsee/jsbridge-x";
|
|
7
|
-
import D, { createContext as pn, useCallback as
|
|
7
|
+
import D, { createContext as pn, useCallback as W } from "react";
|
|
8
8
|
const dt = Symbol("$$REALSEE_LIVE_EVENT$$");
|
|
9
9
|
function $t(i) {
|
|
10
10
|
return i[dt] || (i[dt] = {}), i[dt];
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function We(i) {
|
|
13
13
|
const t = i[dt];
|
|
14
14
|
if (!t) return;
|
|
15
15
|
Object.keys(t).some((n) => Array.isArray(t[n]) && t[n].length > 0) || delete i[dt];
|
|
@@ -63,11 +63,11 @@ class At {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
if (n[t] || (n[t] = []), e === void 0) {
|
|
66
|
-
n[t].length = 0,
|
|
66
|
+
n[t].length = 0, We(this);
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
const s = n[t].findIndex((r) => r[0] === e);
|
|
70
|
-
s !== -1 && n[t].splice(s, 1),
|
|
70
|
+
s !== -1 && n[t].splice(s, 1), We(this);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* 触发事件
|
|
@@ -129,6 +129,13 @@ function Lt() {
|
|
|
129
129
|
return [tt(), tt(), "4" + tt().substring(0, 3), tt(), tt(), tt() + tt() + tt()].join("-").toLowerCase();
|
|
130
130
|
}
|
|
131
131
|
class mn extends Re {
|
|
132
|
+
/**
|
|
133
|
+
* 创建 BrowserRTC 实例
|
|
134
|
+
*
|
|
135
|
+
* @param options 配置选项
|
|
136
|
+
* @param options.getVoiceSign 获取语音签名的函数,必需
|
|
137
|
+
* @param options.autoPlayConfirm 自动播放确认回调(可选),用于处理浏览器的自动播放策略
|
|
138
|
+
*/
|
|
132
139
|
constructor(e) {
|
|
133
140
|
super();
|
|
134
141
|
a(this, "type", ct.RealseeBrowserRTC);
|
|
@@ -139,8 +146,21 @@ class mn extends Re {
|
|
|
139
146
|
throw new Error("方法 getVoiceSign 未实现");
|
|
140
147
|
});
|
|
141
148
|
a(this, "_autoPlayConfirm");
|
|
149
|
+
/**
|
|
150
|
+
* 检查系统要求
|
|
151
|
+
*
|
|
152
|
+
* 检查浏览器是否满足 TRTC 的系统要求。
|
|
153
|
+
*
|
|
154
|
+
* @returns 系统要求检查结果
|
|
155
|
+
*/
|
|
142
156
|
a(this, "checkRequirement", () => le.checkSystemRequirements());
|
|
157
|
+
/**
|
|
158
|
+
* DOM 容器(内部使用)
|
|
159
|
+
*/
|
|
143
160
|
a(this, "$dom", document.createElement("div"));
|
|
161
|
+
/**
|
|
162
|
+
* TRTC 实例(内部使用)
|
|
163
|
+
*/
|
|
144
164
|
a(this, "_trtc", {
|
|
145
165
|
client: null,
|
|
146
166
|
stream: null
|
|
@@ -242,7 +262,15 @@ class mn extends Re {
|
|
|
242
262
|
), (r = this._trtc.client) == null || r.on("error", (o) => this.emit("error", o));
|
|
243
263
|
}
|
|
244
264
|
}
|
|
245
|
-
class
|
|
265
|
+
class Pe extends Re {
|
|
266
|
+
/**
|
|
267
|
+
* 创建 BrowserRTC4Chime 实例
|
|
268
|
+
*
|
|
269
|
+
* @param options 配置选项
|
|
270
|
+
* @param options.getVoiceSign 获取语音签名的函数,必需
|
|
271
|
+
* @param options.autoPlayConfirm 自动播放确认回调(可选),用于处理浏览器的自动播放策略
|
|
272
|
+
* @param options.logLevel 日志级别(可选),默认为 LogLevel.INFO
|
|
273
|
+
*/
|
|
246
274
|
constructor(e) {
|
|
247
275
|
super();
|
|
248
276
|
a(this, "type", ct.RealseeBrowserChimeRTC);
|
|
@@ -265,13 +293,16 @@ class We extends Re {
|
|
|
265
293
|
a(this, "$dom", document.createElement("div"));
|
|
266
294
|
a(this, "$audio", document.createElement("audio"));
|
|
267
295
|
/**
|
|
268
|
-
*
|
|
296
|
+
* 初始化 DOM 元素(内部方法)
|
|
297
|
+
* 创建并挂载 audio 标签到页面
|
|
269
298
|
*/
|
|
270
299
|
a(this, "_initDom", () => {
|
|
271
300
|
this.$audio.id = `rs-rtc-${Lt()}`, this.$dom.id = `rs-rtc-${Lt()}`, this.$dom.appendChild(this.$audio), document.body.appendChild(this.$dom);
|
|
272
301
|
});
|
|
273
302
|
/**
|
|
274
303
|
* 初始化事件监听器
|
|
304
|
+
*
|
|
305
|
+
* 设置设备变化、音视频事件等监听器
|
|
275
306
|
*/
|
|
276
307
|
a(this, "initObservers", () => {
|
|
277
308
|
this.deviceChangeObserver = {
|
|
@@ -463,6 +494,13 @@ class We extends Re {
|
|
|
463
494
|
}
|
|
464
495
|
var ht = /* @__PURE__ */ ((i) => (i[i.Success = 0] = "Success", i[i.Failure = 1] = "Failure", i[i.ReJoin = 2] = "ReJoin", i[i.NoMicroPermission = 3] = "NoMicroPermission", i[i.Unknown = 500] = "Unknown", i))(ht || {});
|
|
465
496
|
class wn extends Re {
|
|
497
|
+
/**
|
|
498
|
+
* 创建 VRWebViewRTC 实例
|
|
499
|
+
*
|
|
500
|
+
* @param options 配置选项,包含以下属性:
|
|
501
|
+
* - jsBridge: JSBridge 实例,必需,用于与原生 App 通信
|
|
502
|
+
* - getVoiceSign: 获取语音签名的函数,必需
|
|
503
|
+
*/
|
|
466
504
|
constructor({ jsBridge: e, getVoiceSign: n }) {
|
|
467
505
|
super();
|
|
468
506
|
a(this, "type", ct.RealseeVRWebViewRTC);
|
|
@@ -475,23 +513,30 @@ class wn extends Re {
|
|
|
475
513
|
a(this, "_joinOptions", null);
|
|
476
514
|
a(this, "options");
|
|
477
515
|
/**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
516
|
+
* 处理用户音量(内部方法)
|
|
517
|
+
*
|
|
518
|
+
* @param userVolumes 用户音量数组
|
|
480
519
|
*/
|
|
481
520
|
a(this, "handleUserVolumes", (e) => {
|
|
482
521
|
this.emit("userVolumes", e);
|
|
483
522
|
});
|
|
484
523
|
/**
|
|
485
|
-
*
|
|
486
|
-
*
|
|
524
|
+
* 处理弱网络情况(内部方法)
|
|
525
|
+
*
|
|
526
|
+
* @param weakNetwork 是否为弱网络
|
|
487
527
|
*/
|
|
488
528
|
a(this, "handleWeakNetwork", (e) => {
|
|
489
529
|
e && this.emit("weakNetwork");
|
|
490
530
|
});
|
|
491
531
|
/**
|
|
492
532
|
* 加入语音房间
|
|
493
|
-
*
|
|
494
|
-
* @
|
|
533
|
+
*
|
|
534
|
+
* @param options 加入房间的选项
|
|
535
|
+
* @param options.voiceId 语音房间ID
|
|
536
|
+
* @param options.userId 用户ID
|
|
537
|
+
* @param options.roomId 房间ID
|
|
538
|
+
* @param options.type RTC类型
|
|
539
|
+
* @returns Promise<boolean> 是否成功加入房间
|
|
495
540
|
*/
|
|
496
541
|
a(this, "join", async (e) => {
|
|
497
542
|
this._joinOptions = e, this.emit("joinWillStart");
|
|
@@ -655,11 +700,16 @@ class wn extends Re {
|
|
|
655
700
|
});
|
|
656
701
|
this.options = { jsBridge: e, getVoiceSign: n }, this.jsBridge.webViewType !== "WxMiniProgramWebView" && this.jsBridge.callAndListen("live/userVolumes", this.handleUserVolumes), this.jsBridge.callAndListen("live/weakNetwork", this.handleWeakNetwork), this.on("inner.rtc.fail", this.handleJoinResult);
|
|
657
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* 获取 JSBridge 实例
|
|
705
|
+
*
|
|
706
|
+
* @returns JSBridge 协议实例
|
|
707
|
+
*/
|
|
658
708
|
get jsBridge() {
|
|
659
709
|
return this.options.jsBridge;
|
|
660
710
|
}
|
|
661
711
|
}
|
|
662
|
-
var B = /* @__PURE__ */ ((i) => (i.SelfUserInfo = "SELF_USER_INFO", i.RoomInfo = "ROOM_INFO", i.RTCInfo = "RTC_INFO", i.UserList = "USER_LIST", i.BuiltinMsg = "BUILTIN_MSG", i.CustomEvent = "CUSTOM_EVENT", i.KeyframeSync = "KEYFRAME_SYNC", i.UserKickOut = "USER_KICK_OUT", i))(B || {}),
|
|
712
|
+
var B = /* @__PURE__ */ ((i) => (i.SelfUserInfo = "SELF_USER_INFO", i.RoomInfo = "ROOM_INFO", i.RTCInfo = "RTC_INFO", i.UserList = "USER_LIST", i.BuiltinMsg = "BUILTIN_MSG", i.CustomEvent = "CUSTOM_EVENT", i.KeyframeSync = "KEYFRAME_SYNC", i.UserKickOut = "USER_KICK_OUT", i))(B || {}), P = /* @__PURE__ */ ((i) => (i.UserChange = "user_change", i.RoomChange = "room_change", i))(P || {}), z = /* @__PURE__ */ ((i) => (i.UserMicroStatus = "change_micro_status", i.UserMicroStatusSync = "sync_micro_status", i.UserPermission = "change_permission", i.UserStatus = "change_status", i.UserInfo = "change_info", i.RoomClose = "close", i))(z || {}), ot = /* @__PURE__ */ ((i) => (i.OPEN = "OPEN", i.CLOSE = "CLOSE", i))(ot || {});
|
|
663
713
|
function Mr(i) {
|
|
664
714
|
try {
|
|
665
715
|
const t = JSON.parse(i), e = {
|
|
@@ -972,62 +1022,80 @@ class Mn extends At {
|
|
|
972
1022
|
}
|
|
973
1023
|
}
|
|
974
1024
|
class Nn extends At {
|
|
1025
|
+
/**
|
|
1026
|
+
* 创建带看控制器实例
|
|
1027
|
+
*
|
|
1028
|
+
* 会自动初始化 WebSocket 事件监听器
|
|
1029
|
+
*/
|
|
975
1030
|
constructor() {
|
|
976
1031
|
super();
|
|
977
1032
|
/**
|
|
978
|
-
*
|
|
1033
|
+
* WebSocket 代理器(内部使用)
|
|
1034
|
+
* 基于 RobustWebSocket 实现,提供自动重连能力
|
|
979
1035
|
*/
|
|
980
1036
|
a(this, "_ws", new Mn({
|
|
981
1037
|
url: "",
|
|
982
1038
|
robustOptions: { should1000Reconnect: !0, ignoreConnectivityEvents: !0 }
|
|
983
1039
|
}));
|
|
984
1040
|
/**
|
|
985
|
-
*
|
|
1041
|
+
* 带看连接状态(内部存储)
|
|
986
1042
|
*/
|
|
987
1043
|
a(this, "_state", j.NOTINITIALIZED);
|
|
988
1044
|
/**
|
|
989
|
-
*
|
|
1045
|
+
* 添加 WebSocket 事件监听(内部方法)
|
|
1046
|
+
* 监听 WebSocket 的各种事件并转换为控制器事件
|
|
990
1047
|
*/
|
|
991
1048
|
a(this, "_addWebSocketEventListeners", () => {
|
|
992
1049
|
this._ws.on("close", this._handleCloseEvent), this._ws.on("closing", this._handleClosingEvent), this._ws.on("connecting", this._handleConnectingEvent), this._ws.on("error", this._handleErrorEvent), this._ws.on("message", this._handleMessageEvent), this._ws.on("open", this._handleOpenEvent), this._ws.on("timeout", this._handleTimeoutEvent);
|
|
993
1050
|
});
|
|
994
1051
|
/**
|
|
995
|
-
*
|
|
1052
|
+
* 移除 WebSocket 事件监听(内部方法)
|
|
1053
|
+
* 在销毁实例时调用,清理所有事件监听器
|
|
996
1054
|
*/
|
|
997
1055
|
a(this, "_removeWebSocketEventListeners", () => {
|
|
998
1056
|
this._ws.off("close", this._handleCloseEvent), this._ws.off("closing", this._handleClosingEvent), this._ws.off("connecting", this._handleConnectingEvent), this._ws.off("error", this._handleErrorEvent), this._ws.off("message", this._handleMessageEvent), this._ws.off("open", this._handleOpenEvent), this._ws.off("timeout", this._handleTimeoutEvent);
|
|
999
1057
|
});
|
|
1000
1058
|
/**
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1059
|
+
* 处理 WebSocket 关闭事件(内部方法)
|
|
1060
|
+
*
|
|
1061
|
+
* @param event WebSocket 关闭事件对象
|
|
1003
1062
|
*/
|
|
1004
1063
|
a(this, "_handleCloseEvent", (e) => {
|
|
1005
1064
|
m.info(`live room closed bacause of ${e.code}-${e.reason || En(e.code)}`), this.state = j.CLOSED;
|
|
1006
1065
|
});
|
|
1007
1066
|
/**
|
|
1008
|
-
*
|
|
1067
|
+
* 处理 WebSocket 正在关闭事件(内部方法)
|
|
1068
|
+
*
|
|
1069
|
+
* 当连接正在关闭时触发,可能是由于网络断开等原因
|
|
1009
1070
|
*/
|
|
1010
1071
|
a(this, "_handleClosingEvent", () => {
|
|
1011
1072
|
var e;
|
|
1012
1073
|
m.info("live room is closing, onLine:", (e = globalThis == null ? void 0 : globalThis.navigator) == null ? void 0 : e.onLine), this.state = j.CLOSED;
|
|
1013
1074
|
});
|
|
1014
1075
|
/**
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1076
|
+
* 处理 WebSocket 连接中事件(内部方法)
|
|
1077
|
+
*
|
|
1078
|
+
* 当开始连接或重连时触发,如果是重连会触发 reconnecting 事件
|
|
1079
|
+
*
|
|
1080
|
+
* @param ev WebSocket 连接事件对象
|
|
1017
1081
|
*/
|
|
1018
1082
|
a(this, "_handleConnectingEvent", (e) => {
|
|
1019
1083
|
m.info("live room is connecting"), this.state = j.CONNECTING, e.detail.reconnects > 0 && this.emit("reconnecting", e.detail);
|
|
1020
1084
|
});
|
|
1021
1085
|
/**
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1086
|
+
* 处理 WebSocket 错误事件(内部方法)
|
|
1087
|
+
*
|
|
1088
|
+
* @param event 错误事件对象
|
|
1024
1089
|
*/
|
|
1025
1090
|
a(this, "_handleErrorEvent", (e) => {
|
|
1026
1091
|
m.error("live room error", e), this.state = j.CLOSED;
|
|
1027
1092
|
});
|
|
1028
1093
|
/**
|
|
1029
|
-
*
|
|
1030
|
-
*
|
|
1094
|
+
* 处理 WebSocket 消息事件(内部方法)
|
|
1095
|
+
*
|
|
1096
|
+
* 解析接收到的消息并触发 message 事件
|
|
1097
|
+
*
|
|
1098
|
+
* @param event WebSocket 消息事件对象
|
|
1031
1099
|
*/
|
|
1032
1100
|
a(this, "_handleMessageEvent", (e) => {
|
|
1033
1101
|
let n = (() => {
|
|
@@ -1040,41 +1108,90 @@ class Nn extends At {
|
|
|
1040
1108
|
this.emit("message", n);
|
|
1041
1109
|
});
|
|
1042
1110
|
/**
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1111
|
+
* 处理 WebSocket 连接成功事件(内部方法)
|
|
1112
|
+
*
|
|
1113
|
+
* 当连接建立成功时触发,如果是重连成功会触发 reconnected 事件
|
|
1114
|
+
*
|
|
1115
|
+
* @param event WebSocket 打开事件对象
|
|
1045
1116
|
*/
|
|
1046
1117
|
a(this, "_handleOpenEvent", (e) => {
|
|
1047
1118
|
m.info("live room open", e.detail), this.state = j.OPEN, e.detail.reconnects > 0 && this.emit("reconnected", e.detail);
|
|
1048
1119
|
});
|
|
1049
1120
|
/**
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1121
|
+
* 处理 WebSocket 连接超时事件(内部方法)
|
|
1122
|
+
*
|
|
1123
|
+
* @param event WebSocket 超时事件对象
|
|
1052
1124
|
*/
|
|
1053
1125
|
a(this, "_handleTimeoutEvent", (e) => {
|
|
1054
1126
|
m.error("live room connect timeout!", e.detail), this.state = j.CLOSED;
|
|
1055
1127
|
});
|
|
1056
1128
|
/**
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1129
|
+
* 释放控制器资源
|
|
1130
|
+
*
|
|
1131
|
+
* 移除所有事件监听器并关闭 WebSocket 连接。
|
|
1132
|
+
* 释放后需要重新实例化才能使用。
|
|
1133
|
+
*
|
|
1134
|
+
* @returns Promise<boolean> 关闭是否成功
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```typescript
|
|
1137
|
+
* await controller.dispose()
|
|
1138
|
+
* ```
|
|
1059
1139
|
*/
|
|
1060
1140
|
a(this, "dispose", async () => (this._removeWebSocketEventListeners(), await this.close("live room close by controller disposed!")));
|
|
1061
1141
|
/**
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1142
|
+
* 打开 WebSocket 连接
|
|
1143
|
+
*
|
|
1144
|
+
* 开始建立与服务器的 WebSocket 连接。
|
|
1145
|
+
*
|
|
1146
|
+
* @param url WebSocket 连接地址(ws:// 或 wss://)
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```typescript
|
|
1149
|
+
* controller.open('wss://example.com/live?ticket=xxx')
|
|
1150
|
+
* ```
|
|
1065
1151
|
*/
|
|
1066
1152
|
a(this, "open", (e) => this._ws.open(e));
|
|
1067
1153
|
/**
|
|
1068
|
-
*
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1154
|
+
* 关闭 WebSocket 连接
|
|
1155
|
+
*
|
|
1156
|
+
* 关闭与服务器的 WebSocket 连接。
|
|
1157
|
+
*
|
|
1158
|
+
* @param code 关闭代码(可选),WebSocket 关闭码
|
|
1159
|
+
* @param reason 关闭原因(可选),关闭原因字符串
|
|
1160
|
+
* @returns Promise<boolean> 关闭是否成功
|
|
1161
|
+
* @example
|
|
1162
|
+
* ```typescript
|
|
1163
|
+
* // 正常关闭
|
|
1164
|
+
* await controller.close()
|
|
1165
|
+
*
|
|
1166
|
+
* // 指定关闭码和原因
|
|
1167
|
+
* await controller.close(1000, '正常关闭')
|
|
1168
|
+
* ```
|
|
1071
1169
|
*/
|
|
1072
1170
|
a(this, "close", (e, n) => new Promise((s) => {
|
|
1073
1171
|
this._ws.once("close", () => s(!0)), this._ws.close(e, n);
|
|
1074
1172
|
}));
|
|
1075
1173
|
/**
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1174
|
+
* 发送消息到服务器
|
|
1175
|
+
*
|
|
1176
|
+
* 只有在连接状态为 OPEN 时才能发送消息。
|
|
1177
|
+
* 消息会被自动序列化为 JSON 字符串。
|
|
1178
|
+
*
|
|
1179
|
+
* @param data 要发送的数据对象,不能为 undefined 或 null
|
|
1180
|
+
* @returns 发送是否成功
|
|
1181
|
+
* @throws {Error} 如果消息为空或连接未打开,会抛出错误
|
|
1182
|
+
* @example
|
|
1183
|
+
* ```typescript
|
|
1184
|
+
* // 发送消息
|
|
1185
|
+
* controller.sendMessage({
|
|
1186
|
+
* command: 'test',
|
|
1187
|
+
* data: { message: 'hello' }
|
|
1188
|
+
* })
|
|
1189
|
+
*
|
|
1190
|
+
* // 检查连接状态
|
|
1191
|
+
* if (controller.state === LiveState.OPEN) {
|
|
1192
|
+
* controller.sendMessage({ command: 'ping' })
|
|
1193
|
+
* }
|
|
1194
|
+
* ```
|
|
1078
1195
|
*/
|
|
1079
1196
|
a(this, "sendMessage", (e = "") => {
|
|
1080
1197
|
if (e == null)
|
|
@@ -1084,17 +1201,38 @@ class Nn extends At {
|
|
|
1084
1201
|
return this._ws.send(JSON.stringify(e));
|
|
1085
1202
|
});
|
|
1086
1203
|
/**
|
|
1087
|
-
*
|
|
1204
|
+
* 准备关闭带看连接
|
|
1205
|
+
*
|
|
1206
|
+
* 标记连接为显式关闭,防止自动重连。
|
|
1207
|
+
* 通常在用户主动退出时调用。
|
|
1208
|
+
*
|
|
1209
|
+
* @example
|
|
1210
|
+
* ```typescript
|
|
1211
|
+
* controller.readyClose()
|
|
1212
|
+
* await controller.close()
|
|
1213
|
+
* ```
|
|
1088
1214
|
*/
|
|
1089
1215
|
a(this, "readyClose", () => {
|
|
1090
1216
|
this._ws && (this._ws._explicitlyClosed = !0);
|
|
1091
1217
|
});
|
|
1092
1218
|
this._addWebSocketEventListeners();
|
|
1093
1219
|
}
|
|
1220
|
+
/**
|
|
1221
|
+
* 设置连接状态
|
|
1222
|
+
*
|
|
1223
|
+
* 当状态改变时,会自动触发 stateChange 事件
|
|
1224
|
+
*
|
|
1225
|
+
* @param state 新的连接状态
|
|
1226
|
+
*/
|
|
1094
1227
|
set state(e) {
|
|
1095
1228
|
const n = JSON.parse(JSON.stringify(this._state));
|
|
1096
1229
|
this._state = e, this.emit("stateChange", this.state, n);
|
|
1097
1230
|
}
|
|
1231
|
+
/**
|
|
1232
|
+
* 获取当前连接状态
|
|
1233
|
+
*
|
|
1234
|
+
* @returns 当前连接状态
|
|
1235
|
+
*/
|
|
1098
1236
|
get state() {
|
|
1099
1237
|
return this._state;
|
|
1100
1238
|
}
|
|
@@ -1180,7 +1318,7 @@ class $n {
|
|
|
1180
1318
|
this._observers = G();
|
|
1181
1319
|
}
|
|
1182
1320
|
}
|
|
1183
|
-
const lt = Math.floor,
|
|
1321
|
+
const lt = Math.floor, Wt = Math.abs, pi = (i, t) => i < t ? i : t, St = (i, t) => i > t ? i : t, xn = (i) => i !== 0 ? i < 0 : 1 / i < 0, Je = 1, He = 2, he = 4, ue = 8, Bn = 32, _i = 64, Ht = 128, Fn = 31, qe = 63, Ot = 127, Wn = 2147483647, Pn = Number.isInteger || ((i) => typeof i == "number" && isFinite(i) && lt(i) === i), Kn = (i) => i.toLowerCase(), Gn = /^\s*/g, Jn = (i) => i.replace(Gn, ""), Hn = /([A-Z])/g, ze = (i, t) => Jn(i.replace(Hn, (e) => `${t}${Kn(e)}`)), qn = (i) => {
|
|
1184
1322
|
const t = unescape(encodeURIComponent(i)), e = t.length, n = new Uint8Array(e);
|
|
1185
1323
|
for (let s = 0; s < e; s++)
|
|
1186
1324
|
n[s] = /** @type {number} */
|
|
@@ -1260,7 +1398,7 @@ Tt.encodeInto ? ts : es, De = (i, t) => {
|
|
|
1260
1398
|
A(i, 119), ft(i, t);
|
|
1261
1399
|
break;
|
|
1262
1400
|
case "number":
|
|
1263
|
-
|
|
1401
|
+
Pn(t) && Wt(t) <= Wn ? (A(i, 125), Te(i, t)) : rs(t) ? (A(i, 124), is(i, t)) : (A(i, 123), ns(i, t));
|
|
1264
1402
|
break;
|
|
1265
1403
|
case "bigint":
|
|
1266
1404
|
A(i, 122), ss(i, t);
|
|
@@ -1308,7 +1446,7 @@ class Xe extends jt {
|
|
|
1308
1446
|
const Ze = (i) => {
|
|
1309
1447
|
i.count > 0 && (Te(i.encoder, i.count === 1 ? i.s : -i.s), i.count > 1 && S(i.encoder, i.count - 2));
|
|
1310
1448
|
};
|
|
1311
|
-
class
|
|
1449
|
+
class Pt {
|
|
1312
1450
|
constructor() {
|
|
1313
1451
|
this.encoder = new jt(), this.s = 0, this.count = 0;
|
|
1314
1452
|
}
|
|
@@ -1354,7 +1492,7 @@ class fe {
|
|
|
1354
1492
|
}
|
|
1355
1493
|
class os {
|
|
1356
1494
|
constructor() {
|
|
1357
|
-
this.sarr = [], this.s = "", this.lensE = new
|
|
1495
|
+
this.sarr = [], this.s = "", this.lensE = new Pt();
|
|
1358
1496
|
}
|
|
1359
1497
|
/**
|
|
1360
1498
|
* @param {string} string
|
|
@@ -1822,7 +1960,7 @@ class Ct extends $n {
|
|
|
1822
1960
|
this.emit("destroyed", [!0]), this.emit("destroy", [this]), super.destroy();
|
|
1823
1961
|
}
|
|
1824
1962
|
}
|
|
1825
|
-
class
|
|
1963
|
+
class Ws {
|
|
1826
1964
|
constructor() {
|
|
1827
1965
|
this.restEncoder = Le();
|
|
1828
1966
|
}
|
|
@@ -1844,7 +1982,7 @@ class Ps {
|
|
|
1844
1982
|
S(this.restEncoder, t);
|
|
1845
1983
|
}
|
|
1846
1984
|
}
|
|
1847
|
-
class
|
|
1985
|
+
class Ps extends Ws {
|
|
1848
1986
|
/**
|
|
1849
1987
|
* @param {ID} id
|
|
1850
1988
|
*/
|
|
@@ -1947,7 +2085,7 @@ class Ks {
|
|
|
1947
2085
|
}
|
|
1948
2086
|
class Gs extends Ks {
|
|
1949
2087
|
constructor() {
|
|
1950
|
-
super(), this.keyMap = /* @__PURE__ */ new Map(), this.keyClock = 0, this.keyClockEncoder = new fe(), this.clientEncoder = new
|
|
2088
|
+
super(), this.keyMap = /* @__PURE__ */ new Map(), this.keyClock = 0, this.keyClockEncoder = new fe(), this.clientEncoder = new Pt(), this.leftClockEncoder = new fe(), this.rightClockEncoder = new fe(), this.infoEncoder = new Xe(Ce), this.stringEncoder = new os(), this.parentInfoEncoder = new Xe(Ce), this.typeRefEncoder = new Pt(), this.lenEncoder = new Pt();
|
|
1951
2089
|
}
|
|
1952
2090
|
toUint8Array() {
|
|
1953
2091
|
const t = Le();
|
|
@@ -2263,7 +2401,7 @@ const ci = (i, t) => t.deleteSet.clients.size === 0 && !Un(t.afterState, (e, n)
|
|
|
2263
2401
|
y + 1 < w.length && Gt(w, y + 1) > 1 || y > 0 && Gt(w, y);
|
|
2264
2402
|
}
|
|
2265
2403
|
if (!e.local && e.afterState.get(n.clientID) !== e.beforeState.get(n.clientID) && (Vs(Ve, Si, "[yjs] ", Ci, Ei, "Changed the client-id because another client seems to be using it."), n.clientID = Ti()), n.emit("afterTransactionCleanup", [e, n]), n._observers.has("update")) {
|
|
2266
|
-
const u = new
|
|
2404
|
+
const u = new Ps();
|
|
2267
2405
|
ci(u, e) && n.emit("update", [u.toUint8Array(), e.origin, n, e]);
|
|
2268
2406
|
}
|
|
2269
2407
|
if (n._observers.has("updateV2")) {
|
|
@@ -2470,7 +2608,7 @@ const rr = (i) => {
|
|
|
2470
2608
|
}, ie = (i, t) => {
|
|
2471
2609
|
if (i._start === null || t === 0 || i._searchMarker === null)
|
|
2472
2610
|
return null;
|
|
2473
|
-
const e = i._searchMarker.length === 0 ? null : i._searchMarker.reduce((r, o) =>
|
|
2611
|
+
const e = i._searchMarker.length === 0 ? null : i._searchMarker.reduce((r, o) => Wt(t - r.index) < Wt(t - o.index) ? r : o);
|
|
2474
2612
|
let n = i._start, s = 0;
|
|
2475
2613
|
for (e !== null && (n = e.p, s = e.index, rr(e)); n.right !== null && s < t; ) {
|
|
2476
2614
|
if (!n.deleted && n.countable) {
|
|
@@ -2484,7 +2622,7 @@ const rr = (i) => {
|
|
|
2484
2622
|
n = n.left, !n.deleted && n.countable && (s -= n.length);
|
|
2485
2623
|
for (; n.left !== null && n.left.id.client === n.id.client && n.left.id.clock + n.left.length === n.id.clock; )
|
|
2486
2624
|
n = n.left, !n.deleted && n.countable && (s -= n.length);
|
|
2487
|
-
return e !== null &&
|
|
2625
|
+
return e !== null && Wt(e.index - s) < /** @type {YText|YArray<any>} */
|
|
2488
2626
|
n.parent.length / Ui ? (ji(e, n, s), e) : or(i._searchMarker, n, s);
|
|
2489
2627
|
}, Nt = (i, t, e) => {
|
|
2490
2628
|
for (let n = i.length - 1; n >= 0; n--) {
|
|
@@ -2740,9 +2878,9 @@ const $i = (i, t, e) => {
|
|
|
2740
2878
|
}
|
|
2741
2879
|
}
|
|
2742
2880
|
}), u();
|
|
2743
|
-
},
|
|
2881
|
+
}, Wi = () => mt("Length exceeded!"), Pi = (i, t, e, n) => {
|
|
2744
2882
|
if (e > t._length)
|
|
2745
|
-
throw
|
|
2883
|
+
throw Wi();
|
|
2746
2884
|
if (e === 0)
|
|
2747
2885
|
return t._searchMarker && Nt(t._searchMarker, e, n.length), zt(i, t, null, n);
|
|
2748
2886
|
const s = e, r = ie(t, e);
|
|
@@ -2772,7 +2910,7 @@ const $i = (i, t, e) => {
|
|
|
2772
2910
|
for (; n > 0 && c !== null; )
|
|
2773
2911
|
c.deleted || (n < c.length && nt(i, k(c.id.client, c.id.clock + n)), c.delete(i), n -= c.length), c = c.right;
|
|
2774
2912
|
if (n > 0)
|
|
2775
|
-
throw
|
|
2913
|
+
throw Wi();
|
|
2776
2914
|
t._searchMarker && Nt(
|
|
2777
2915
|
t._searchMarker,
|
|
2778
2916
|
s,
|
|
@@ -2933,7 +3071,7 @@ class Rt extends M {
|
|
|
2933
3071
|
*/
|
|
2934
3072
|
insert(t, e) {
|
|
2935
3073
|
this.doc !== null ? E(this.doc, (n) => {
|
|
2936
|
-
|
|
3074
|
+
Pi(
|
|
2937
3075
|
n,
|
|
2938
3076
|
this,
|
|
2939
3077
|
t,
|
|
@@ -4188,7 +4326,7 @@ class wt extends M {
|
|
|
4188
4326
|
*/
|
|
4189
4327
|
insert(t, e) {
|
|
4190
4328
|
this.doc !== null ? E(this.doc, (n) => {
|
|
4191
|
-
|
|
4329
|
+
Pi(n, this, t, e);
|
|
4192
4330
|
}) : this._prelimContent.splice(t, 0, ...e);
|
|
4193
4331
|
}
|
|
4194
4332
|
/**
|
|
@@ -5477,6 +5615,50 @@ const It = (i) => Promise.reject(new Error("unimplemented method GetVoiceSign"))
|
|
|
5477
5615
|
window != null && window.__Realsee_Live__ && ((t = (i = window == null ? void 0 : window.__Realsee_Live__) == null ? void 0 : i.dispose) == null || t.call(i), window.__Realsee_Live__ = null);
|
|
5478
5616
|
};
|
|
5479
5617
|
class Ir extends At {
|
|
5618
|
+
/**
|
|
5619
|
+
* 创建 Live 带看实例
|
|
5620
|
+
*
|
|
5621
|
+
* @param opts 带看配置选项,包含以下属性:
|
|
5622
|
+
* - url: WebSocket 连接地址(可选,可在 connect 时提供)
|
|
5623
|
+
* - getTicket: 获取连接票据的函数(可选,可在 connect 时提供)
|
|
5624
|
+
* - rtc: RTC 实例(可选,如果不提供会根据配置自动创建)
|
|
5625
|
+
* - rtcType: 指定内置 RTC 类型(当 rtc 为空时使用)
|
|
5626
|
+
* - useBuiltInRTC: 是否使用内置 RTC(默认根据环境自动选择)
|
|
5627
|
+
* - getVoiceSign: 获取语音签名的函数(使用内置 RTC 时必需)
|
|
5628
|
+
* - jsBridge: JSBridge 实例(可选,用于 App/WebView 环境)
|
|
5629
|
+
* - useBuiltInJsBridge: 是否使用内置 JSBridge(默认 false)
|
|
5630
|
+
* - initialMicroStatus: 麦克风初始状态(默认 OPEN)
|
|
5631
|
+
* - autoPlayConfirm: 自动播放确认回调(使用 BrowserRTC 时可能需要)
|
|
5632
|
+
* - __debug__: 是否开启调试模式(会在控制台打印日志)
|
|
5633
|
+
*
|
|
5634
|
+
* @example
|
|
5635
|
+
* ```typescript
|
|
5636
|
+
* // 基础用法
|
|
5637
|
+
* const live = new Live({
|
|
5638
|
+
* url: 'wss://example.com/live',
|
|
5639
|
+
* getTicket: async () => {
|
|
5640
|
+
* const response = await fetch('/api/get-ticket')
|
|
5641
|
+
* return response.json().ticket
|
|
5642
|
+
* },
|
|
5643
|
+
* getVoiceSign: async (params) => {
|
|
5644
|
+
* const response = await fetch('/api/get-voice-sign', {
|
|
5645
|
+
* method: 'POST',
|
|
5646
|
+
* body: JSON.stringify(params)
|
|
5647
|
+
* })
|
|
5648
|
+
* return response.json()
|
|
5649
|
+
* },
|
|
5650
|
+
* useBuiltInRTC: true
|
|
5651
|
+
* })
|
|
5652
|
+
*
|
|
5653
|
+
* // 使用自定义 RTC
|
|
5654
|
+
* const customRTC = new MyCustomRTC()
|
|
5655
|
+
* const live = new Live({
|
|
5656
|
+
* rtc: customRTC,
|
|
5657
|
+
* url: 'wss://example.com/live',
|
|
5658
|
+
* getTicket: async () => 'ticket'
|
|
5659
|
+
* })
|
|
5660
|
+
* ```
|
|
5661
|
+
*/
|
|
5480
5662
|
constructor(e) {
|
|
5481
5663
|
super();
|
|
5482
5664
|
/**
|
|
@@ -5484,20 +5666,40 @@ class Ir extends At {
|
|
|
5484
5666
|
*/
|
|
5485
5667
|
a(this, "_options", {});
|
|
5486
5668
|
/**
|
|
5487
|
-
*
|
|
5669
|
+
* 帧数据监听器
|
|
5670
|
+
*
|
|
5671
|
+
* 用于监听特定键的帧数据变化。当其他用户发送帧数据更新时,会触发对应键的事件。
|
|
5672
|
+
*
|
|
5673
|
+
* @example
|
|
5674
|
+
* ```typescript
|
|
5675
|
+
* // 监听 camera 帧数据的变化
|
|
5676
|
+
* live.keyframes.on('camera', (nextFrame, prevFrame, frontRequestId) => {
|
|
5677
|
+
* console.log('相机位置更新:', nextFrame)
|
|
5678
|
+
* })
|
|
5679
|
+
* ```
|
|
5488
5680
|
*/
|
|
5489
5681
|
a(this, "keyframes", new At());
|
|
5490
5682
|
/**
|
|
5491
|
-
* 带看的
|
|
5683
|
+
* 带看的 Yjs 文档实例(用于帧数据同步)
|
|
5492
5684
|
*/
|
|
5493
5685
|
a(this, "_yDoc");
|
|
5494
5686
|
/**
|
|
5495
|
-
*
|
|
5687
|
+
* 内置的一些数据(用户信息、房间信息、帧数据等)
|
|
5496
5688
|
*/
|
|
5497
5689
|
a(this, "_buildInData");
|
|
5690
|
+
/**
|
|
5691
|
+
* 初始化帧数据观察者(内部方法)
|
|
5692
|
+
* 用于监听 Yjs Map 的变化并同步到其他用户
|
|
5693
|
+
*/
|
|
5498
5694
|
a(this, "_initializeKeyframesObservers", () => {
|
|
5499
5695
|
this._yDoc.getMap("keyframes").observe(this._handleKeyframesChange);
|
|
5500
5696
|
});
|
|
5697
|
+
/**
|
|
5698
|
+
* 处理帧数据变化(内部方法)
|
|
5699
|
+
* 当本地或远程帧数据发生变化时,会触发此方法进行同步
|
|
5700
|
+
*
|
|
5701
|
+
* @param event Yjs Map 事件对象
|
|
5702
|
+
*/
|
|
5501
5703
|
a(this, "_handleKeyframesChange", (e) => {
|
|
5502
5704
|
var o;
|
|
5503
5705
|
const { transaction: n, target: s, changes: r } = e;
|
|
@@ -5524,16 +5726,51 @@ class Ir extends At {
|
|
|
5524
5726
|
}), r.keys.size !== 0 && this.emit("keyframes", this.snapshot, n.origin.frontRequestId);
|
|
5525
5727
|
});
|
|
5526
5728
|
/**
|
|
5527
|
-
*
|
|
5729
|
+
* 根据键值获取对应的帧数据
|
|
5730
|
+
*
|
|
5731
|
+
* @template Key 帧数据的键类型
|
|
5528
5732
|
* @param key 帧数据的键值
|
|
5529
|
-
* @returns
|
|
5733
|
+
* @returns 对应键的帧数据,如果不存在则返回 undefined
|
|
5734
|
+
* @example
|
|
5735
|
+
* ```typescript
|
|
5736
|
+
* // 获取相机帧数据
|
|
5737
|
+
* const cameraFrame = live.getFramesByKey('camera')
|
|
5738
|
+
* if (cameraFrame) {
|
|
5739
|
+
* console.log('相机位置:', cameraFrame.position)
|
|
5740
|
+
* }
|
|
5741
|
+
* ```
|
|
5530
5742
|
*/
|
|
5531
5743
|
a(this, "getFramesByKey", (e) => this.snapshot[e]);
|
|
5532
5744
|
/**
|
|
5533
5745
|
* 发送帧数据(需要能够被序列化)
|
|
5746
|
+
*
|
|
5747
|
+
* 将帧数据同步到其他用户。帧数据必须是可序列化的 JSON 对象。
|
|
5748
|
+
* 只有在连接状态为 OPEN 时才能发送。
|
|
5749
|
+
*
|
|
5750
|
+
* @template Key 帧数据的键类型
|
|
5534
5751
|
* @param key 帧数据键值
|
|
5535
|
-
* @param frame
|
|
5536
|
-
* @returns 发送结果,成功返回true
|
|
5752
|
+
* @param frame 帧数据本体,必须可序列化
|
|
5753
|
+
* @returns 发送结果,成功返回 true,连接未打开返回 false,其他错误返回 Error
|
|
5754
|
+
* @example
|
|
5755
|
+
* ```typescript
|
|
5756
|
+
* // 发送相机位置更新
|
|
5757
|
+
* const result = live.sendKeyframe('camera', {
|
|
5758
|
+
* position: [1, 2, 3],
|
|
5759
|
+
* rotation: [0, 0, 0]
|
|
5760
|
+
* })
|
|
5761
|
+
*
|
|
5762
|
+
* if (result === true) {
|
|
5763
|
+
* console.log('发送成功')
|
|
5764
|
+
* } else {
|
|
5765
|
+
* console.error('发送失败:', result)
|
|
5766
|
+
* }
|
|
5767
|
+
*
|
|
5768
|
+
* // 发送标注更新
|
|
5769
|
+
* live.sendKeyframe('annotation', {
|
|
5770
|
+
* text: '这是一个标注',
|
|
5771
|
+
* position: [100, 200]
|
|
5772
|
+
* })
|
|
5773
|
+
* ```
|
|
5537
5774
|
*/
|
|
5538
5775
|
a(this, "sendKeyframe", (e, n) => {
|
|
5539
5776
|
var s;
|
|
@@ -5548,22 +5785,41 @@ class Ir extends At {
|
|
|
5548
5785
|
), !0);
|
|
5549
5786
|
});
|
|
5550
5787
|
/**
|
|
5551
|
-
*
|
|
5788
|
+
* 带看控制器(内部使用)
|
|
5552
5789
|
*/
|
|
5553
5790
|
a(this, "_controller", new Nn());
|
|
5791
|
+
/**
|
|
5792
|
+
* 初始化配置选项(内部方法)
|
|
5793
|
+
* @param opts 配置选项
|
|
5794
|
+
*/
|
|
5554
5795
|
a(this, "_initializeOptions", (e) => {
|
|
5555
5796
|
var n;
|
|
5556
5797
|
this._options = Object.assign({ initialMicroStatus: ot.OPEN }, e), this._options.jsBridge = this._initializeJsBridge(e), this._options.getVoiceSign = (n = e.getVoiceSign) != null ? n : It, this._options.autoPlayConfirm = e.autoPlayConfirm, this._options.rtc = this._initializeRTC(e);
|
|
5557
5798
|
});
|
|
5799
|
+
/**
|
|
5800
|
+
* 初始化 JSBridge 实例(内部方法)
|
|
5801
|
+
* @param opts 配置选项
|
|
5802
|
+
* @returns JSBridge 实例或 undefined
|
|
5803
|
+
*/
|
|
5558
5804
|
a(this, "_initializeJsBridge", (e) => {
|
|
5559
5805
|
if (e.jsBridge) return e.jsBridge;
|
|
5560
5806
|
if (e.useBuiltInJsBridge) return new gn();
|
|
5561
5807
|
});
|
|
5808
|
+
/**
|
|
5809
|
+
* 初始化 RTC 实例(内部方法)
|
|
5810
|
+
* @param opts 配置选项
|
|
5811
|
+
* @returns RTC 实例或 undefined
|
|
5812
|
+
*/
|
|
5562
5813
|
a(this, "_initializeRTC", (e) => {
|
|
5563
5814
|
if (e.rtc) return e.rtc;
|
|
5564
5815
|
if (e.rtcType) return this._createBuiltInRTC(e);
|
|
5565
5816
|
if (e.useBuiltInRTC) return this._createDefaultRTC(e);
|
|
5566
5817
|
});
|
|
5818
|
+
/**
|
|
5819
|
+
* 创建内置 RTC 实例(内部方法)
|
|
5820
|
+
* @param opts 配置选项
|
|
5821
|
+
* @returns RTC 实例或 undefined
|
|
5822
|
+
*/
|
|
5567
5823
|
a(this, "_createBuiltInRTC", (e) => {
|
|
5568
5824
|
var n;
|
|
5569
5825
|
if (!e.getVoiceSign) {
|
|
@@ -5574,7 +5830,7 @@ class Ir extends At {
|
|
|
5574
5830
|
case ct.RealseeVRWebViewRTC:
|
|
5575
5831
|
return this._createVRWebViewRTC();
|
|
5576
5832
|
case ct.RealseeBrowserChimeRTC:
|
|
5577
|
-
return new
|
|
5833
|
+
return new Pe({
|
|
5578
5834
|
getVoiceSign: (n = this._options.getVoiceSign) != null ? n : It,
|
|
5579
5835
|
logLevel: e.__debug__ ? 0 : 1
|
|
5580
5836
|
});
|
|
@@ -5585,6 +5841,10 @@ class Ir extends At {
|
|
|
5585
5841
|
return;
|
|
5586
5842
|
}
|
|
5587
5843
|
});
|
|
5844
|
+
/**
|
|
5845
|
+
* 创建 VRWebView RTC 实例(内部方法)
|
|
5846
|
+
* @returns RTC 实例或 undefined
|
|
5847
|
+
*/
|
|
5588
5848
|
a(this, "_createVRWebViewRTC", () => {
|
|
5589
5849
|
var e;
|
|
5590
5850
|
if (this._options.jsBridge)
|
|
@@ -5594,6 +5854,10 @@ class Ir extends At {
|
|
|
5594
5854
|
});
|
|
5595
5855
|
m.error("JsBridge instance must be passed when using built-in VRWebViewRTC instances");
|
|
5596
5856
|
});
|
|
5857
|
+
/**
|
|
5858
|
+
* 创建浏览器 RTC 实例(内部方法)
|
|
5859
|
+
* @returns RTC 实例或 undefined
|
|
5860
|
+
*/
|
|
5597
5861
|
a(this, "_createBrowserRTC", () => {
|
|
5598
5862
|
var e;
|
|
5599
5863
|
if (!this._options.autoPlayConfirm) {
|
|
@@ -5605,14 +5869,28 @@ class Ir extends At {
|
|
|
5605
5869
|
autoPlayConfirm: this._options.autoPlayConfirm
|
|
5606
5870
|
});
|
|
5607
5871
|
});
|
|
5872
|
+
/**
|
|
5873
|
+
* 创建默认 RTC 实例(内部方法)
|
|
5874
|
+
* 根据环境自动选择合适的 RTC 实现
|
|
5875
|
+
* @param opts 配置选项
|
|
5876
|
+
* @returns RTC 实例或 undefined
|
|
5877
|
+
*/
|
|
5608
5878
|
a(this, "_createDefaultRTC", (e) => {
|
|
5609
5879
|
var s;
|
|
5610
5880
|
const n = (s = this._options.getVoiceSign) != null ? s : It;
|
|
5611
|
-
return !this._options.jsBridge || !Ge && !Ke ? e.builtInRTCType === fi.RealseeXChimeRTC ? new
|
|
5881
|
+
return !this._options.jsBridge || !Ge && !Ke ? e.builtInRTCType === fi.RealseeXChimeRTC ? new Pe({ getVoiceSign: n }) : this._createBrowserRTC() : Ge && (vn || In) || Ke ? this._createVRWebViewRTC() : this._createBrowserRTC();
|
|
5612
5882
|
});
|
|
5883
|
+
/**
|
|
5884
|
+
* 自动连接(内部方法)
|
|
5885
|
+
* 如果配置中已提供 url 和 getTicket,则自动连接
|
|
5886
|
+
*/
|
|
5613
5887
|
a(this, "_autoConnect", () => {
|
|
5614
5888
|
this._options.url && this._options.getTicket && this.connect();
|
|
5615
5889
|
});
|
|
5890
|
+
/**
|
|
5891
|
+
* 调试模式设置(内部方法)
|
|
5892
|
+
* 在调试模式下,将实例挂载到 window 对象上
|
|
5893
|
+
*/
|
|
5616
5894
|
a(this, "_debugSetup", () => {
|
|
5617
5895
|
this._options.__debug__ && Object.assign(window, { $liveController: this._controller, $live: this });
|
|
5618
5896
|
});
|
|
@@ -5715,7 +5993,7 @@ class Ir extends At {
|
|
|
5715
5993
|
}
|
|
5716
5994
|
case B.BuiltinMsg: {
|
|
5717
5995
|
const p = u;
|
|
5718
|
-
this.emit("builtinEvent", p), p.event_type ===
|
|
5996
|
+
this.emit("builtinEvent", p), p.event_type === P.UserChange && this.emit("userChange", p), p.event_type === P.RoomChange && this.emit("roomChange", p), p.event_type === P.UserChange && p.action === z.UserMicroStatus && await this.toggleMicro(p.data.status === ot.OPEN), p.event_type === P.RoomChange && p.action === z.RoomClose && await this._exit();
|
|
5719
5997
|
break;
|
|
5720
5998
|
}
|
|
5721
5999
|
case B.UserKickOut: {
|
|
@@ -5736,9 +6014,46 @@ class Ir extends At {
|
|
|
5736
6014
|
this._buildInData.keyframes.clear(), this._buildInData = { keyframes: this._yDoc.getMap("keyframes") };
|
|
5737
6015
|
});
|
|
5738
6016
|
/**
|
|
5739
|
-
*
|
|
5740
|
-
*
|
|
5741
|
-
*
|
|
6017
|
+
* 连接带看房间
|
|
6018
|
+
*
|
|
6019
|
+
* 建立 WebSocket 连接并加入带看房间。如果配置中已提供 url 和 getTicket,
|
|
6020
|
+
* 可以在创建实例后自动连接,也可以手动调用此方法。
|
|
6021
|
+
*
|
|
6022
|
+
* @param options 连接选项,包含以下属性:
|
|
6023
|
+
* - url: WebSocket 连接地址(可选,会覆盖构造函数中的配置)
|
|
6024
|
+
* - getTicket: 获取连接票据的函数(可选,会覆盖构造函数中的配置)
|
|
6025
|
+
* - rtcMicStatus: 麦克风初始状态(可选,会覆盖构造函数中的配置)
|
|
6026
|
+
* - force: 是否强制连接(如果已有连接,会先关闭再连接)
|
|
6027
|
+
* @returns 连接结果,成功返回 true,失败返回 Error
|
|
6028
|
+
* @example
|
|
6029
|
+
* ```typescript
|
|
6030
|
+
* // 在创建实例时已配置 url 和 getTicket
|
|
6031
|
+
* const live = new Live({
|
|
6032
|
+
* url: 'wss://example.com/live',
|
|
6033
|
+
* getTicket: async () => 'ticket'
|
|
6034
|
+
* })
|
|
6035
|
+
*
|
|
6036
|
+
* // 手动连接
|
|
6037
|
+
* const result = await live.connect()
|
|
6038
|
+
* if (result === true) {
|
|
6039
|
+
* console.log('连接成功')
|
|
6040
|
+
* } else {
|
|
6041
|
+
* console.error('连接失败:', result.message)
|
|
6042
|
+
* }
|
|
6043
|
+
*
|
|
6044
|
+
* // 在连接时提供配置
|
|
6045
|
+
* await live.connect({
|
|
6046
|
+
* url: 'wss://example.com/live',
|
|
6047
|
+
* getTicket: async () => {
|
|
6048
|
+
* const res = await fetch('/api/ticket')
|
|
6049
|
+
* return res.json().ticket
|
|
6050
|
+
* },
|
|
6051
|
+
* rtcMicStatus: MicroStatus.OPEN
|
|
6052
|
+
* })
|
|
6053
|
+
*
|
|
6054
|
+
* // 强制重连
|
|
6055
|
+
* await live.connect({ force: true })
|
|
6056
|
+
* ```
|
|
5742
6057
|
*/
|
|
5743
6058
|
a(this, "connect", async (e = {}) => {
|
|
5744
6059
|
var s, r, o, c;
|
|
@@ -5764,8 +6079,10 @@ class Ir extends At {
|
|
|
5764
6079
|
}
|
|
5765
6080
|
});
|
|
5766
6081
|
/**
|
|
5767
|
-
*
|
|
5768
|
-
*
|
|
6082
|
+
* 退出带看(内部方法)
|
|
6083
|
+
* 清理数据并关闭连接,但不发送房间关闭消息
|
|
6084
|
+
*
|
|
6085
|
+
* @returns Promise<boolean> 关闭是否成功
|
|
5769
6086
|
*/
|
|
5770
6087
|
a(this, "_exit", async () => {
|
|
5771
6088
|
var e;
|
|
@@ -5778,13 +6095,37 @@ class Ir extends At {
|
|
|
5778
6095
|
return this.state !== j.OPEN ? !0 : await this._controller.close();
|
|
5779
6096
|
});
|
|
5780
6097
|
/**
|
|
5781
|
-
*
|
|
5782
|
-
*
|
|
6098
|
+
* 退出带看房间
|
|
6099
|
+
*
|
|
6100
|
+
* 这是 close 方法的别名,用于保持 API 的一致性。
|
|
6101
|
+
*
|
|
6102
|
+
* @returns Promise<void>
|
|
6103
|
+
* @example
|
|
6104
|
+
* ```typescript
|
|
6105
|
+
* // 退出带看
|
|
6106
|
+
* await live.exit()
|
|
6107
|
+
* ```
|
|
5783
6108
|
*/
|
|
5784
6109
|
a(this, "exit", async () => this.close());
|
|
5785
6110
|
/**
|
|
5786
6111
|
* 关闭带看房间
|
|
5787
|
-
*
|
|
6112
|
+
*
|
|
6113
|
+
* 关闭 WebSocket 连接、退出 RTC 房间,并发送房间关闭消息。
|
|
6114
|
+
* 与 exit 方法不同的是,此方法会通知服务器房间已关闭。
|
|
6115
|
+
*
|
|
6116
|
+
* @returns Promise<void>
|
|
6117
|
+
* @example
|
|
6118
|
+
* ```typescript
|
|
6119
|
+
* // 关闭房间
|
|
6120
|
+
* await live.close()
|
|
6121
|
+
*
|
|
6122
|
+
* // 在组件卸载时关闭
|
|
6123
|
+
* useEffect(() => {
|
|
6124
|
+
* return () => {
|
|
6125
|
+
* live.close()
|
|
6126
|
+
* }
|
|
6127
|
+
* }, [])
|
|
6128
|
+
* ```
|
|
5788
6129
|
*/
|
|
5789
6130
|
a(this, "close", async () => {
|
|
5790
6131
|
var e;
|
|
@@ -5794,11 +6135,27 @@ class Ir extends At {
|
|
|
5794
6135
|
} catch (n) {
|
|
5795
6136
|
m.warn(n);
|
|
5796
6137
|
}
|
|
5797
|
-
await this.updateStatus(
|
|
6138
|
+
await this.updateStatus(P.RoomChange, z.RoomClose, {});
|
|
5798
6139
|
});
|
|
5799
6140
|
/**
|
|
5800
|
-
*
|
|
5801
|
-
*
|
|
6141
|
+
* 销毁带看实例
|
|
6142
|
+
*
|
|
6143
|
+
* 完全销毁实例,清理所有资源,包括事件监听、Yjs 文档等。
|
|
6144
|
+
* 销毁后实例不能再使用,需要重新创建。
|
|
6145
|
+
*
|
|
6146
|
+
* @returns Promise<void>
|
|
6147
|
+
* @example
|
|
6148
|
+
* ```typescript
|
|
6149
|
+
* // 销毁实例
|
|
6150
|
+
* await live.dispose()
|
|
6151
|
+
*
|
|
6152
|
+
* // 在组件卸载时销毁
|
|
6153
|
+
* useEffect(() => {
|
|
6154
|
+
* return () => {
|
|
6155
|
+
* live.dispose()
|
|
6156
|
+
* }
|
|
6157
|
+
* }, [])
|
|
6158
|
+
* ```
|
|
5802
6159
|
*/
|
|
5803
6160
|
a(this, "dispose", async () => {
|
|
5804
6161
|
this._removeLiveControllerEventListeners();
|
|
@@ -5811,16 +6168,62 @@ class Ir extends At {
|
|
|
5811
6168
|
});
|
|
5812
6169
|
/**
|
|
5813
6170
|
* 设置自己的用户信息
|
|
5814
|
-
*
|
|
5815
|
-
*
|
|
6171
|
+
*
|
|
6172
|
+
* 更新当前用户在房间中的信息,如昵称、头像等。
|
|
6173
|
+
*
|
|
6174
|
+
* @param userInfo 用户信息的部分更新对象
|
|
6175
|
+
* @returns Promise<boolean> 是否更新成功
|
|
6176
|
+
* @example
|
|
6177
|
+
* ```typescript
|
|
6178
|
+
* // 更新昵称和头像
|
|
6179
|
+
* await live.setSelfInfo({
|
|
6180
|
+
* extension: {
|
|
6181
|
+
* nickname: '新昵称',
|
|
6182
|
+
* avatar: 'https://example.com/avatar.jpg'
|
|
6183
|
+
* }
|
|
6184
|
+
* })
|
|
6185
|
+
* ```
|
|
5816
6186
|
*/
|
|
5817
|
-
a(this, "setSelfInfo", async (e) => await this.updateStatus(
|
|
6187
|
+
a(this, "setSelfInfo", async (e) => await this.updateStatus(P.UserChange, z.UserInfo, e));
|
|
5818
6188
|
/**
|
|
5819
|
-
*
|
|
5820
|
-
*
|
|
5821
|
-
*
|
|
5822
|
-
*
|
|
5823
|
-
*
|
|
6189
|
+
* 自定义广播消息
|
|
6190
|
+
*
|
|
6191
|
+
* 向指定用户发送自定义消息,并等待响应。如果设置了超时时间,
|
|
6192
|
+
* 超时后会拒绝 Promise。
|
|
6193
|
+
*
|
|
6194
|
+
* @template Request 请求数据类型
|
|
6195
|
+
* @template Response 响应数据类型
|
|
6196
|
+
* @param request 广播请求的数据对象
|
|
6197
|
+
* @param toUserIds 目标用户ID,可以是单个字符串或字符串数组,空数组表示广播给所有人
|
|
6198
|
+
* @param timeout 超时时间(毫秒),0 表示不超时
|
|
6199
|
+
* @returns Promise<Response> 响应数据,连接未打开返回 false,发送失败返回 Error
|
|
6200
|
+
* @example
|
|
6201
|
+
* ```typescript
|
|
6202
|
+
* // 发送自定义消息并等待响应
|
|
6203
|
+
* try {
|
|
6204
|
+
* const response = await live.broadcast(
|
|
6205
|
+
* { type: 'ping', data: 'hello' },
|
|
6206
|
+
* ['user-id-1', 'user-id-2'],
|
|
6207
|
+
* 5000 // 5秒超时
|
|
6208
|
+
* )
|
|
6209
|
+
* console.log('收到响应:', response)
|
|
6210
|
+
* } catch (error) {
|
|
6211
|
+
* console.error('广播失败或超时:', error)
|
|
6212
|
+
* }
|
|
6213
|
+
*
|
|
6214
|
+
* // 广播给所有人
|
|
6215
|
+
* const response = await live.broadcast(
|
|
6216
|
+
* { type: 'announcement', message: '大家好' },
|
|
6217
|
+
* [],
|
|
6218
|
+
* 0 // 不超时
|
|
6219
|
+
* )
|
|
6220
|
+
*
|
|
6221
|
+
* // 监听广播消息
|
|
6222
|
+
* live.on('broadcast', (data, frontRequestId) => {
|
|
6223
|
+
* console.log('收到广播:', data)
|
|
6224
|
+
* // 可以在这里响应广播
|
|
6225
|
+
* })
|
|
6226
|
+
* ```
|
|
5824
6227
|
*/
|
|
5825
6228
|
a(this, "broadcast", (e, n, s) => this.state !== j.OPEN ? !1 : new Promise((r, o) => {
|
|
5826
6229
|
const c = we(B.CustomEvent, e, n), l = c.front_request_id, h = s ? setTimeout(() => {
|
|
@@ -5835,13 +6238,38 @@ class Ir extends At {
|
|
|
5835
6238
|
o(d);
|
|
5836
6239
|
}
|
|
5837
6240
|
}));
|
|
5838
|
-
|
|
6241
|
+
/**
|
|
6242
|
+
* 切换自己的麦克风状态
|
|
6243
|
+
*
|
|
6244
|
+
* 开启或关闭自己的麦克风。只有拥有 control_own_micro 权限的用户才能操作。
|
|
6245
|
+
*
|
|
6246
|
+
* @param microStatus 麦克风状态,true 表示开启,false 表示关闭
|
|
6247
|
+
* @returns Promise<boolean> 是否操作成功,无权限返回 false
|
|
6248
|
+
* @example
|
|
6249
|
+
* ```typescript
|
|
6250
|
+
* // 开启麦克风
|
|
6251
|
+
* const result = await live.toggleMicro(true)
|
|
6252
|
+
* if (result) {
|
|
6253
|
+
* console.log('麦克风已开启')
|
|
6254
|
+
* }
|
|
6255
|
+
*
|
|
6256
|
+
* // 关闭麦克风
|
|
6257
|
+
* await live.toggleMicro(false)
|
|
6258
|
+
*
|
|
6259
|
+
* // 检查权限
|
|
6260
|
+
* if (live.selfInfo?.permission?.control_own_micro) {
|
|
6261
|
+
* await live.toggleMicro(true)
|
|
6262
|
+
* } else {
|
|
6263
|
+
* console.log('没有权限控制麦克风')
|
|
6264
|
+
* }
|
|
6265
|
+
* ```
|
|
6266
|
+
*/
|
|
5839
6267
|
a(this, "toggleMicro", async (e) => {
|
|
5840
6268
|
var s, r, o;
|
|
5841
6269
|
if (!((r = (s = this.selfInfo) == null ? void 0 : s.permission) != null && r.control_own_micro)) return !1;
|
|
5842
6270
|
const n = await ((o = this.$RTC) == null ? void 0 : o.toggleMicro(e));
|
|
5843
6271
|
return n && await this.updateStatus(
|
|
5844
|
-
|
|
6272
|
+
P.UserChange,
|
|
5845
6273
|
z.UserMicroStatus,
|
|
5846
6274
|
{
|
|
5847
6275
|
status: e ? ot.OPEN : ot.CLOSE
|
|
@@ -5850,15 +6278,31 @@ class Ir extends At {
|
|
|
5850
6278
|
), n;
|
|
5851
6279
|
});
|
|
5852
6280
|
/**
|
|
5853
|
-
*
|
|
5854
|
-
*
|
|
5855
|
-
*
|
|
5856
|
-
*
|
|
6281
|
+
* 控制其他用户的麦克风状态
|
|
6282
|
+
*
|
|
6283
|
+
* 开启或关闭指定用户的麦克风。只有拥有 control_other_micro 权限的用户才能操作。
|
|
6284
|
+
*
|
|
6285
|
+
* @param microStatus 麦克风状态(MicroStatus.OPEN 或 MicroStatus.CLOSE)
|
|
6286
|
+
* @param toUserIds 目标用户ID,可以是单个字符串或字符串数组
|
|
6287
|
+
* @returns Promise<boolean> 是否操作成功,无权限或权限检查失败返回 false
|
|
6288
|
+
* @example
|
|
6289
|
+
* ```typescript
|
|
6290
|
+
* // 关闭某个用户的麦克风
|
|
6291
|
+
* await live.forbidMicro(MicroStatus.CLOSE, 'user-id-1')
|
|
6292
|
+
*
|
|
6293
|
+
* // 开启多个用户的麦克风
|
|
6294
|
+
* await live.forbidMicro(MicroStatus.OPEN, ['user-id-1', 'user-id-2'])
|
|
6295
|
+
*
|
|
6296
|
+
* // 检查权限
|
|
6297
|
+
* if (live.selfInfo?.permission?.control_other_micro) {
|
|
6298
|
+
* await live.forbidMicro(MicroStatus.CLOSE, 'user-id-1')
|
|
6299
|
+
* }
|
|
6300
|
+
* ```
|
|
5857
6301
|
*/
|
|
5858
6302
|
a(this, "forbidMicro", async (e, n) => {
|
|
5859
6303
|
var s, r;
|
|
5860
6304
|
return typeof this._options.canForbidUserMicro == "function" && !this._options.canForbidUserMicro(n) || !((r = (s = this.selfInfo) == null ? void 0 : s.permission) != null && r.control_other_micro) ? !1 : await this.updateStatus(
|
|
5861
|
-
|
|
6305
|
+
P.UserChange,
|
|
5862
6306
|
z.UserMicroStatus,
|
|
5863
6307
|
{
|
|
5864
6308
|
status: e
|
|
@@ -5867,29 +6311,56 @@ class Ir extends At {
|
|
|
5867
6311
|
);
|
|
5868
6312
|
});
|
|
5869
6313
|
/**
|
|
5870
|
-
*
|
|
5871
|
-
*
|
|
5872
|
-
*
|
|
5873
|
-
*
|
|
6314
|
+
* 控制其他用户的帧数据同步权限
|
|
6315
|
+
*
|
|
6316
|
+
* 允许或禁止指定用户同步全量帧数据。只有拥有 control_other_sync 权限的用户才能操作。
|
|
6317
|
+
*
|
|
6318
|
+
* @param sync 是否允许同步,true 表示允许,false 表示禁止
|
|
6319
|
+
* @param toUserIds 目标用户ID,可以是单个字符串或字符串数组
|
|
6320
|
+
* @returns Promise<boolean> 是否操作成功,无权限或权限检查失败返回 false
|
|
6321
|
+
* @example
|
|
6322
|
+
* ```typescript
|
|
6323
|
+
* // 禁止某个用户同步帧数据
|
|
6324
|
+
* await live.forbidSync(false, 'user-id-1')
|
|
6325
|
+
*
|
|
6326
|
+
* // 允许多个用户同步帧数据
|
|
6327
|
+
* await live.forbidSync(true, ['user-id-1', 'user-id-2'])
|
|
6328
|
+
* ```
|
|
5874
6329
|
*/
|
|
5875
6330
|
a(this, "forbidSync", async (e, n) => {
|
|
5876
6331
|
var s, r;
|
|
5877
6332
|
return typeof this._options.canForbidUserSync == "function" && !this._options.canForbidUserSync(n) || !((r = (s = this.selfInfo) == null ? void 0 : s.permission) != null && r.control_other_sync) ? !1 : await this.updateStatus(
|
|
5878
|
-
|
|
6333
|
+
P.UserChange,
|
|
5879
6334
|
z.UserPermission,
|
|
5880
6335
|
{ sync_frame: e },
|
|
5881
6336
|
n
|
|
5882
6337
|
);
|
|
5883
6338
|
});
|
|
5884
6339
|
/**
|
|
5885
|
-
*
|
|
5886
|
-
*
|
|
5887
|
-
*
|
|
6340
|
+
* 将用户踢出带看房间
|
|
6341
|
+
*
|
|
6342
|
+
* 强制将指定用户从房间中移除。只有拥有 change_other_status 权限的用户才能操作。
|
|
6343
|
+
*
|
|
6344
|
+
* @param toUserIds 目标用户ID,可以是单个字符串或字符串数组
|
|
6345
|
+
* @returns Promise<boolean> 是否操作成功,无权限或权限检查失败返回 false
|
|
6346
|
+
* @example
|
|
6347
|
+
* ```typescript
|
|
6348
|
+
* // 踢出单个用户
|
|
6349
|
+
* await live.kick('user-id-1')
|
|
6350
|
+
*
|
|
6351
|
+
* // 踢出多个用户
|
|
6352
|
+
* await live.kick(['user-id-1', 'user-id-2'])
|
|
6353
|
+
*
|
|
6354
|
+
* // 检查权限
|
|
6355
|
+
* if (live.selfInfo?.permission?.change_other_status) {
|
|
6356
|
+
* await live.kick('user-id-1')
|
|
6357
|
+
* }
|
|
6358
|
+
* ```
|
|
5888
6359
|
*/
|
|
5889
6360
|
a(this, "kick", async (e) => {
|
|
5890
6361
|
var n, s;
|
|
5891
6362
|
return typeof this._options.canForbidUserKick == "function" && !this._options.canForbidUserKick(e) || !((s = (n = this.selfInfo) == null ? void 0 : n.permission) != null && s.change_other_status) ? !1 : await this.updateStatus(
|
|
5892
|
-
|
|
6363
|
+
P.UserChange,
|
|
5893
6364
|
z.UserStatus,
|
|
5894
6365
|
{
|
|
5895
6366
|
status: "KICK_OUT"
|
|
@@ -5898,7 +6369,17 @@ class Ir extends At {
|
|
|
5898
6369
|
);
|
|
5899
6370
|
});
|
|
5900
6371
|
/**
|
|
5901
|
-
*
|
|
6372
|
+
* 获取指定键的帧数据快照
|
|
6373
|
+
*
|
|
6374
|
+
* 这是 getFramesByKey 方法的别名,用于保持 API 的一致性。
|
|
6375
|
+
*
|
|
6376
|
+
* @template Key 帧数据的键类型
|
|
6377
|
+
* @param key 帧数据的键值
|
|
6378
|
+
* @returns 对应键的帧数据,如果不存在则返回 undefined
|
|
6379
|
+
* @example
|
|
6380
|
+
* ```typescript
|
|
6381
|
+
* const cameraFrame = live.getSnapshotForKey('camera')
|
|
6382
|
+
* ```
|
|
5902
6383
|
*/
|
|
5903
6384
|
a(this, "getSnapshotForKey", (e) => this.snapshot[e]);
|
|
5904
6385
|
m.info("Initializing Live instance with options:", e), this._addLiveControllerEventListeners(), this._yDoc = new Ct({
|
|
@@ -5907,11 +6388,16 @@ class Ir extends At {
|
|
|
5907
6388
|
keyframes: this._yDoc.getMap("keyframes")
|
|
5908
6389
|
}, this._initializeKeyframesObservers(), this._initializeOptions(e), this._autoConnect(), this._debugSetup();
|
|
5909
6390
|
}
|
|
6391
|
+
/**
|
|
6392
|
+
* 获取带看的配置选项(只读)
|
|
6393
|
+
* @returns 冻结的配置选项对象
|
|
6394
|
+
*/
|
|
5910
6395
|
get options() {
|
|
5911
6396
|
return Object.freeze(this._options || {});
|
|
5912
6397
|
}
|
|
5913
6398
|
/**
|
|
5914
|
-
*
|
|
6399
|
+
* 获取当前带看连接状态
|
|
6400
|
+
* @returns 当前连接状态
|
|
5915
6401
|
*/
|
|
5916
6402
|
get state() {
|
|
5917
6403
|
return this._controller.state;
|
|
@@ -5919,6 +6405,7 @@ class Ir extends At {
|
|
|
5919
6405
|
/**
|
|
5920
6406
|
* 兼容老逻辑
|
|
5921
6407
|
* @deprecated 请直接读取 state 属性字段,未来将移除该属性
|
|
6408
|
+
* @returns 当前连接状态
|
|
5922
6409
|
*/
|
|
5923
6410
|
get readyState() {
|
|
5924
6411
|
return this._controller.state;
|
|
@@ -5926,53 +6413,122 @@ class Ir extends At {
|
|
|
5926
6413
|
/**
|
|
5927
6414
|
* 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
|
|
5928
6415
|
* @deprecated 带看不需要关注底层ws的相关信息,未来将移除
|
|
6416
|
+
* @returns WebSocket 连接 URL,如果未设置则返回 undefined
|
|
5929
6417
|
*/
|
|
5930
6418
|
get url() {
|
|
5931
6419
|
return this.options.url;
|
|
5932
6420
|
}
|
|
5933
6421
|
/**
|
|
5934
|
-
* 获取当前live
|
|
6422
|
+
* 获取当前 live 实例使用的 RTC 实例
|
|
6423
|
+
* @returns RTC 协议实例,用于语音通信
|
|
5935
6424
|
*/
|
|
5936
6425
|
get $RTC() {
|
|
5937
6426
|
return this._options.rtc;
|
|
5938
6427
|
}
|
|
5939
6428
|
/**
|
|
5940
|
-
* 获取当前live
|
|
6429
|
+
* 获取当前 live 实例使用的 jsBridge 实例
|
|
6430
|
+
* @returns JSBridge 协议实例,用于与原生 App 通信
|
|
5941
6431
|
*/
|
|
5942
6432
|
get jsBridge() {
|
|
5943
6433
|
return this._options.jsBridge;
|
|
5944
6434
|
}
|
|
5945
6435
|
/**
|
|
5946
|
-
*
|
|
6436
|
+
* 获取当前所有帧数据的快照
|
|
6437
|
+
*
|
|
6438
|
+
* @returns 当前帧数据的部分快照对象
|
|
6439
|
+
* @example
|
|
6440
|
+
* ```typescript
|
|
6441
|
+
* const snapshot = live.snapshot
|
|
6442
|
+
* console.log('当前相机位置:', snapshot.camera)
|
|
6443
|
+
* console.log('当前标注:', snapshot.annotation)
|
|
6444
|
+
* ```
|
|
5947
6445
|
*/
|
|
5948
6446
|
get snapshot() {
|
|
5949
6447
|
return this._buildInData.keyframes.toJSON();
|
|
5950
6448
|
}
|
|
5951
6449
|
/**
|
|
5952
|
-
*
|
|
6450
|
+
* 获取当前用户信息
|
|
6451
|
+
*
|
|
6452
|
+
* @returns 当前用户信息对象,如果尚未获取则返回 undefined
|
|
6453
|
+
* @example
|
|
6454
|
+
* ```typescript
|
|
6455
|
+
* const selfInfo = live.selfInfo
|
|
6456
|
+
* if (selfInfo) {
|
|
6457
|
+
* console.log('用户ID:', selfInfo.id)
|
|
6458
|
+
* console.log('麦克风状态:', selfInfo.micro_status)
|
|
6459
|
+
* console.log('用户权限:', selfInfo.permission)
|
|
6460
|
+
* }
|
|
6461
|
+
* ```
|
|
5953
6462
|
*/
|
|
5954
6463
|
get selfInfo() {
|
|
5955
6464
|
return this._buildInData.selfInfo;
|
|
5956
6465
|
}
|
|
5957
6466
|
/**
|
|
5958
|
-
*
|
|
6467
|
+
* 获取当前房间内的用户列表
|
|
6468
|
+
*
|
|
6469
|
+
* @returns 用户信息数组,如果尚未获取则返回空数组
|
|
6470
|
+
* @example
|
|
6471
|
+
* ```typescript
|
|
6472
|
+
* const users = live.userList
|
|
6473
|
+
* console.log(`房间内有 ${users.length} 个用户`)
|
|
6474
|
+
* users.forEach(user => {
|
|
6475
|
+
* console.log(`用户 ${user.id} 在线状态: ${user.current_ws_online}`)
|
|
6476
|
+
* })
|
|
6477
|
+
* ```
|
|
5959
6478
|
*/
|
|
5960
6479
|
get userList() {
|
|
5961
6480
|
return this._buildInData.userList || [];
|
|
5962
6481
|
}
|
|
5963
6482
|
/**
|
|
5964
|
-
*
|
|
6483
|
+
* 获取当前带看房间信息
|
|
6484
|
+
*
|
|
6485
|
+
* @returns 房间信息对象,如果尚未获取则返回 undefined
|
|
6486
|
+
* @example
|
|
6487
|
+
* ```typescript
|
|
6488
|
+
* const roomInfo = live.roomInfo
|
|
6489
|
+
* if (roomInfo) {
|
|
6490
|
+
* console.log('房间代码:', roomInfo.info.room_code)
|
|
6491
|
+
* console.log('房间状态:', roomInfo.info.status)
|
|
6492
|
+
* }
|
|
6493
|
+
* ```
|
|
5965
6494
|
*/
|
|
5966
6495
|
get roomInfo() {
|
|
5967
6496
|
return this._buildInData.roomInfo;
|
|
5968
6497
|
}
|
|
5969
6498
|
/**
|
|
5970
|
-
*
|
|
5971
|
-
*
|
|
5972
|
-
*
|
|
5973
|
-
*
|
|
5974
|
-
* @param
|
|
5975
|
-
* @
|
|
6499
|
+
* 更新带看状态
|
|
6500
|
+
*
|
|
6501
|
+
* 发送内置消息来更新用户或房间的状态。只有在连接状态为 OPEN 时才能发送。
|
|
6502
|
+
*
|
|
6503
|
+
* @param evtType 事件类型(用户变化或房间变化)
|
|
6504
|
+
* @param atnType 操作类型(如用户信息、麦克风状态、房间关闭等)
|
|
6505
|
+
* @param status 状态数据对象
|
|
6506
|
+
* @param toUserIds 目标用户ID(可选,不传则广播给所有人)
|
|
6507
|
+
* @returns 是否发送成功,连接未打开或发送失败返回 false
|
|
6508
|
+
* @example
|
|
6509
|
+
* ```typescript
|
|
6510
|
+
* // 更新用户信息
|
|
6511
|
+
* await live.updateStatus(
|
|
6512
|
+
* BuiltinEventType.UserChange,
|
|
6513
|
+
* BuiltinActionType.UserInfo,
|
|
6514
|
+
* { nickname: '新昵称', avatar: 'https://example.com/avatar.jpg' }
|
|
6515
|
+
* )
|
|
6516
|
+
*
|
|
6517
|
+
* // 关闭房间(仅管理员可用)
|
|
6518
|
+
* await live.updateStatus(
|
|
6519
|
+
* BuiltinEventType.RoomChange,
|
|
6520
|
+
* BuiltinActionType.RoomClose,
|
|
6521
|
+
* {}
|
|
6522
|
+
* )
|
|
6523
|
+
*
|
|
6524
|
+
* // 向特定用户发送状态更新
|
|
6525
|
+
* await live.updateStatus(
|
|
6526
|
+
* BuiltinEventType.UserChange,
|
|
6527
|
+
* BuiltinActionType.UserMicroStatus,
|
|
6528
|
+
* { status: MicroStatus.CLOSE },
|
|
6529
|
+
* ['user-id-1', 'user-id-2']
|
|
6530
|
+
* )
|
|
6531
|
+
* ```
|
|
5976
6532
|
*/
|
|
5977
6533
|
async updateStatus(e, n, s, r) {
|
|
5978
6534
|
if (this.state !== j.OPEN) return !1;
|
|
@@ -5996,52 +6552,52 @@ function Nr(i) {
|
|
|
5996
6552
|
return D.useEffect(() => (b.keyframes.on(f, C), T), I), T;
|
|
5997
6553
|
}
|
|
5998
6554
|
function d() {
|
|
5999
|
-
const f = r(), C =
|
|
6555
|
+
const f = r(), C = W(
|
|
6000
6556
|
async (O) => {
|
|
6001
6557
|
await f.connect(O);
|
|
6002
6558
|
},
|
|
6003
6559
|
[f]
|
|
6004
|
-
), R =
|
|
6560
|
+
), R = W(
|
|
6005
6561
|
(O) => {
|
|
6006
6562
|
f.toggleMicro(O);
|
|
6007
6563
|
},
|
|
6008
6564
|
[f]
|
|
6009
|
-
), b =
|
|
6565
|
+
), b = W(
|
|
6010
6566
|
async (O, H, ce = 0) => {
|
|
6011
6567
|
await f.broadcast(O, H, ce);
|
|
6012
6568
|
},
|
|
6013
6569
|
[f]
|
|
6014
|
-
), I =
|
|
6570
|
+
), I = W(async () => {
|
|
6015
6571
|
await f.exit();
|
|
6016
|
-
}, [f]), T =
|
|
6572
|
+
}, [f]), T = W(
|
|
6017
6573
|
async (O) => {
|
|
6018
6574
|
await f.kick(O);
|
|
6019
6575
|
},
|
|
6020
6576
|
[f]
|
|
6021
|
-
), F =
|
|
6577
|
+
), F = W(
|
|
6022
6578
|
async (O, H = []) => {
|
|
6023
6579
|
await f.forbidMicro(O, H);
|
|
6024
6580
|
},
|
|
6025
6581
|
[f]
|
|
6026
|
-
), rt =
|
|
6582
|
+
), rt = W(
|
|
6027
6583
|
(O, H = []) => {
|
|
6028
6584
|
f.forbidSync(O, H);
|
|
6029
6585
|
},
|
|
6030
6586
|
[f]
|
|
6031
|
-
), oe =
|
|
6587
|
+
), oe = W(
|
|
6032
6588
|
(O) => f.getFramesByKey(O),
|
|
6033
6589
|
[f]
|
|
6034
|
-
), en =
|
|
6590
|
+
), en = W(
|
|
6035
6591
|
(O, H) => {
|
|
6036
6592
|
f.sendKeyframe(O, H);
|
|
6037
6593
|
},
|
|
6038
6594
|
[f]
|
|
6039
|
-
), nn =
|
|
6595
|
+
), nn = W(
|
|
6040
6596
|
(O) => {
|
|
6041
6597
|
f.setSelfInfo(O);
|
|
6042
6598
|
},
|
|
6043
6599
|
[f]
|
|
6044
|
-
), sn =
|
|
6600
|
+
), sn = W(
|
|
6045
6601
|
(O, H, ce, rn) => {
|
|
6046
6602
|
f.updateStatus(O, H, ce, rn);
|
|
6047
6603
|
},
|
|
@@ -6139,15 +6695,15 @@ function Nr(i) {
|
|
|
6139
6695
|
}
|
|
6140
6696
|
const ye = globalThis.__REALSEE_LIVE_BADGE_LOG__;
|
|
6141
6697
|
(ye == null || ye) && console.log(
|
|
6142
|
-
"%c@realsee/live@0.7.
|
|
6698
|
+
"%c@realsee/live@0.7.4 (12/4/2025, 11:27:14 AM)",
|
|
6143
6699
|
"background: linear-gradient(to right, #1890ff, #52c41a); color: white; padding: 3px 6px; border-radius: 4px; font-weight: bold; text-shadow: 0 1px 0 rgba(0,0,0,0.2);"
|
|
6144
6700
|
);
|
|
6145
6701
|
export {
|
|
6146
6702
|
mn as BrowserRTC,
|
|
6147
|
-
|
|
6703
|
+
Pe as BrowserRTC4Chime,
|
|
6148
6704
|
fi as BuiltInRTCType,
|
|
6149
6705
|
z as BuiltinActionType,
|
|
6150
|
-
|
|
6706
|
+
P as BuiltinEventType,
|
|
6151
6707
|
B as Command,
|
|
6152
6708
|
Re as CoreRTC,
|
|
6153
6709
|
Ir as Live,
|
|
@@ -6156,6 +6712,7 @@ export {
|
|
|
6156
6712
|
ot as MicroStatus,
|
|
6157
6713
|
ht as RTCJoinedInfoCodeEnum,
|
|
6158
6714
|
ct as RTCType,
|
|
6715
|
+
At as Subscribe,
|
|
6159
6716
|
yn as UserStatus,
|
|
6160
6717
|
wn as VRWebViewRTC,
|
|
6161
6718
|
Cn as WebSocketCloseError,
|