@yrzhao/aves-core 0.1.0
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/LICENSE +21 -0
- package/README.md +428 -0
- package/dist/core/AvesClient.d.ts +84 -0
- package/dist/core/AvesClient.js +275 -0
- package/dist/core/EventEmitter.d.ts +40 -0
- package/dist/core/EventEmitter.js +82 -0
- package/dist/core/SignalingClient.d.ts +89 -0
- package/dist/core/SignalingClient.js +231 -0
- package/dist/core/WebRTCManager.d.ts +93 -0
- package/dist/core/WebRTCManager.js +308 -0
- package/dist/esm/core/AvesClient.d.ts +84 -0
- package/dist/esm/core/AvesClient.js +271 -0
- package/dist/esm/core/EventEmitter.d.ts +40 -0
- package/dist/esm/core/EventEmitter.js +78 -0
- package/dist/esm/core/SignalingClient.d.ts +89 -0
- package/dist/esm/core/SignalingClient.js +227 -0
- package/dist/esm/core/WebRTCManager.d.ts +93 -0
- package/dist/esm/core/WebRTCManager.js +304 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/types/types.d.ts +55 -0
- package/dist/esm/types/types.js +2 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +18 -0
- package/dist/types/types.d.ts +55 -0
- package/dist/types/types.js +3 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yrZhaoweb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
# Aves Core
|
|
2
|
+
|
|
3
|
+
一个轻量级的 WebRTC 客户端库,用于实时点对点通信。Aves Core 提供了简单的事件驱动 API,抽象了 WebRTC 的复杂性,让你专注于构建应用。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🚀 简单直观的 WebRTC 连接 API
|
|
8
|
+
- 🔄 自动连接管理和重连机制
|
|
9
|
+
- 📡 内置 WebSocket 信令客户端
|
|
10
|
+
- 🎯 事件驱动的状态管理架构
|
|
11
|
+
- 📦 完整的 TypeScript 类型定义支持
|
|
12
|
+
- 🔌 基于房间的通信模型
|
|
13
|
+
- 💬 DataChannel 消息传输,自动序列化
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install aves-core
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 快速开始
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { AvesClient } from "aves-core";
|
|
25
|
+
|
|
26
|
+
// 创建客户端实例
|
|
27
|
+
const client = new AvesClient({
|
|
28
|
+
signalingUrl: "ws://localhost:3000",
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 监听消息
|
|
32
|
+
client.on("message", (peerId, message) => {
|
|
33
|
+
console.log(`收到来自 ${peerId} 的消息:`, message);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 监听用户加入
|
|
37
|
+
client.on("userJoined", (participant) => {
|
|
38
|
+
console.log(`${participant.name} 加入了房间`);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// 创建房间
|
|
42
|
+
const roomId = await client.createRoom();
|
|
43
|
+
console.log("房间已创建:", roomId);
|
|
44
|
+
|
|
45
|
+
// 加入房间
|
|
46
|
+
const participants = await client.joinRoom(roomId, "user-123", "Alice");
|
|
47
|
+
console.log("已加入房间,当前参与者:", participants);
|
|
48
|
+
|
|
49
|
+
// 向所有对等端发送消息
|
|
50
|
+
client.sendMessage({ text: "大家好!" });
|
|
51
|
+
|
|
52
|
+
// 向特定对等端发送消息
|
|
53
|
+
client.sendMessageToPeer("peer-id", { text: "你好!" });
|
|
54
|
+
|
|
55
|
+
// 离开房间
|
|
56
|
+
await client.leaveRoom();
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 配置
|
|
60
|
+
|
|
61
|
+
### AvesClientConfig
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
interface AvesClientConfig {
|
|
65
|
+
signalingUrl: string; // 信令服务器的 WebSocket URL(必需)
|
|
66
|
+
iceServers?: RTCIceServer[]; // STUN/TURN 服务器(可选)
|
|
67
|
+
reconnect?: {
|
|
68
|
+
// 重连设置(可选)
|
|
69
|
+
maxAttempts?: number; // 最大重连次数(默认:5)
|
|
70
|
+
delay?: number; // 重连延迟(毫秒,默认:1000)
|
|
71
|
+
};
|
|
72
|
+
debug?: boolean; // 启用调试日志(默认:false)
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 默认配置
|
|
77
|
+
|
|
78
|
+
如果未指定,Aves Core 使用以下默认值:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
{
|
|
82
|
+
iceServers: [
|
|
83
|
+
{ urls: 'stun:stun.l.google.com:19302' }
|
|
84
|
+
],
|
|
85
|
+
reconnect: {
|
|
86
|
+
maxAttempts: 5,
|
|
87
|
+
delay: 1000
|
|
88
|
+
},
|
|
89
|
+
debug: false
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API 参考
|
|
94
|
+
|
|
95
|
+
### AvesClient
|
|
96
|
+
|
|
97
|
+
管理 WebRTC 连接的主类。
|
|
98
|
+
|
|
99
|
+
#### 构造函数
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
new AvesClient(config: AvesClientConfig)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
使用指定配置创建新的 AvesClient 实例。
|
|
106
|
+
|
|
107
|
+
#### 方法
|
|
108
|
+
|
|
109
|
+
##### 房间管理
|
|
110
|
+
|
|
111
|
+
**`createRoom(): Promise<string>`**
|
|
112
|
+
|
|
113
|
+
创建新房间并返回房间 ID。
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const roomId = await client.createRoom();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**`joinRoom(roomId: string, userId: string, userName: string): Promise<Participant[]>`**
|
|
120
|
+
|
|
121
|
+
加入现有房间并返回当前参与者列表。
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const participants = await client.joinRoom("room-123", "user-456", "Bob");
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**`leaveRoom(): Promise<void>`**
|
|
128
|
+
|
|
129
|
+
离开当前房间并关闭所有对等连接。
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
await client.leaveRoom();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
##### 消息传输
|
|
136
|
+
|
|
137
|
+
**`sendMessage(message: any): void`**
|
|
138
|
+
|
|
139
|
+
向房间内所有已连接的对等端发送消息。
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
client.sendMessage({ type: "chat", text: "Hello!" });
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**`sendMessageToPeer(peerId: string, message: any): void`**
|
|
146
|
+
|
|
147
|
+
向特定对等端发送消息。
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
client.sendMessageToPeer("peer-123", { type: "private", text: "Hi there!" });
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
##### 状态查询
|
|
154
|
+
|
|
155
|
+
**`getConnectionState(peerId: string): RTCPeerConnectionState`**
|
|
156
|
+
|
|
157
|
+
返回特定对等端的连接状态。
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const state = client.getConnectionState("peer-123");
|
|
161
|
+
// Returns: 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed'
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**`getParticipants(): Participant[]`**
|
|
165
|
+
|
|
166
|
+
返回当前房间内所有参与者的列表。
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const participants = client.getParticipants();
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**`isConnected(): boolean`**
|
|
173
|
+
|
|
174
|
+
返回信令连接是否处于活动状态。
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
if (client.isConnected()) {
|
|
178
|
+
console.log("已连接到信令服务器");
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
##### 生命周期
|
|
183
|
+
|
|
184
|
+
**`destroy(): void`**
|
|
185
|
+
|
|
186
|
+
销毁客户端,关闭所有连接并清理资源。
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
client.destroy();
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 事件
|
|
193
|
+
|
|
194
|
+
Aves Core 使用事件驱动架构。使用 `on`、`off` 和 `once` 方法订阅事件。
|
|
195
|
+
|
|
196
|
+
### 事件方法
|
|
197
|
+
|
|
198
|
+
**`on(event: string, callback: Function): this`**
|
|
199
|
+
|
|
200
|
+
注册事件监听器。
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
client.on("message", (peerId, message) => {
|
|
204
|
+
console.log("收到消息:", message);
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**`off(event: string, callback: Function): this`**
|
|
209
|
+
|
|
210
|
+
移除事件监听器。
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
const handler = (peerId, message) => console.log(message);
|
|
214
|
+
client.on("message", handler);
|
|
215
|
+
client.off("message", handler);
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
**`once(event: string, callback: Function): this`**
|
|
219
|
+
|
|
220
|
+
注册一次性事件监听器。
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
client.once("userJoined", (participant) => {
|
|
224
|
+
console.log("第一个用户加入:", participant);
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 可用事件
|
|
229
|
+
|
|
230
|
+
#### `connectionStateChange`
|
|
231
|
+
|
|
232
|
+
当对等连接状态改变时触发。
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
client.on(
|
|
236
|
+
"connectionStateChange",
|
|
237
|
+
(peerId: string, state: RTCPeerConnectionState) => {
|
|
238
|
+
console.log(`与 ${peerId} 的连接状态现在是 ${state}`);
|
|
239
|
+
}
|
|
240
|
+
);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
#### `dataChannelStateChange`
|
|
244
|
+
|
|
245
|
+
当数据通道状态改变时触发。
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
client.on(
|
|
249
|
+
"dataChannelStateChange",
|
|
250
|
+
(peerId: string, state: RTCDataChannelState) => {
|
|
251
|
+
console.log(`与 ${peerId} 的数据通道状态现在是 ${state}`);
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
#### `signalingStateChange`
|
|
257
|
+
|
|
258
|
+
当信令连接状态改变时触发。
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
client.on(
|
|
262
|
+
"signalingStateChange",
|
|
263
|
+
(state: "connecting" | "connected" | "disconnected") => {
|
|
264
|
+
console.log(`信令状态: ${state}`);
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### `message`
|
|
270
|
+
|
|
271
|
+
当从对等端接收到消息时触发。
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
client.on("message", (peerId: string, message: any) => {
|
|
275
|
+
console.log(`来自 ${peerId} 的消息:`, message);
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
#### `userJoined`
|
|
280
|
+
|
|
281
|
+
当新用户加入房间时触发。
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
client.on("userJoined", (participant: Participant) => {
|
|
285
|
+
console.log(`${participant.name} 加入了`);
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### `userLeft`
|
|
290
|
+
|
|
291
|
+
当用户离开房间时触发。
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
client.on("userLeft", (userId: string) => {
|
|
295
|
+
console.log(`用户 ${userId} 离开了`);
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
#### `error`
|
|
300
|
+
|
|
301
|
+
当发生错误时触发。
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
client.on("error", (error: Error) => {
|
|
305
|
+
console.error("错误:", error.message);
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## 类型定义
|
|
310
|
+
|
|
311
|
+
### Participant
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
interface Participant {
|
|
315
|
+
id: string; // 唯一用户 ID
|
|
316
|
+
name: string; // 显示名称
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### RTCPeerConnectionState
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
type RTCPeerConnectionState =
|
|
324
|
+
| "new"
|
|
325
|
+
| "connecting"
|
|
326
|
+
| "connected"
|
|
327
|
+
| "disconnected"
|
|
328
|
+
| "failed"
|
|
329
|
+
| "closed";
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### RTCDataChannelState
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
type RTCDataChannelState = "connecting" | "open" | "closing" | "closed";
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## 高级用法
|
|
339
|
+
|
|
340
|
+
### 自定义 ICE 服务器
|
|
341
|
+
|
|
342
|
+
配置自定义 STUN/TURN 服务器以获得更好的连接性:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const client = new AvesClient({
|
|
346
|
+
signalingUrl: "ws://localhost:3000",
|
|
347
|
+
iceServers: [
|
|
348
|
+
{ urls: "stun:stun.l.google.com:19302" },
|
|
349
|
+
{
|
|
350
|
+
urls: "turn:turn.example.com:3478",
|
|
351
|
+
username: "user",
|
|
352
|
+
credential: "pass",
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### 自定义重连策略
|
|
359
|
+
|
|
360
|
+
调整重连行为:
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
const client = new AvesClient({
|
|
364
|
+
signalingUrl: "ws://localhost:3000",
|
|
365
|
+
reconnect: {
|
|
366
|
+
maxAttempts: 10,
|
|
367
|
+
delay: 2000,
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### 调试模式
|
|
373
|
+
|
|
374
|
+
启用调试日志以进行故障排查:
|
|
375
|
+
|
|
376
|
+
```typescript
|
|
377
|
+
const client = new AvesClient({
|
|
378
|
+
signalingUrl: "ws://localhost:3000",
|
|
379
|
+
debug: true,
|
|
380
|
+
});
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## 错误处理
|
|
384
|
+
|
|
385
|
+
Aves Core 提供全面的错误处理:
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
client.on("error", (error) => {
|
|
389
|
+
if (error.message.includes("DataChannel not ready")) {
|
|
390
|
+
console.log("等待连接建立...");
|
|
391
|
+
} else if (error.message.includes("Room not found")) {
|
|
392
|
+
console.log("房间不存在");
|
|
393
|
+
} else {
|
|
394
|
+
console.error("意外错误:", error);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// 处理连接失败
|
|
399
|
+
client.on("connectionStateChange", (peerId, state) => {
|
|
400
|
+
if (state === "failed") {
|
|
401
|
+
console.log(`与 ${peerId} 的连接失败`);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// 处理信令断开
|
|
406
|
+
client.on("signalingStateChange", (state) => {
|
|
407
|
+
if (state === "disconnected") {
|
|
408
|
+
console.log("信令连接丢失,正在尝试重连...");
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## 浏览器兼容性
|
|
414
|
+
|
|
415
|
+
Aves Core 支持所有支持 WebRTC 的现代浏览器:
|
|
416
|
+
|
|
417
|
+
- Chrome/Edge 56+
|
|
418
|
+
- Firefox 44+
|
|
419
|
+
- Safari 11+
|
|
420
|
+
- Opera 43+
|
|
421
|
+
|
|
422
|
+
## 许可证
|
|
423
|
+
|
|
424
|
+
MIT
|
|
425
|
+
|
|
426
|
+
## 相关包
|
|
427
|
+
|
|
428
|
+
- [aves-node](https://www.npmjs.com/package/aves-node) - Aves Core 的信令服务器
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { EventEmitter } from "./EventEmitter";
|
|
2
|
+
import { AvesClientConfig, Participant } from "../types/types";
|
|
3
|
+
/**
|
|
4
|
+
* AvesClient - Main client class for WebRTC communication
|
|
5
|
+
*
|
|
6
|
+
* This class coordinates WebRTCManager and SignalingClient to provide
|
|
7
|
+
* a simple API for WebRTC-based real-time communication.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Room management (create, join, leave)
|
|
11
|
+
* - Automatic WebRTC connection establishment
|
|
12
|
+
* - Message sending and receiving
|
|
13
|
+
* - Connection state monitoring
|
|
14
|
+
* - Automatic reconnection
|
|
15
|
+
*/
|
|
16
|
+
export declare class AvesClient extends EventEmitter {
|
|
17
|
+
private config;
|
|
18
|
+
private webrtcManager;
|
|
19
|
+
private signalingClient;
|
|
20
|
+
private currentRoomId;
|
|
21
|
+
private currentUserId;
|
|
22
|
+
private participants;
|
|
23
|
+
constructor(config: AvesClientConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Setup event handlers to coordinate between components
|
|
26
|
+
*/
|
|
27
|
+
private setupEventHandlers;
|
|
28
|
+
/**
|
|
29
|
+
* Initiate a WebRTC connection with a peer (as offerer)
|
|
30
|
+
*/
|
|
31
|
+
private initiateConnection;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new room
|
|
34
|
+
* @returns Promise that resolves with the room ID
|
|
35
|
+
*/
|
|
36
|
+
createRoom(): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Join an existing room
|
|
39
|
+
* @param roomId - Room ID to join
|
|
40
|
+
* @param userId - User ID
|
|
41
|
+
* @param userName - User name
|
|
42
|
+
* @returns Promise that resolves with the list of current participants
|
|
43
|
+
*/
|
|
44
|
+
joinRoom(roomId: string, userId: string, userName: string): Promise<Participant[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Leave the current room
|
|
47
|
+
* Disconnects from signaling server and closes all WebRTC connections
|
|
48
|
+
*/
|
|
49
|
+
leaveRoom(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Send a message to all connected peers
|
|
52
|
+
* @param message - Message to send (will be JSON serialized)
|
|
53
|
+
* @throws Error if any DataChannel is not ready
|
|
54
|
+
*/
|
|
55
|
+
sendMessage(message: any): void;
|
|
56
|
+
/**
|
|
57
|
+
* Send a message to a specific peer
|
|
58
|
+
* @param peerId - Target peer ID
|
|
59
|
+
* @param message - Message to send (will be JSON serialized)
|
|
60
|
+
* @throws Error if DataChannel is not ready
|
|
61
|
+
*/
|
|
62
|
+
sendMessageToPeer(peerId: string, message: any): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get the connection state for a specific peer
|
|
65
|
+
* @param peerId - Peer ID
|
|
66
|
+
* @returns Connection state or 'closed' if peer not found
|
|
67
|
+
*/
|
|
68
|
+
getConnectionState(peerId: string): RTCPeerConnectionState;
|
|
69
|
+
/**
|
|
70
|
+
* Get the list of current participants in the room
|
|
71
|
+
* @returns Array of participants
|
|
72
|
+
*/
|
|
73
|
+
getParticipants(): Participant[];
|
|
74
|
+
/**
|
|
75
|
+
* Check if connected to the signaling server
|
|
76
|
+
* @returns true if connected, false otherwise
|
|
77
|
+
*/
|
|
78
|
+
isConnected(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Destroy the client and clean up all resources
|
|
81
|
+
* Closes all connections and removes all event listeners
|
|
82
|
+
*/
|
|
83
|
+
destroy(): void;
|
|
84
|
+
}
|