@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
@@ -4,115 +4,236 @@ import { RobustWebSocketEventDetail } from '../utils/RobustWebSocket';
4
4
  import { Subscribe } from '../utils/subscribe';
5
5
  /**
6
6
  * 带看控制器事件映射
7
+ *
8
+ * 定义了 LiveController 可以触发的事件类型
7
9
  */
8
10
  export type LiveControllerEventMap = {
9
11
  /**
10
- * 带看状态变更
11
- * @param state
12
- * @param prevState
13
- * @returns
12
+ * 带看连接状态变更事件
13
+ *
14
+ * @param state 当前连接状态
15
+ * @param prevState 之前的连接状态
14
16
  */
15
17
  stateChange: (state: LiveState, prevState: LiveState) => void;
16
18
  /**
17
- * 接收到带看消息
18
- * @param message
19
- * @returns
19
+ * 接收到带看消息事件
20
+ *
21
+ * @param message 接收到的消息对象
20
22
  */
21
23
  message: (message: LiveMsg) => void;
22
24
  /**
23
- * 带看重连中
24
- * @param detail
25
- * @returns
25
+ * 带看重连中事件
26
+ *
27
+ * 当 WebSocket 连接断开并开始重连时触发
28
+ *
29
+ * @param detail 重连详情,包含重连次数等信息
26
30
  */
27
31
  reconnecting: (detail: RobustWebSocketEventDetail) => void;
28
32
  /**
29
- * 带看重连成功
30
- * @param detail
31
- * @returns
33
+ * 带看重连成功事件
34
+ *
35
+ * 当 WebSocket 重连成功后触发
36
+ *
37
+ * @param detail 重连详情,包含重连次数等信息
32
38
  */
33
39
  reconnected: (detail: RobustWebSocketEventDetail) => void;
34
40
  };
35
41
  /**
36
- * 带看控制器
42
+ * 带看控制器类
43
+ *
44
+ * 负责管理 WebSocket 连接的建立、消息收发、重连等底层通信功能。
45
+ * 基于 RobustWebSocket 实现,提供自动重连能力。
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const controller = new LiveController()
50
+ *
51
+ * // 监听状态变化
52
+ * controller.on('stateChange', (state, prevState) => {
53
+ * console.log(`状态从 ${prevState} 变为 ${state}`)
54
+ * })
55
+ *
56
+ * // 监听消息
57
+ * controller.on('message', (message) => {
58
+ * console.log('收到消息:', message)
59
+ * })
60
+ *
61
+ * // 打开连接
62
+ * controller.open('wss://example.com/live')
63
+ *
64
+ * // 发送消息
65
+ * controller.sendMessage({ command: 'test', data: {} })
66
+ *
67
+ * // 关闭连接
68
+ * await controller.close()
69
+ * ```
37
70
  */
38
71
  export declare class LiveController extends Subscribe<LiveControllerEventMap> {
39
72
  /**
40
- * ws代理器
73
+ * WebSocket 代理器(内部使用)
74
+ * 基于 RobustWebSocket 实现,提供自动重连能力
41
75
  */
42
76
  private _ws;
43
77
  /**
44
- * 带看连接状态
78
+ * 带看连接状态(内部存储)
45
79
  */
46
80
  private _state;
81
+ /**
82
+ * 设置连接状态
83
+ *
84
+ * 当状态改变时,会自动触发 stateChange 事件
85
+ *
86
+ * @param state 新的连接状态
87
+ */
47
88
  set state(state: LiveState);
89
+ /**
90
+ * 获取当前连接状态
91
+ *
92
+ * @returns 当前连接状态
93
+ */
48
94
  get state(): LiveState;
95
+ /**
96
+ * 创建带看控制器实例
97
+ *
98
+ * 会自动初始化 WebSocket 事件监听器
99
+ */
49
100
  constructor();
50
101
  /**
51
- * 添加事件监听
102
+ * 添加 WebSocket 事件监听(内部方法)
103
+ * 监听 WebSocket 的各种事件并转换为控制器事件
52
104
  */
53
105
  private _addWebSocketEventListeners;
54
106
  /**
55
- * 移除事件监听
107
+ * 移除 WebSocket 事件监听(内部方法)
108
+ * 在销毁实例时调用,清理所有事件监听器
56
109
  */
57
110
  private _removeWebSocketEventListeners;
58
111
  /**
59
- * 处理房间关闭事件
60
- * @param event
112
+ * 处理 WebSocket 关闭事件(内部方法)
113
+ *
114
+ * @param event WebSocket 关闭事件对象
61
115
  */
62
116
  private _handleCloseEvent;
63
117
  /**
64
- * 处理房间正在关闭事件(这个时候可能是断网了)
118
+ * 处理 WebSocket 正在关闭事件(内部方法)
119
+ *
120
+ * 当连接正在关闭时触发,可能是由于网络断开等原因
65
121
  */
66
122
  private _handleClosingEvent;
67
123
  /**
68
- * 连接中
69
- * @param event
124
+ * 处理 WebSocket 连接中事件(内部方法)
125
+ *
126
+ * 当开始连接或重连时触发,如果是重连会触发 reconnecting 事件
127
+ *
128
+ * @param ev WebSocket 连接事件对象
70
129
  */
71
130
  private _handleConnectingEvent;
72
131
  /**
73
- * 连接发送异常
74
- * @param event
132
+ * 处理 WebSocket 错误事件(内部方法)
133
+ *
134
+ * @param event 错误事件对象
75
135
  */
76
136
  private _handleErrorEvent;
77
137
  /**
78
- * 接收到消息
79
- * @param event
138
+ * 处理 WebSocket 消息事件(内部方法)
139
+ *
140
+ * 解析接收到的消息并触发 message 事件
141
+ *
142
+ * @param event WebSocket 消息事件对象
80
143
  */
81
144
  private _handleMessageEvent;
82
145
  /**
83
- * 连接建立成功
84
- * @param event
146
+ * 处理 WebSocket 连接成功事件(内部方法)
147
+ *
148
+ * 当连接建立成功时触发,如果是重连成功会触发 reconnected 事件
149
+ *
150
+ * @param event WebSocket 打开事件对象
85
151
  */
86
152
  private _handleOpenEvent;
87
153
  /**
88
- * 处理超时
89
- * @param event
154
+ * 处理 WebSocket 连接超时事件(内部方法)
155
+ *
156
+ * @param event WebSocket 超时事件对象
90
157
  */
91
158
  private _handleTimeoutEvent;
92
159
  /**
93
- * 释放资源,释放之后需要重新实例化
94
- * @returns
160
+ * 释放控制器资源
161
+ *
162
+ * 移除所有事件监听器并关闭 WebSocket 连接。
163
+ * 释放后需要重新实例化才能使用。
164
+ *
165
+ * @returns Promise<boolean> 关闭是否成功
166
+ * @example
167
+ * ```typescript
168
+ * await controller.dispose()
169
+ * ```
95
170
  */
96
171
  dispose: () => Promise<boolean>;
97
172
  /**
98
- * 开启房间链接
99
- * @param url 房间链接
100
- * @returns
173
+ * 打开 WebSocket 连接
174
+ *
175
+ * 开始建立与服务器的 WebSocket 连接。
176
+ *
177
+ * @param url WebSocket 连接地址(ws:// 或 wss://)
178
+ * @example
179
+ * ```typescript
180
+ * controller.open('wss://example.com/live?ticket=xxx')
181
+ * ```
101
182
  */
102
183
  open: (url: string) => void;
103
184
  /**
104
- * 关闭房间
105
- * @param code
106
- * @param reason
185
+ * 关闭 WebSocket 连接
186
+ *
187
+ * 关闭与服务器的 WebSocket 连接。
188
+ *
189
+ * @param code 关闭代码(可选),WebSocket 关闭码
190
+ * @param reason 关闭原因(可选),关闭原因字符串
191
+ * @returns Promise<boolean> 关闭是否成功
192
+ * @example
193
+ * ```typescript
194
+ * // 正常关闭
195
+ * await controller.close()
196
+ *
197
+ * // 指定关闭码和原因
198
+ * await controller.close(1000, '正常关闭')
199
+ * ```
107
200
  */
108
201
  close: (code?: string | number | undefined, reason?: string | undefined) => Promise<boolean>;
109
202
  /**
110
- * 发送数据
111
- * @param data
203
+ * 发送消息到服务器
204
+ *
205
+ * 只有在连接状态为 OPEN 时才能发送消息。
206
+ * 消息会被自动序列化为 JSON 字符串。
207
+ *
208
+ * @param data 要发送的数据对象,不能为 undefined 或 null
209
+ * @returns 发送是否成功
210
+ * @throws {Error} 如果消息为空或连接未打开,会抛出错误
211
+ * @example
212
+ * ```typescript
213
+ * // 发送消息
214
+ * controller.sendMessage({
215
+ * command: 'test',
216
+ * data: { message: 'hello' }
217
+ * })
218
+ *
219
+ * // 检查连接状态
220
+ * if (controller.state === LiveState.OPEN) {
221
+ * controller.sendMessage({ command: 'ping' })
222
+ * }
223
+ * ```
112
224
  */
113
225
  sendMessage: (data?: any) => void | undefined;
114
226
  /**
115
- * 准备关闭带看
227
+ * 准备关闭带看连接
228
+ *
229
+ * 标记连接为显式关闭,防止自动重连。
230
+ * 通常在用户主动退出时调用。
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * controller.readyClose()
235
+ * await controller.close()
236
+ * ```
116
237
  */
117
238
  readyClose: () => void;
118
239
  }
@@ -1,8 +1,40 @@
1
1
  import { LiveOptions } from '../typings/live/LiveOptions';
2
2
  import { Live } from './live';
3
3
  /**
4
- * 创建`Live`实例
5
- * @param opts
6
- * @returns
4
+ * 创建 Live 带看实例
5
+ *
6
+ * 这是一个工厂函数,用于创建 Live 实例。在创建新实例前,会先清理全局的旧实例(如果存在)。
7
+ *
8
+ * @template KeyframesSnapshot 帧数据快照类型,必须是一个对象类型
9
+ * @param opts 带看配置选项,详见 {@link LiveOptions}
10
+ * @returns Live 实例
11
+ * @example
12
+ * ```typescript
13
+ * // 定义帧数据类型
14
+ * interface MyKeyframes {
15
+ * camera: { position: [number, number, number] }
16
+ * annotation: { text: string; position: [number, number] }
17
+ * }
18
+ *
19
+ * // 创建 Live 实例
20
+ * const live = createLive<MyKeyframes>({
21
+ * url: 'wss://example.com/live',
22
+ * getTicket: async () => {
23
+ * const response = await fetch('/api/get-ticket')
24
+ * return response.json().ticket
25
+ * },
26
+ * getVoiceSign: async (params) => {
27
+ * const response = await fetch('/api/get-voice-sign', {
28
+ * method: 'POST',
29
+ * body: JSON.stringify(params)
30
+ * })
31
+ * return response.json()
32
+ * },
33
+ * useBuiltInRTC: true
34
+ * })
35
+ *
36
+ * // 连接带看
37
+ * await live.connect()
38
+ * ```
7
39
  */
8
40
  export declare const createLive: <KeyframesSnapshot extends Record<string, any>>(opts: LiveOptions) => Live<KeyframesSnapshot>;
@@ -2,14 +2,62 @@ import { default as React } from 'react';
2
2
  import { BuiltinActionType, BuiltinEventType, KeyframeEventType, LiveConnectOptions, LiveEventType, LiveOptions, MicroStatus, RTCEventType, RTCType, UserInfo } from '../typings';
3
3
  import { LiveState } from '../typings/live/LiveState';
4
4
  import { Live } from './live';
5
+ /**
6
+ * LiveProvider 组件的属性类型
7
+ *
8
+ * @template KeyframesSnapshot 帧数据快照类型
9
+ */
5
10
  export type LiveProviderPropTypes<KeyframesSnapshot extends Record<string, any>> = {
11
+ /**
12
+ * 子组件
13
+ */
6
14
  children?: React.ReactNode;
15
+ /**
16
+ * 自定义 Live 实例(可选,默认使用内部创建的实例)
17
+ */
7
18
  live?: Live<KeyframesSnapshot>;
8
19
  };
9
20
  /**
10
- * 创建 LiveReact 实例,并提供 `React` 技术栈相关工具链。
11
- * @param options 带看配置
12
- * @returns 返回当前的带看上下文实例
21
+ * 创建 LiveReact 实例,并提供 React 技术栈相关工具链
22
+ *
23
+ * 这个函数会创建一个 Live 实例和一系列 React Hooks,用于在 React 组件中方便地使用带看功能。
24
+ * 返回的对象包含 LiveProvider 组件和各种 Hooks。
25
+ *
26
+ * @template KeyframesSnapshot 帧数据快照类型,必须是一个对象类型
27
+ * @param options 带看配置选项,详见 {@link LiveOptions}
28
+ * @returns 包含 LiveProvider 组件和各种 Hooks 的对象
29
+ * @example
30
+ * ```typescript
31
+ * // 定义帧数据类型
32
+ * interface MyKeyframes {
33
+ * camera: { position: [number, number, number] }
34
+ * annotation: { text: string; position: [number, number] }
35
+ * }
36
+ *
37
+ * // 创建 LiveReact 实例
38
+ * const { LiveProvider, useLiveAction, useKeyframe } = createLiveReact<MyKeyframes>({
39
+ * url: 'wss://example.com/live',
40
+ * getTicket: async () => 'ticket',
41
+ * getVoiceSign: async (params) => ({ sdkAppId: 0, userId: '', userSig: '', roomId: '' }),
42
+ * useBuiltInRTC: true
43
+ * })
44
+ *
45
+ * // 在组件中使用
46
+ * function App() {
47
+ * return (
48
+ * <LiveProvider>
49
+ * <MyComponent />
50
+ * </LiveProvider>
51
+ * )
52
+ * }
53
+ *
54
+ * function MyComponent() {
55
+ * const { connect, sendKeyframe } = useLiveAction()
56
+ * const [camera, setCamera] = useKeyframe('camera')
57
+ *
58
+ * // 使用带看功能...
59
+ * }
60
+ * ```
13
61
  */
14
62
  export declare function createLiveReact<KeyframesSnapshot extends Record<string, any>>(options: LiveOptions): {
15
63
  live: Live<KeyframesSnapshot>;