@realsee/live 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +209 -87
- 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 +644 -87
- 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/assets/highlight.css +34 -6
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/BrowserRTC.html +50 -22
- package/docs/classes/BrowserRTC4Chime.html +51 -23
- package/docs/classes/CoreRTC.html +28 -23
- package/docs/classes/Live.html +197 -41
- package/docs/classes/Subscribe.html +36 -0
- package/docs/classes/VRWebViewRTC.html +32 -13
- package/docs/enums/MemUserStatus.html +10 -2
- package/docs/functions/GetVoiceSignFn.html +20 -4
- package/docs/functions/createLive.html +9 -2
- package/docs/functions/createLiveReact.html +110 -17
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +80 -118
- package/docs/interfaces/LiveOptions.html +20 -4
- package/docs/interfaces/Permission.html +18 -2
- package/docs/interfaces/RTCProtocol.html +6 -6
- 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 +20 -4
- package/docs/modules/SubscribeMixinType.html +6 -0
- package/docs/modules.html +4 -1
- package/docs/types/EventMap.html +1 -0
- package/docs/types/EventType.html +1 -1
- package/docs/types/GetVoiceSign.html +2 -1
- package/docs/types/KeyframeEventType.html +1 -1
- package/docs/types/LiveEventType.html +38 -12
- package/docs/types/LiveProviderPropTypes.html +5 -1
- package/docs/types/RTCEventType.html +29 -7
- package/docs/types/UserInfo.html +1 -1
- package/docs/types/UserInfoExt.html +1 -1
- package/package.json +1 -1
|
@@ -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
|
-
*
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
12
|
+
* 带看连接状态变更事件
|
|
13
|
+
*
|
|
14
|
+
* @param state 当前连接状态
|
|
15
|
+
* @param prevState 之前的连接状态
|
|
14
16
|
*/
|
|
15
17
|
stateChange: (state: LiveState, prevState: LiveState) => void;
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
19
|
+
* 接收到带看消息事件
|
|
20
|
+
*
|
|
21
|
+
* @param message 接收到的消息对象
|
|
20
22
|
*/
|
|
21
23
|
message: (message: LiveMsg) => void;
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* 带看重连中事件
|
|
26
|
+
*
|
|
27
|
+
* 当 WebSocket 连接断开并开始重连时触发
|
|
28
|
+
*
|
|
29
|
+
* @param detail 重连详情,包含重连次数等信息
|
|
26
30
|
*/
|
|
27
31
|
reconnecting: (detail: RobustWebSocketEventDetail) => void;
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
124
|
+
* 处理 WebSocket 连接中事件(内部方法)
|
|
125
|
+
*
|
|
126
|
+
* 当开始连接或重连时触发,如果是重连会触发 reconnecting 事件
|
|
127
|
+
*
|
|
128
|
+
* @param ev WebSocket 连接事件对象
|
|
70
129
|
*/
|
|
71
130
|
private _handleConnectingEvent;
|
|
72
131
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
132
|
+
* 处理 WebSocket 错误事件(内部方法)
|
|
133
|
+
*
|
|
134
|
+
* @param event 错误事件对象
|
|
75
135
|
*/
|
|
76
136
|
private _handleErrorEvent;
|
|
77
137
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
138
|
+
* 处理 WebSocket 消息事件(内部方法)
|
|
139
|
+
*
|
|
140
|
+
* 解析接收到的消息并触发 message 事件
|
|
141
|
+
*
|
|
142
|
+
* @param event WebSocket 消息事件对象
|
|
80
143
|
*/
|
|
81
144
|
private _handleMessageEvent;
|
|
82
145
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
146
|
+
* 处理 WebSocket 连接成功事件(内部方法)
|
|
147
|
+
*
|
|
148
|
+
* 当连接建立成功时触发,如果是重连成功会触发 reconnected 事件
|
|
149
|
+
*
|
|
150
|
+
* @param event WebSocket 打开事件对象
|
|
85
151
|
*/
|
|
86
152
|
private _handleOpenEvent;
|
|
87
153
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
154
|
+
* 处理 WebSocket 连接超时事件(内部方法)
|
|
155
|
+
*
|
|
156
|
+
* @param event WebSocket 超时事件对象
|
|
90
157
|
*/
|
|
91
158
|
private _handleTimeoutEvent;
|
|
92
159
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
-
*
|
|
100
|
-
*
|
|
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
|
-
*
|
|
106
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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 实例,并提供
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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>;
|