@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.
Files changed (143) hide show
  1. package/dist/index.cjs.js +3 -3
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.es.js +687 -130
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/live/controller.d.ts +163 -42
  7. package/dist/live/createLive.d.ts +35 -3
  8. package/dist/live/createLiveReact.d.ts +51 -3
  9. package/dist/live/live.d.ts +501 -50
  10. package/dist/rtc/BrowserRTC.d.ts +63 -0
  11. package/dist/rtc/BrowserRTC4Chime.d.ts +38 -2
  12. package/dist/rtc/CoreRTC.d.ts +65 -1
  13. package/dist/rtc/VRWebViewRTC.d.ts +56 -6
  14. package/dist/typings/live/EventType.d.ts +58 -10
  15. package/dist/typings/live/GetVoiceSign.d.ts +27 -7
  16. package/dist/typings/live/UserInfo.d.ts +70 -0
  17. package/dist/typings/rtc/eventType.d.ts +55 -8
  18. package/dist/utils/appendUri.d.ts +17 -0
  19. package/dist/utils/uuid.d.ts +11 -1
  20. package/docs/.nojekyll +1 -0
  21. package/docs/assets/highlight.css +127 -0
  22. package/docs/assets/icons.js +18 -0
  23. package/docs/assets/icons.svg +1 -0
  24. package/docs/assets/main.js +60 -0
  25. package/docs/assets/navigation.js +1 -0
  26. package/docs/assets/search.js +1 -0
  27. package/docs/assets/style.css +1493 -0
  28. package/docs/classes/BrowserRTC.html +88 -0
  29. package/docs/classes/BrowserRTC4Chime.html +100 -0
  30. package/docs/classes/CoreRTC.html +65 -0
  31. package/docs/classes/Live.html +249 -0
  32. package/docs/classes/Subscribe.html +36 -0
  33. package/docs/classes/VRWebViewRTC.html +72 -0
  34. package/docs/enums/BuiltInRTCType.html +3 -0
  35. package/docs/enums/BuiltinActionType.html +14 -0
  36. package/docs/enums/BuiltinEventType.html +6 -0
  37. package/docs/enums/Command.html +22 -0
  38. package/docs/enums/LiveState.html +8 -0
  39. package/docs/enums/MemUserStatus.html +15 -0
  40. package/docs/enums/MicroStatus.html +6 -0
  41. package/docs/enums/RTCJoinedInfoCodeEnum.html +12 -0
  42. package/docs/enums/RTCType.html +5 -0
  43. package/docs/enums/UserStatus.html +8 -0
  44. package/docs/enums/WebSocketCloseError.html +20 -0
  45. package/docs/enums/WebSocketErrorType.html +8 -0
  46. package/docs/enums/WebSocketState.html +12 -0
  47. package/docs/functions/GetVoiceSignFn.html +20 -0
  48. package/docs/functions/_clearLiveInstanceIfNeed.html +1 -0
  49. package/docs/functions/createLive.html +9 -0
  50. package/docs/functions/createLiveReact.html +110 -0
  51. package/docs/functions/parseLiveMsg.html +4 -0
  52. package/docs/functions/parseWSClsErr.html +1 -0
  53. package/docs/hierarchy.html +1 -0
  54. package/docs/index.html +336 -0
  55. package/docs/interfaces/AttendeeResponse.html +4 -0
  56. package/docs/interfaces/LiveOptions.html +56 -0
  57. package/docs/interfaces/MeetingResponse.html +3 -0
  58. package/docs/interfaces/MeetingSessionConfigurationOptions.html +8 -0
  59. package/docs/interfaces/Permission.html +31 -0
  60. package/docs/interfaces/RTCJoinedInfo.html +7 -0
  61. package/docs/interfaces/RTCProtocol.html +65 -0
  62. package/docs/interfaces/SubscribeMixinType.emit.html +1 -0
  63. package/docs/interfaces/SubscribeMixinType.hasListener.html +1 -0
  64. package/docs/interfaces/SubscribeMixinType.off.html +1 -0
  65. package/docs/interfaces/SubscribeMixinType.on.html +1 -0
  66. package/docs/interfaces/SubscribeMixinType.once.html +1 -0
  67. package/docs/interfaces/VRWebViewRTCOptions.html +22 -0
  68. package/docs/modules/SubscribeMixinType.html +6 -0
  69. package/docs/modules.html +55 -0
  70. package/docs/types/BuiltinMsg.html +2 -0
  71. package/docs/types/EventMap.html +1 -0
  72. package/docs/types/EventType.html +2 -0
  73. package/docs/types/GetVoiceSign.html +3 -0
  74. package/docs/types/GetVoiceSignParams.html +5 -0
  75. package/docs/types/GetVoiceSignReturnType.html +6 -0
  76. package/docs/types/KeyframeEventType.html +2 -0
  77. package/docs/types/LiveBuiltInData.html +1 -0
  78. package/docs/types/LiveConnectOptions.html +8 -0
  79. package/docs/types/LiveEventType.html +41 -0
  80. package/docs/types/LiveMsg.html +2 -0
  81. package/docs/types/LiveProviderPropTypes.html +5 -0
  82. package/docs/types/RTCActionReactCallback.html +1 -0
  83. package/docs/types/RTCEventType.html +29 -0
  84. package/docs/types/ReqLiveMsg.html +6 -0
  85. package/docs/types/RoomInfo.html +1 -0
  86. package/docs/types/UserInfo.html +12 -0
  87. package/docs/types/UserInfoExt.html +5 -0
  88. package/docs/types/UserVolume.html +2 -0
  89. package/docs/types/WebSocketError.html +1 -0
  90. package/package.json +1 -2
  91. package/docs/README.md +0 -437
  92. package/docs/classes/BrowserRTC.md +0 -436
  93. package/docs/classes/BrowserRTC4Chime.md +0 -558
  94. package/docs/classes/CoreRTC.md +0 -448
  95. package/docs/classes/Live.md +0 -770
  96. package/docs/classes/VRWebViewRTC.md +0 -436
  97. package/docs/enumerations/BuiltInRTCType.md +0 -27
  98. package/docs/enumerations/BuiltinActionType.md +0 -81
  99. package/docs/enumerations/BuiltinEventType.md +0 -33
  100. package/docs/enumerations/Command.md +0 -107
  101. package/docs/enumerations/LiveState.md +0 -53
  102. package/docs/enumerations/MemUserStatus.md +0 -67
  103. package/docs/enumerations/MicroStatus.md +0 -33
  104. package/docs/enumerations/RTCJoinedInfoCodeEnum.md +0 -69
  105. package/docs/enumerations/RTCType.md +0 -39
  106. package/docs/enumerations/UserStatus.md +0 -45
  107. package/docs/enumerations/WebSocketCloseError.md +0 -117
  108. package/docs/enumerations/WebSocketErrorType.md +0 -77
  109. package/docs/enumerations/WebSocketState.md +0 -69
  110. package/docs/functions/GetVoiceSignFn.md +0 -27
  111. package/docs/functions/clearLiveInstanceIfNeed.md +0 -17
  112. package/docs/functions/createLive.md +0 -27
  113. package/docs/functions/createLiveReact.md +0 -449
  114. package/docs/functions/parseLiveMsg.md +0 -27
  115. package/docs/functions/parseWSClsErr.md +0 -21
  116. package/docs/globals.md +0 -71
  117. package/docs/interfaces/AttendeeResponse.md +0 -37
  118. package/docs/interfaces/LiveOptions.md +0 -246
  119. package/docs/interfaces/MeetingResponse.md +0 -55
  120. package/docs/interfaces/MeetingSessionConfigurationOptions.md +0 -93
  121. package/docs/interfaces/Permission.md +0 -147
  122. package/docs/interfaces/RTCJoinedInfo.md +0 -67
  123. package/docs/interfaces/RTCProtocol.md +0 -404
  124. package/docs/interfaces/VRWebViewRTCOptions.md +0 -41
  125. package/docs/type-aliases/BuiltinMsg.md +0 -41
  126. package/docs/type-aliases/EventType.md +0 -19
  127. package/docs/type-aliases/GetVoiceSign.md +0 -15
  128. package/docs/type-aliases/GetVoiceSignParams.md +0 -35
  129. package/docs/type-aliases/GetVoiceSignReturnType.md +0 -41
  130. package/docs/type-aliases/KeyframeEventType.md +0 -19
  131. package/docs/type-aliases/LiveBuiltInData.md +0 -47
  132. package/docs/type-aliases/LiveConnectOptions.md +0 -47
  133. package/docs/type-aliases/LiveEventType.md +0 -165
  134. package/docs/type-aliases/LiveMsg.md +0 -53
  135. package/docs/type-aliases/LiveProviderPropTypes.md +0 -27
  136. package/docs/type-aliases/RTCActionReactCallback.md +0 -13
  137. package/docs/type-aliases/RTCEventType.md +0 -65
  138. package/docs/type-aliases/ReqLiveMsg.md +0 -45
  139. package/docs/type-aliases/RoomInfo.md +0 -55
  140. package/docs/type-aliases/UserInfo.md +0 -77
  141. package/docs/type-aliases/UserInfoExt.md +0 -33
  142. package/docs/type-aliases/UserVolume.md +0 -25
  143. package/docs/type-aliases/WebSocketError.md +0 -31
@@ -15,90 +15,310 @@ export type LiveBuiltInData<KeyframesSnapshot> = {
15
15
  keyframes: Y.Map<KeyframesSnapshot>;
16
16
  };
17
17
  export declare const _clearLiveInstanceIfNeed: () => void;
18
+ /**
19
+ * Live 带看实例类
20
+ *
21
+ * 这是带看功能的核心类,负责管理 WebSocket 连接、帧数据同步、RTC 语音通信等功能。
22
+ * 通过 Yjs 实现帧数据的协同编辑和同步。
23
+ *
24
+ * @template KeyframesSnapshot 帧数据快照类型,必须是一个对象类型
25
+ * @example
26
+ * ```typescript
27
+ * // 定义帧数据类型
28
+ * interface MyKeyframes {
29
+ * camera: { position: [number, number, number] }
30
+ * annotation: { text: string; position: [number, number] }
31
+ * }
32
+ *
33
+ * // 创建 Live 实例
34
+ * const live = new Live<MyKeyframes>({
35
+ * url: 'wss://example.com/live',
36
+ * getTicket: async () => 'your-ticket',
37
+ * getVoiceSign: async (params) => ({ sdkAppId: 0, userId: '', userSig: '', roomId: '' }),
38
+ * useBuiltInRTC: true
39
+ * })
40
+ *
41
+ * // 监听状态变化
42
+ * live.on('stateChange', (state, prevState) => {
43
+ * console.log(`状态从 ${prevState} 变为 ${state}`)
44
+ * })
45
+ *
46
+ * // 连接带看
47
+ * await live.connect()
48
+ * ```
49
+ */
18
50
  export declare class Live<KeyframesSnapshot extends Record<string, any>> extends Subscribe<EventType<KeyframesSnapshot>> {
19
51
  /**
20
52
  * 带看的配置选项
21
53
  */
22
54
  private _options;
55
+ /**
56
+ * 获取带看的配置选项(只读)
57
+ * @returns 冻结的配置选项对象
58
+ */
23
59
  get options(): LiveOptions;
24
60
  /**
25
- * 带看状态
61
+ * 获取当前带看连接状态
62
+ * @returns 当前连接状态
26
63
  */
27
64
  get state(): LiveState;
28
65
  /**
29
66
  * 兼容老逻辑
30
67
  * @deprecated 请直接读取 state 属性字段,未来将移除该属性
68
+ * @returns 当前连接状态
31
69
  */
32
70
  get readyState(): LiveState;
33
71
  /**
34
72
  * 获取当前WebSocket连接的URL。(注意:这个是WebSocket连接的完整连接,附带一些query参数)。
35
73
  * @deprecated 带看不需要关注底层ws的相关信息,未来将移除
74
+ * @returns WebSocket 连接 URL,如果未设置则返回 undefined
36
75
  */
37
76
  get url(): string | undefined;
38
77
  /**
39
- * 获取当前live使用的RTC实例
78
+ * 获取当前 live 实例使用的 RTC 实例
79
+ * @returns RTC 协议实例,用于语音通信
40
80
  */
41
81
  get $RTC(): RTCProtocol;
42
82
  /**
43
- * 获取当前live使用的jsBridge实例
83
+ * 获取当前 live 实例使用的 jsBridge 实例
84
+ * @returns JSBridge 协议实例,用于与原生 App 通信
44
85
  */
45
86
  get jsBridge(): JSBridgeProtocol;
46
87
  /**
47
- * 帧数据监听
88
+ * 帧数据监听器
89
+ *
90
+ * 用于监听特定键的帧数据变化。当其他用户发送帧数据更新时,会触发对应键的事件。
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * // 监听 camera 帧数据的变化
95
+ * live.keyframes.on('camera', (nextFrame, prevFrame, frontRequestId) => {
96
+ * console.log('相机位置更新:', nextFrame)
97
+ * })
98
+ * ```
48
99
  */
49
100
  keyframes: Subscribe<KeyframeEventType<KeyframesSnapshot>>;
50
101
  /**
51
- * 带看的 yDoc
102
+ * 带看的 Yjs 文档实例(用于帧数据同步)
52
103
  */
53
104
  private _yDoc;
54
105
  /**
55
- * 内置的一些数据
106
+ * 内置的一些数据(用户信息、房间信息、帧数据等)
56
107
  */
57
108
  private _buildInData;
109
+ /**
110
+ * 创建 Live 带看实例
111
+ *
112
+ * @param opts 带看配置选项,包含以下属性:
113
+ * - url: WebSocket 连接地址(可选,可在 connect 时提供)
114
+ * - getTicket: 获取连接票据的函数(可选,可在 connect 时提供)
115
+ * - rtc: RTC 实例(可选,如果不提供会根据配置自动创建)
116
+ * - rtcType: 指定内置 RTC 类型(当 rtc 为空时使用)
117
+ * - useBuiltInRTC: 是否使用内置 RTC(默认根据环境自动选择)
118
+ * - getVoiceSign: 获取语音签名的函数(使用内置 RTC 时必需)
119
+ * - jsBridge: JSBridge 实例(可选,用于 App/WebView 环境)
120
+ * - useBuiltInJsBridge: 是否使用内置 JSBridge(默认 false)
121
+ * - initialMicroStatus: 麦克风初始状态(默认 OPEN)
122
+ * - autoPlayConfirm: 自动播放确认回调(使用 BrowserRTC 时可能需要)
123
+ * - __debug__: 是否开启调试模式(会在控制台打印日志)
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // 基础用法
128
+ * const live = new Live({
129
+ * url: 'wss://example.com/live',
130
+ * getTicket: async () => {
131
+ * const response = await fetch('/api/get-ticket')
132
+ * return response.json().ticket
133
+ * },
134
+ * getVoiceSign: async (params) => {
135
+ * const response = await fetch('/api/get-voice-sign', {
136
+ * method: 'POST',
137
+ * body: JSON.stringify(params)
138
+ * })
139
+ * return response.json()
140
+ * },
141
+ * useBuiltInRTC: true
142
+ * })
143
+ *
144
+ * // 使用自定义 RTC
145
+ * const customRTC = new MyCustomRTC()
146
+ * const live = new Live({
147
+ * rtc: customRTC,
148
+ * url: 'wss://example.com/live',
149
+ * getTicket: async () => 'ticket'
150
+ * })
151
+ * ```
152
+ */
58
153
  constructor(opts: LiveOptions);
59
154
  /**
60
- * 当前帧数据快照
155
+ * 获取当前所有帧数据的快照
156
+ *
157
+ * @returns 当前帧数据的部分快照对象
158
+ * @example
159
+ * ```typescript
160
+ * const snapshot = live.snapshot
161
+ * console.log('当前相机位置:', snapshot.camera)
162
+ * console.log('当前标注:', snapshot.annotation)
163
+ * ```
61
164
  */
62
165
  get snapshot(): Partial<KeyframesSnapshot>;
166
+ /**
167
+ * 初始化帧数据观察者(内部方法)
168
+ * 用于监听 Yjs Map 的变化并同步到其他用户
169
+ */
63
170
  _initializeKeyframesObservers: () => void;
171
+ /**
172
+ * 处理帧数据变化(内部方法)
173
+ * 当本地或远程帧数据发生变化时,会触发此方法进行同步
174
+ *
175
+ * @param event Yjs Map 事件对象
176
+ */
64
177
  _handleKeyframesChange: (event: Y.YMapEvent<KeyframesSnapshot>) => void;
65
178
  /**
66
- * 根据键值取帧数据
179
+ * 根据键值获取对应的帧数据
180
+ *
181
+ * @template Key 帧数据的键类型
67
182
  * @param key 帧数据的键值
68
- * @returns
183
+ * @returns 对应键的帧数据,如果不存在则返回 undefined
184
+ * @example
185
+ * ```typescript
186
+ * // 获取相机帧数据
187
+ * const cameraFrame = live.getFramesByKey('camera')
188
+ * if (cameraFrame) {
189
+ * console.log('相机位置:', cameraFrame.position)
190
+ * }
191
+ * ```
69
192
  */
70
193
  getFramesByKey: <Key extends keyof KeyframesSnapshot>(key: Key) => Partial<KeyframesSnapshot>[Key] | undefined;
71
194
  /**
72
195
  * 发送帧数据(需要能够被序列化)
196
+ *
197
+ * 将帧数据同步到其他用户。帧数据必须是可序列化的 JSON 对象。
198
+ * 只有在连接状态为 OPEN 时才能发送。
199
+ *
200
+ * @template Key 帧数据的键类型
73
201
  * @param key 帧数据键值
74
- * @param frame 帧数据本体
75
- * @returns 发送结果,成功返回true,失败返回false或Error
202
+ * @param frame 帧数据本体,必须可序列化
203
+ * @returns 发送结果,成功返回 true,连接未打开返回 false,其他错误返回 Error
204
+ * @example
205
+ * ```typescript
206
+ * // 发送相机位置更新
207
+ * const result = live.sendKeyframe('camera', {
208
+ * position: [1, 2, 3],
209
+ * rotation: [0, 0, 0]
210
+ * })
211
+ *
212
+ * if (result === true) {
213
+ * console.log('发送成功')
214
+ * } else {
215
+ * console.error('发送失败:', result)
216
+ * }
217
+ *
218
+ * // 发送标注更新
219
+ * live.sendKeyframe('annotation', {
220
+ * text: '这是一个标注',
221
+ * position: [100, 200]
222
+ * })
223
+ * ```
76
224
  */
77
225
  sendKeyframe: <Key extends keyof KeyframesSnapshot>(key: Key, frame: KeyframesSnapshot[Key]) => boolean | Error;
78
226
  /**
79
- * 当前用户信息
227
+ * 获取当前用户信息
228
+ *
229
+ * @returns 当前用户信息对象,如果尚未获取则返回 undefined
230
+ * @example
231
+ * ```typescript
232
+ * const selfInfo = live.selfInfo
233
+ * if (selfInfo) {
234
+ * console.log('用户ID:', selfInfo.id)
235
+ * console.log('麦克风状态:', selfInfo.micro_status)
236
+ * console.log('用户权限:', selfInfo.permission)
237
+ * }
238
+ * ```
80
239
  */
81
240
  get selfInfo(): UserInfo | undefined;
82
241
  /**
83
- * 当前用户列表
242
+ * 获取当前房间内的用户列表
243
+ *
244
+ * @returns 用户信息数组,如果尚未获取则返回空数组
245
+ * @example
246
+ * ```typescript
247
+ * const users = live.userList
248
+ * console.log(`房间内有 ${users.length} 个用户`)
249
+ * users.forEach(user => {
250
+ * console.log(`用户 ${user.id} 在线状态: ${user.current_ws_online}`)
251
+ * })
252
+ * ```
84
253
  */
85
254
  get userList(): UserInfo[];
86
255
  /**
87
- * 当前带看房间信息
256
+ * 获取当前带看房间信息
257
+ *
258
+ * @returns 房间信息对象,如果尚未获取则返回 undefined
259
+ * @example
260
+ * ```typescript
261
+ * const roomInfo = live.roomInfo
262
+ * if (roomInfo) {
263
+ * console.log('房间代码:', roomInfo.info.room_code)
264
+ * console.log('房间状态:', roomInfo.info.status)
265
+ * }
266
+ * ```
88
267
  */
89
268
  get roomInfo(): RoomInfo | undefined;
90
269
  /**
91
- * 带看控制器
270
+ * 带看控制器(内部使用)
92
271
  */
93
272
  private _controller;
273
+ /**
274
+ * 初始化配置选项(内部方法)
275
+ * @param opts 配置选项
276
+ */
94
277
  private _initializeOptions;
278
+ /**
279
+ * 初始化 JSBridge 实例(内部方法)
280
+ * @param opts 配置选项
281
+ * @returns JSBridge 实例或 undefined
282
+ */
95
283
  private _initializeJsBridge;
284
+ /**
285
+ * 初始化 RTC 实例(内部方法)
286
+ * @param opts 配置选项
287
+ * @returns RTC 实例或 undefined
288
+ */
96
289
  private _initializeRTC;
290
+ /**
291
+ * 创建内置 RTC 实例(内部方法)
292
+ * @param opts 配置选项
293
+ * @returns RTC 实例或 undefined
294
+ */
97
295
  private _createBuiltInRTC;
296
+ /**
297
+ * 创建 VRWebView RTC 实例(内部方法)
298
+ * @returns RTC 实例或 undefined
299
+ */
98
300
  private _createVRWebViewRTC;
301
+ /**
302
+ * 创建浏览器 RTC 实例(内部方法)
303
+ * @returns RTC 实例或 undefined
304
+ */
99
305
  private _createBrowserRTC;
306
+ /**
307
+ * 创建默认 RTC 实例(内部方法)
308
+ * 根据环境自动选择合适的 RTC 实现
309
+ * @param opts 配置选项
310
+ * @returns RTC 实例或 undefined
311
+ */
100
312
  private _createDefaultRTC;
313
+ /**
314
+ * 自动连接(内部方法)
315
+ * 如果配置中已提供 url 和 getTicket,则自动连接
316
+ */
101
317
  private _autoConnect;
318
+ /**
319
+ * 调试模式设置(内部方法)
320
+ * 在调试模式下,将实例挂载到 window 对象上
321
+ */
102
322
  private _debugSetup;
103
323
  /**
104
324
  * 添加带看控制的事件监听
@@ -124,77 +344,308 @@ export declare class Live<KeyframesSnapshot extends Record<string, any>> extends
124
344
  */
125
345
  private _clearLiveData;
126
346
  /**
127
- * 连接带看
128
- * @param options 连接选项
129
- * @returns 连接结果,成功返回true,失败返回Error
347
+ * 连接带看房间
348
+ *
349
+ * 建立 WebSocket 连接并加入带看房间。如果配置中已提供 url 和 getTicket,
350
+ * 可以在创建实例后自动连接,也可以手动调用此方法。
351
+ *
352
+ * @param options 连接选项,包含以下属性:
353
+ * - url: WebSocket 连接地址(可选,会覆盖构造函数中的配置)
354
+ * - getTicket: 获取连接票据的函数(可选,会覆盖构造函数中的配置)
355
+ * - rtcMicStatus: 麦克风初始状态(可选,会覆盖构造函数中的配置)
356
+ * - force: 是否强制连接(如果已有连接,会先关闭再连接)
357
+ * @returns 连接结果,成功返回 true,失败返回 Error
358
+ * @example
359
+ * ```typescript
360
+ * // 在创建实例时已配置 url 和 getTicket
361
+ * const live = new Live({
362
+ * url: 'wss://example.com/live',
363
+ * getTicket: async () => 'ticket'
364
+ * })
365
+ *
366
+ * // 手动连接
367
+ * const result = await live.connect()
368
+ * if (result === true) {
369
+ * console.log('连接成功')
370
+ * } else {
371
+ * console.error('连接失败:', result.message)
372
+ * }
373
+ *
374
+ * // 在连接时提供配置
375
+ * await live.connect({
376
+ * url: 'wss://example.com/live',
377
+ * getTicket: async () => {
378
+ * const res = await fetch('/api/ticket')
379
+ * return res.json().ticket
380
+ * },
381
+ * rtcMicStatus: MicroStatus.OPEN
382
+ * })
383
+ *
384
+ * // 强制重连
385
+ * await live.connect({ force: true })
386
+ * ```
130
387
  */
131
388
  connect: (options?: LiveConnectOptions) => Promise<true | Error>;
132
389
  /**
133
- * 退出带看
134
- * @returns
390
+ * 退出带看(内部方法)
391
+ * 清理数据并关闭连接,但不发送房间关闭消息
392
+ *
393
+ * @returns Promise<boolean> 关闭是否成功
135
394
  */
136
395
  _exit: () => Promise<boolean>;
137
396
  /**
138
- * 退出带看
139
- * @returns
397
+ * 退出带看房间
398
+ *
399
+ * 这是 close 方法的别名,用于保持 API 的一致性。
400
+ *
401
+ * @returns Promise<void>
402
+ * @example
403
+ * ```typescript
404
+ * // 退出带看
405
+ * await live.exit()
406
+ * ```
140
407
  */
141
408
  exit: () => Promise<void>;
142
409
  /**
143
410
  * 关闭带看房间
144
- * @returns 关闭结果
411
+ *
412
+ * 关闭 WebSocket 连接、退出 RTC 房间,并发送房间关闭消息。
413
+ * 与 exit 方法不同的是,此方法会通知服务器房间已关闭。
414
+ *
415
+ * @returns Promise<void>
416
+ * @example
417
+ * ```typescript
418
+ * // 关闭房间
419
+ * await live.close()
420
+ *
421
+ * // 在组件卸载时关闭
422
+ * useEffect(() => {
423
+ * return () => {
424
+ * live.close()
425
+ * }
426
+ * }, [])
427
+ * ```
145
428
  */
146
429
  close: () => Promise<void>;
147
430
  /**
148
- * 销毁带看
149
- * @returns
431
+ * 销毁带看实例
432
+ *
433
+ * 完全销毁实例,清理所有资源,包括事件监听、Yjs 文档等。
434
+ * 销毁后实例不能再使用,需要重新创建。
435
+ *
436
+ * @returns Promise<void>
437
+ * @example
438
+ * ```typescript
439
+ * // 销毁实例
440
+ * await live.dispose()
441
+ *
442
+ * // 在组件卸载时销毁
443
+ * useEffect(() => {
444
+ * return () => {
445
+ * live.dispose()
446
+ * }
447
+ * }, [])
448
+ * ```
150
449
  */
151
450
  dispose: () => Promise<boolean>;
152
451
  /**
153
- * 修改状态
154
- * @param evtType
155
- * @param atnType
156
- * @param status
157
- * @param toUserIds
158
- * @returns
452
+ * 更新带看状态
453
+ *
454
+ * 发送内置消息来更新用户或房间的状态。只有在连接状态为 OPEN 时才能发送。
455
+ *
456
+ * @param evtType 事件类型(用户变化或房间变化)
457
+ * @param atnType 操作类型(如用户信息、麦克风状态、房间关闭等)
458
+ * @param status 状态数据对象
459
+ * @param toUserIds 目标用户ID(可选,不传则广播给所有人)
460
+ * @returns 是否发送成功,连接未打开或发送失败返回 false
461
+ * @example
462
+ * ```typescript
463
+ * // 更新用户信息
464
+ * await live.updateStatus(
465
+ * BuiltinEventType.UserChange,
466
+ * BuiltinActionType.UserInfo,
467
+ * { nickname: '新昵称', avatar: 'https://example.com/avatar.jpg' }
468
+ * )
469
+ *
470
+ * // 关闭房间(仅管理员可用)
471
+ * await live.updateStatus(
472
+ * BuiltinEventType.RoomChange,
473
+ * BuiltinActionType.RoomClose,
474
+ * {}
475
+ * )
476
+ *
477
+ * // 向特定用户发送状态更新
478
+ * await live.updateStatus(
479
+ * BuiltinEventType.UserChange,
480
+ * BuiltinActionType.UserMicroStatus,
481
+ * { status: MicroStatus.CLOSE },
482
+ * ['user-id-1', 'user-id-2']
483
+ * )
484
+ * ```
159
485
  */
160
486
  updateStatus(evtType: BuiltinEventType, atnType: BuiltinActionType, status: Record<string, any>, toUserIds?: string | string[]): Promise<boolean>;
161
487
  /**
162
488
  * 设置自己的用户信息
163
- * @param userInfo
164
- * @returns
489
+ *
490
+ * 更新当前用户在房间中的信息,如昵称、头像等。
491
+ *
492
+ * @param userInfo 用户信息的部分更新对象
493
+ * @returns Promise<boolean> 是否更新成功
494
+ * @example
495
+ * ```typescript
496
+ * // 更新昵称和头像
497
+ * await live.setSelfInfo({
498
+ * extension: {
499
+ * nickname: '新昵称',
500
+ * avatar: 'https://example.com/avatar.jpg'
501
+ * }
502
+ * })
503
+ * ```
165
504
  */
166
505
  setSelfInfo: (userInfo: Partial<UserInfo>) => Promise<boolean>;
167
506
  /**
168
- * 自定义广播
169
- * @param request 广播请求的数据
170
- * @param toUserIds
171
- * @param timeout
172
- * @returns
507
+ * 自定义广播消息
508
+ *
509
+ * 向指定用户发送自定义消息,并等待响应。如果设置了超时时间,
510
+ * 超时后会拒绝 Promise。
511
+ *
512
+ * @template Request 请求数据类型
513
+ * @template Response 响应数据类型
514
+ * @param request 广播请求的数据对象
515
+ * @param toUserIds 目标用户ID,可以是单个字符串或字符串数组,空数组表示广播给所有人
516
+ * @param timeout 超时时间(毫秒),0 表示不超时
517
+ * @returns Promise<Response> 响应数据,连接未打开返回 false,发送失败返回 Error
518
+ * @example
519
+ * ```typescript
520
+ * // 发送自定义消息并等待响应
521
+ * try {
522
+ * const response = await live.broadcast(
523
+ * { type: 'ping', data: 'hello' },
524
+ * ['user-id-1', 'user-id-2'],
525
+ * 5000 // 5秒超时
526
+ * )
527
+ * console.log('收到响应:', response)
528
+ * } catch (error) {
529
+ * console.error('广播失败或超时:', error)
530
+ * }
531
+ *
532
+ * // 广播给所有人
533
+ * const response = await live.broadcast(
534
+ * { type: 'announcement', message: '大家好' },
535
+ * [],
536
+ * 0 // 不超时
537
+ * )
538
+ *
539
+ * // 监听广播消息
540
+ * live.on('broadcast', (data, frontRequestId) => {
541
+ * console.log('收到广播:', data)
542
+ * // 可以在这里响应广播
543
+ * })
544
+ * ```
173
545
  */
174
546
  broadcast: <Request extends Record<string, any>, Response>(request: Request, toUserIds: string | string[], timeout: number) => Promise<Response> | Error | false;
547
+ /**
548
+ * 切换自己的麦克风状态
549
+ *
550
+ * 开启或关闭自己的麦克风。只有拥有 control_own_micro 权限的用户才能操作。
551
+ *
552
+ * @param microStatus 麦克风状态,true 表示开启,false 表示关闭
553
+ * @returns Promise<boolean> 是否操作成功,无权限返回 false
554
+ * @example
555
+ * ```typescript
556
+ * // 开启麦克风
557
+ * const result = await live.toggleMicro(true)
558
+ * if (result) {
559
+ * console.log('麦克风已开启')
560
+ * }
561
+ *
562
+ * // 关闭麦克风
563
+ * await live.toggleMicro(false)
564
+ *
565
+ * // 检查权限
566
+ * if (live.selfInfo?.permission?.control_own_micro) {
567
+ * await live.toggleMicro(true)
568
+ * } else {
569
+ * console.log('没有权限控制麦克风')
570
+ * }
571
+ * ```
572
+ */
175
573
  toggleMicro: (microStatus: boolean) => Promise<boolean>;
176
574
  /**
177
- * 控制别人的麦
178
- * @param microStatus
179
- * @param toUserIds
180
- * @returns
575
+ * 控制其他用户的麦克风状态
576
+ *
577
+ * 开启或关闭指定用户的麦克风。只有拥有 control_other_micro 权限的用户才能操作。
578
+ *
579
+ * @param microStatus 麦克风状态(MicroStatus.OPEN 或 MicroStatus.CLOSE)
580
+ * @param toUserIds 目标用户ID,可以是单个字符串或字符串数组
581
+ * @returns Promise<boolean> 是否操作成功,无权限或权限检查失败返回 false
582
+ * @example
583
+ * ```typescript
584
+ * // 关闭某个用户的麦克风
585
+ * await live.forbidMicro(MicroStatus.CLOSE, 'user-id-1')
586
+ *
587
+ * // 开启多个用户的麦克风
588
+ * await live.forbidMicro(MicroStatus.OPEN, ['user-id-1', 'user-id-2'])
589
+ *
590
+ * // 检查权限
591
+ * if (live.selfInfo?.permission?.control_other_micro) {
592
+ * await live.forbidMicro(MicroStatus.CLOSE, 'user-id-1')
593
+ * }
594
+ * ```
181
595
  */
182
596
  forbidMicro: (microStatus: MicroStatus, toUserIds: string | string[]) => Promise<boolean>;
183
597
  /**
184
- * 控制别人的同步全量帧数据权限
185
- * @param sync
186
- * @param toUserIds
187
- * @returns
598
+ * 控制其他用户的帧数据同步权限
599
+ *
600
+ * 允许或禁止指定用户同步全量帧数据。只有拥有 control_other_sync 权限的用户才能操作。
601
+ *
602
+ * @param sync 是否允许同步,true 表示允许,false 表示禁止
603
+ * @param toUserIds 目标用户ID,可以是单个字符串或字符串数组
604
+ * @returns Promise<boolean> 是否操作成功,无权限或权限检查失败返回 false
605
+ * @example
606
+ * ```typescript
607
+ * // 禁止某个用户同步帧数据
608
+ * await live.forbidSync(false, 'user-id-1')
609
+ *
610
+ * // 允许多个用户同步帧数据
611
+ * await live.forbidSync(true, ['user-id-1', 'user-id-2'])
612
+ * ```
188
613
  */
189
614
  forbidSync: (sync: boolean, toUserIds: string | string[]) => Promise<boolean>;
190
615
  /**
191
- * 把用户踢出带看
192
- * @param toUserIds
193
- * @returns
616
+ * 将用户踢出带看房间
617
+ *
618
+ * 强制将指定用户从房间中移除。只有拥有 change_other_status 权限的用户才能操作。
619
+ *
620
+ * @param toUserIds 目标用户ID,可以是单个字符串或字符串数组
621
+ * @returns Promise<boolean> 是否操作成功,无权限或权限检查失败返回 false
622
+ * @example
623
+ * ```typescript
624
+ * // 踢出单个用户
625
+ * await live.kick('user-id-1')
626
+ *
627
+ * // 踢出多个用户
628
+ * await live.kick(['user-id-1', 'user-id-2'])
629
+ *
630
+ * // 检查权限
631
+ * if (live.selfInfo?.permission?.change_other_status) {
632
+ * await live.kick('user-id-1')
633
+ * }
634
+ * ```
194
635
  */
195
636
  kick: (toUserIds: string | string[]) => Promise<boolean>;
196
637
  /**
197
- * 获取当前某个 keyframe 的数据快照
638
+ * 获取指定键的帧数据快照
639
+ *
640
+ * 这是 getFramesByKey 方法的别名,用于保持 API 的一致性。
641
+ *
642
+ * @template Key 帧数据的键类型
643
+ * @param key 帧数据的键值
644
+ * @returns 对应键的帧数据,如果不存在则返回 undefined
645
+ * @example
646
+ * ```typescript
647
+ * const cameraFrame = live.getSnapshotForKey('camera')
648
+ * ```
198
649
  */
199
650
  getSnapshotForKey: <Key extends keyof KeyframesSnapshot>(key: Key) => any;
200
651
  }