@pulsebeam/peer 0.0.11 → 0.0.13
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 +2 -2
- package/dist/index.cjs +37 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +668 -0
- package/dist/index.d.ts +668 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
@@ -0,0 +1,668 @@
|
|
1
|
+
import { RpcOptions, UnaryCall } from '@protobuf-ts/runtime-rpc';
|
2
|
+
import { MessageType } from '@protobuf-ts/runtime';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @generated from protobuf enum pulsebeam.v1.SdpKind
|
6
|
+
*/
|
7
|
+
declare enum SdpKind {
|
8
|
+
/**
|
9
|
+
* @generated from protobuf enum value: SDP_KIND_UNSPECIFIED = 0;
|
10
|
+
*/
|
11
|
+
UNSPECIFIED = 0,
|
12
|
+
/**
|
13
|
+
* @generated from protobuf enum value: SDP_KIND_OFFER = 1;
|
14
|
+
*/
|
15
|
+
OFFER = 1,
|
16
|
+
/**
|
17
|
+
* @generated from protobuf enum value: SDP_KIND_ANSWER = 2;
|
18
|
+
*/
|
19
|
+
ANSWER = 2,
|
20
|
+
/**
|
21
|
+
* @generated from protobuf enum value: SDP_KIND_PRANSWER = 3;
|
22
|
+
*/
|
23
|
+
PRANSWER = 3,
|
24
|
+
/**
|
25
|
+
* @generated from protobuf enum value: SDP_KIND_ROLLBACK = 4;
|
26
|
+
*/
|
27
|
+
ROLLBACK = 4
|
28
|
+
}
|
29
|
+
declare class PrepareReq$Type extends MessageType<PrepareReq> {
|
30
|
+
constructor();
|
31
|
+
}
|
32
|
+
/**
|
33
|
+
* @generated from protobuf message pulsebeam.v1.PrepareReq
|
34
|
+
*/
|
35
|
+
interface PrepareReq {
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* @generated MessageType for protobuf message pulsebeam.v1.PrepareReq
|
39
|
+
*/
|
40
|
+
declare const PrepareReq: PrepareReq$Type;
|
41
|
+
declare class PrepareResp$Type extends MessageType<PrepareResp> {
|
42
|
+
constructor();
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* @generated from protobuf message pulsebeam.v1.PrepareResp
|
46
|
+
*/
|
47
|
+
interface PrepareResp {
|
48
|
+
/**
|
49
|
+
* @generated from protobuf field: repeated pulsebeam.v1.IceServer ice_servers = 1;
|
50
|
+
*/
|
51
|
+
iceServers: IceServer[];
|
52
|
+
}
|
53
|
+
/**
|
54
|
+
* @generated MessageType for protobuf message pulsebeam.v1.PrepareResp
|
55
|
+
*/
|
56
|
+
declare const PrepareResp: PrepareResp$Type;
|
57
|
+
declare class IceServer$Type extends MessageType<IceServer> {
|
58
|
+
constructor();
|
59
|
+
}
|
60
|
+
/**
|
61
|
+
* @generated from protobuf message pulsebeam.v1.IceServer
|
62
|
+
*/
|
63
|
+
interface IceServer {
|
64
|
+
/**
|
65
|
+
* @generated from protobuf field: repeated string urls = 1;
|
66
|
+
*/
|
67
|
+
urls: string[];
|
68
|
+
/**
|
69
|
+
* @generated from protobuf field: optional string username = 2;
|
70
|
+
*/
|
71
|
+
username?: string;
|
72
|
+
/**
|
73
|
+
* @generated from protobuf field: optional string credential = 3;
|
74
|
+
*/
|
75
|
+
credential?: string;
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* @generated MessageType for protobuf message pulsebeam.v1.IceServer
|
79
|
+
*/
|
80
|
+
declare const IceServer: IceServer$Type;
|
81
|
+
declare class SendReq$Type extends MessageType<SendReq> {
|
82
|
+
constructor();
|
83
|
+
}
|
84
|
+
/**
|
85
|
+
* @generated from protobuf message pulsebeam.v1.SendReq
|
86
|
+
*/
|
87
|
+
interface SendReq {
|
88
|
+
/**
|
89
|
+
* @generated from protobuf field: pulsebeam.v1.Message msg = 1;
|
90
|
+
*/
|
91
|
+
msg?: Message;
|
92
|
+
}
|
93
|
+
/**
|
94
|
+
* @generated MessageType for protobuf message pulsebeam.v1.SendReq
|
95
|
+
*/
|
96
|
+
declare const SendReq: SendReq$Type;
|
97
|
+
declare class SendResp$Type extends MessageType<SendResp> {
|
98
|
+
constructor();
|
99
|
+
}
|
100
|
+
/**
|
101
|
+
* @generated from protobuf message pulsebeam.v1.SendResp
|
102
|
+
*/
|
103
|
+
interface SendResp {
|
104
|
+
}
|
105
|
+
/**
|
106
|
+
* @generated MessageType for protobuf message pulsebeam.v1.SendResp
|
107
|
+
*/
|
108
|
+
declare const SendResp: SendResp$Type;
|
109
|
+
declare class RecvReq$Type extends MessageType<RecvReq> {
|
110
|
+
constructor();
|
111
|
+
}
|
112
|
+
/**
|
113
|
+
* @generated from protobuf message pulsebeam.v1.RecvReq
|
114
|
+
*/
|
115
|
+
interface RecvReq {
|
116
|
+
/**
|
117
|
+
* @generated from protobuf field: pulsebeam.v1.PeerInfo info = 1;
|
118
|
+
*/
|
119
|
+
info?: PeerInfo;
|
120
|
+
}
|
121
|
+
/**
|
122
|
+
* @generated MessageType for protobuf message pulsebeam.v1.RecvReq
|
123
|
+
*/
|
124
|
+
declare const RecvReq: RecvReq$Type;
|
125
|
+
declare class RecvResp$Type extends MessageType<RecvResp> {
|
126
|
+
constructor();
|
127
|
+
}
|
128
|
+
/**
|
129
|
+
* @generated from protobuf message pulsebeam.v1.RecvResp
|
130
|
+
*/
|
131
|
+
interface RecvResp {
|
132
|
+
/**
|
133
|
+
* @generated from protobuf field: repeated pulsebeam.v1.Message msgs = 1;
|
134
|
+
*/
|
135
|
+
msgs: Message[];
|
136
|
+
}
|
137
|
+
/**
|
138
|
+
* @generated MessageType for protobuf message pulsebeam.v1.RecvResp
|
139
|
+
*/
|
140
|
+
declare const RecvResp: RecvResp$Type;
|
141
|
+
declare class PeerInfo$Type extends MessageType<PeerInfo> {
|
142
|
+
constructor();
|
143
|
+
}
|
144
|
+
/**
|
145
|
+
* @generated from protobuf message pulsebeam.v1.PeerInfo
|
146
|
+
*/
|
147
|
+
interface PeerInfo {
|
148
|
+
/**
|
149
|
+
* @generated from protobuf field: uint32 conn_id = 1;
|
150
|
+
*/
|
151
|
+
connId: number;
|
152
|
+
/**
|
153
|
+
* @generated from protobuf field: bool enable_discovery = 2;
|
154
|
+
*/
|
155
|
+
enableDiscovery: boolean;
|
156
|
+
}
|
157
|
+
/**
|
158
|
+
* @generated MessageType for protobuf message pulsebeam.v1.PeerInfo
|
159
|
+
*/
|
160
|
+
declare const PeerInfo: PeerInfo$Type;
|
161
|
+
declare class Message$Type extends MessageType<Message> {
|
162
|
+
constructor();
|
163
|
+
}
|
164
|
+
/**
|
165
|
+
* Use small tag numbers (1-15) for fields that are frequently used or are performance-sensitive, even if they are optional.
|
166
|
+
* Larger tag numbers (16 and above) can be used for fields that are optional and not frequently included in messages, as they will require more bytes to encode.
|
167
|
+
* Avoid the 19000–19999 range, as it's reserved.
|
168
|
+
* Consider future-proofing your schema by leaving gaps between field numbers to allow for extensions or new fields later.
|
169
|
+
*
|
170
|
+
* @generated from protobuf message pulsebeam.v1.Message
|
171
|
+
*/
|
172
|
+
interface Message {
|
173
|
+
/**
|
174
|
+
* @generated from protobuf field: pulsebeam.v1.MessageHeader header = 1;
|
175
|
+
*/
|
176
|
+
header?: MessageHeader;
|
177
|
+
/**
|
178
|
+
* payload will be treated as opaque in backend. Size limit is 10kB.
|
179
|
+
*
|
180
|
+
* @generated from protobuf field: pulsebeam.v1.MessagePayload payload = 2;
|
181
|
+
*/
|
182
|
+
payload?: MessagePayload;
|
183
|
+
}
|
184
|
+
/**
|
185
|
+
* @generated MessageType for protobuf message pulsebeam.v1.Message
|
186
|
+
*/
|
187
|
+
declare const Message: Message$Type;
|
188
|
+
declare class MessagePayload$Type extends MessageType<MessagePayload> {
|
189
|
+
constructor();
|
190
|
+
}
|
191
|
+
/**
|
192
|
+
* @generated from protobuf message pulsebeam.v1.MessagePayload
|
193
|
+
*/
|
194
|
+
interface MessagePayload {
|
195
|
+
/**
|
196
|
+
* @generated from protobuf oneof: payload_type
|
197
|
+
*/
|
198
|
+
payloadType: {
|
199
|
+
oneofKind: "signal";
|
200
|
+
/**
|
201
|
+
* @generated from protobuf field: pulsebeam.v1.Signal signal = 1;
|
202
|
+
*/
|
203
|
+
signal: Signal;
|
204
|
+
} | {
|
205
|
+
oneofKind: "join";
|
206
|
+
/**
|
207
|
+
* @generated from protobuf field: pulsebeam.v1.Join join = 2;
|
208
|
+
*/
|
209
|
+
join: Join;
|
210
|
+
} | {
|
211
|
+
oneofKind: "bye";
|
212
|
+
/**
|
213
|
+
* @generated from protobuf field: pulsebeam.v1.Bye bye = 3;
|
214
|
+
*/
|
215
|
+
bye: Bye;
|
216
|
+
} | {
|
217
|
+
oneofKind: "ack";
|
218
|
+
/**
|
219
|
+
* @generated from protobuf field: pulsebeam.v1.Ack ack = 4;
|
220
|
+
*/
|
221
|
+
ack: Ack;
|
222
|
+
} | {
|
223
|
+
oneofKind: undefined;
|
224
|
+
};
|
225
|
+
}
|
226
|
+
/**
|
227
|
+
* @generated MessageType for protobuf message pulsebeam.v1.MessagePayload
|
228
|
+
*/
|
229
|
+
declare const MessagePayload: MessagePayload$Type;
|
230
|
+
declare class MessageHeader$Type extends MessageType<MessageHeader> {
|
231
|
+
constructor();
|
232
|
+
}
|
233
|
+
/**
|
234
|
+
* @generated from protobuf message pulsebeam.v1.MessageHeader
|
235
|
+
*/
|
236
|
+
interface MessageHeader {
|
237
|
+
/**
|
238
|
+
* @generated from protobuf field: string group_id = 1;
|
239
|
+
*/
|
240
|
+
groupId: string;
|
241
|
+
/**
|
242
|
+
* @generated from protobuf field: string peer_id = 2;
|
243
|
+
*/
|
244
|
+
peerId: string;
|
245
|
+
/**
|
246
|
+
* @generated from protobuf field: uint32 conn_id = 3;
|
247
|
+
*/
|
248
|
+
connId: number;
|
249
|
+
/**
|
250
|
+
* @generated from protobuf field: string other_group_id = 4;
|
251
|
+
*/
|
252
|
+
otherGroupId: string;
|
253
|
+
/**
|
254
|
+
* @generated from protobuf field: string other_peer_id = 5;
|
255
|
+
*/
|
256
|
+
otherPeerId: string;
|
257
|
+
/**
|
258
|
+
* @generated from protobuf field: uint32 other_conn_id = 6;
|
259
|
+
*/
|
260
|
+
otherConnId: number;
|
261
|
+
/**
|
262
|
+
* @generated from protobuf field: uint32 seqnum = 7;
|
263
|
+
*/
|
264
|
+
seqnum: number;
|
265
|
+
/**
|
266
|
+
* @generated from protobuf field: bool reliable = 8;
|
267
|
+
*/
|
268
|
+
reliable: boolean;
|
269
|
+
}
|
270
|
+
/**
|
271
|
+
* @generated MessageType for protobuf message pulsebeam.v1.MessageHeader
|
272
|
+
*/
|
273
|
+
declare const MessageHeader: MessageHeader$Type;
|
274
|
+
declare class Signal$Type extends MessageType<Signal> {
|
275
|
+
constructor();
|
276
|
+
}
|
277
|
+
/**
|
278
|
+
* @generated from protobuf message pulsebeam.v1.Signal
|
279
|
+
*/
|
280
|
+
interface Signal {
|
281
|
+
/**
|
282
|
+
* @generated from protobuf field: uint32 generation_counter = 1;
|
283
|
+
*/
|
284
|
+
generationCounter: number;
|
285
|
+
/**
|
286
|
+
* @generated from protobuf oneof: data
|
287
|
+
*/
|
288
|
+
data: {
|
289
|
+
oneofKind: "sdp";
|
290
|
+
/**
|
291
|
+
* @generated from protobuf field: pulsebeam.v1.Sdp sdp = 9;
|
292
|
+
*/
|
293
|
+
sdp: Sdp;
|
294
|
+
} | {
|
295
|
+
oneofKind: "iceCandidate";
|
296
|
+
/**
|
297
|
+
* @generated from protobuf field: pulsebeam.v1.ICECandidate ice_candidate = 10;
|
298
|
+
*/
|
299
|
+
iceCandidate: ICECandidate;
|
300
|
+
} | {
|
301
|
+
oneofKind: undefined;
|
302
|
+
};
|
303
|
+
}
|
304
|
+
/**
|
305
|
+
* @generated MessageType for protobuf message pulsebeam.v1.Signal
|
306
|
+
*/
|
307
|
+
declare const Signal: Signal$Type;
|
308
|
+
declare class Sdp$Type extends MessageType<Sdp> {
|
309
|
+
constructor();
|
310
|
+
}
|
311
|
+
/**
|
312
|
+
* @generated from protobuf message pulsebeam.v1.Sdp
|
313
|
+
*/
|
314
|
+
interface Sdp {
|
315
|
+
/**
|
316
|
+
* @generated from protobuf field: pulsebeam.v1.SdpKind kind = 1;
|
317
|
+
*/
|
318
|
+
kind: SdpKind;
|
319
|
+
/**
|
320
|
+
* @generated from protobuf field: string sdp = 2;
|
321
|
+
*/
|
322
|
+
sdp: string;
|
323
|
+
}
|
324
|
+
/**
|
325
|
+
* @generated MessageType for protobuf message pulsebeam.v1.Sdp
|
326
|
+
*/
|
327
|
+
declare const Sdp: Sdp$Type;
|
328
|
+
declare class ICECandidate$Type extends MessageType<ICECandidate> {
|
329
|
+
constructor();
|
330
|
+
}
|
331
|
+
/**
|
332
|
+
* @generated from protobuf message pulsebeam.v1.ICECandidate
|
333
|
+
*/
|
334
|
+
interface ICECandidate {
|
335
|
+
/**
|
336
|
+
* @generated from protobuf field: string candidate = 1;
|
337
|
+
*/
|
338
|
+
candidate: string;
|
339
|
+
/**
|
340
|
+
* @generated from protobuf field: optional uint32 sdp_m_line_index = 2;
|
341
|
+
*/
|
342
|
+
sdpMLineIndex?: number;
|
343
|
+
/**
|
344
|
+
* @generated from protobuf field: optional string sdp_mid = 3;
|
345
|
+
*/
|
346
|
+
sdpMid?: string;
|
347
|
+
/**
|
348
|
+
* @generated from protobuf field: optional string username = 4;
|
349
|
+
*/
|
350
|
+
username?: string;
|
351
|
+
/**
|
352
|
+
* @generated from protobuf field: optional string password = 5;
|
353
|
+
*/
|
354
|
+
password?: string;
|
355
|
+
}
|
356
|
+
/**
|
357
|
+
* @generated MessageType for protobuf message pulsebeam.v1.ICECandidate
|
358
|
+
*/
|
359
|
+
declare const ICECandidate: ICECandidate$Type;
|
360
|
+
declare class Join$Type extends MessageType<Join> {
|
361
|
+
constructor();
|
362
|
+
}
|
363
|
+
/**
|
364
|
+
* @generated from protobuf message pulsebeam.v1.Join
|
365
|
+
*/
|
366
|
+
interface Join {
|
367
|
+
}
|
368
|
+
/**
|
369
|
+
* @generated MessageType for protobuf message pulsebeam.v1.Join
|
370
|
+
*/
|
371
|
+
declare const Join: Join$Type;
|
372
|
+
declare class Bye$Type extends MessageType<Bye> {
|
373
|
+
constructor();
|
374
|
+
}
|
375
|
+
/**
|
376
|
+
* @generated from protobuf message pulsebeam.v1.Bye
|
377
|
+
*/
|
378
|
+
interface Bye {
|
379
|
+
}
|
380
|
+
/**
|
381
|
+
* @generated MessageType for protobuf message pulsebeam.v1.Bye
|
382
|
+
*/
|
383
|
+
declare const Bye: Bye$Type;
|
384
|
+
declare class Ack$Type extends MessageType<Ack> {
|
385
|
+
constructor();
|
386
|
+
}
|
387
|
+
/**
|
388
|
+
* @generated from protobuf message pulsebeam.v1.Ack
|
389
|
+
*/
|
390
|
+
interface Ack {
|
391
|
+
/**
|
392
|
+
* @generated from protobuf field: repeated pulsebeam.v1.AckRange ack_ranges = 1;
|
393
|
+
*/
|
394
|
+
ackRanges: AckRange[];
|
395
|
+
}
|
396
|
+
/**
|
397
|
+
* @generated MessageType for protobuf message pulsebeam.v1.Ack
|
398
|
+
*/
|
399
|
+
declare const Ack: Ack$Type;
|
400
|
+
declare class AckRange$Type extends MessageType<AckRange> {
|
401
|
+
constructor();
|
402
|
+
}
|
403
|
+
/**
|
404
|
+
* @generated from protobuf message pulsebeam.v1.AckRange
|
405
|
+
*/
|
406
|
+
interface AckRange {
|
407
|
+
/**
|
408
|
+
* @generated from protobuf field: uint32 seqnum_start = 1;
|
409
|
+
*/
|
410
|
+
seqnumStart: number;
|
411
|
+
/**
|
412
|
+
* @generated from protobuf field: uint32 seqnum_end = 2;
|
413
|
+
*/
|
414
|
+
seqnumEnd: number;
|
415
|
+
}
|
416
|
+
/**
|
417
|
+
* @generated MessageType for protobuf message pulsebeam.v1.AckRange
|
418
|
+
*/
|
419
|
+
declare const AckRange: AckRange$Type;
|
420
|
+
|
421
|
+
/**
|
422
|
+
* @generated from protobuf service pulsebeam.v1.Tunnel
|
423
|
+
*/
|
424
|
+
interface ITunnelClient {
|
425
|
+
/**
|
426
|
+
* @generated from protobuf rpc: Prepare(pulsebeam.v1.PrepareReq) returns (pulsebeam.v1.PrepareResp);
|
427
|
+
*/
|
428
|
+
prepare(input: PrepareReq, options?: RpcOptions): UnaryCall<PrepareReq, PrepareResp>;
|
429
|
+
/**
|
430
|
+
* @generated from protobuf rpc: Send(pulsebeam.v1.SendReq) returns (pulsebeam.v1.SendResp);
|
431
|
+
*/
|
432
|
+
send(input: SendReq, options?: RpcOptions): UnaryCall<SendReq, SendResp>;
|
433
|
+
/**
|
434
|
+
* @generated from protobuf rpc: Recv(pulsebeam.v1.RecvReq) returns (pulsebeam.v1.RecvResp);
|
435
|
+
*/
|
436
|
+
recv(input: RecvReq, options?: RpcOptions): UnaryCall<RecvReq, RecvResp>;
|
437
|
+
}
|
438
|
+
|
439
|
+
type LogObj = Record<string, unknown>;
|
440
|
+
type LogHandler = (_obj: LogObj) => void;
|
441
|
+
type LogSink = {
|
442
|
+
"DEBUG": LogHandler;
|
443
|
+
"INFO": LogHandler;
|
444
|
+
"WARN": LogHandler;
|
445
|
+
"ERROR": LogHandler;
|
446
|
+
};
|
447
|
+
declare class Logger {
|
448
|
+
readonly name: string;
|
449
|
+
private readonly obj;
|
450
|
+
private readonly sink;
|
451
|
+
constructor(name: string, obj?: LogObj, sink?: LogSink);
|
452
|
+
private log;
|
453
|
+
debug(message: string, obj?: LogObj): void;
|
454
|
+
info(message: string, obj?: LogObj): void;
|
455
|
+
warn(message: string, obj?: LogObj): void;
|
456
|
+
error(message: string, obj?: LogObj): void;
|
457
|
+
sub(name: string, obj?: LogObj): Logger;
|
458
|
+
}
|
459
|
+
|
460
|
+
/**
|
461
|
+
* A high-level API for managing the peer-to-peer WebRTC connection. Provides
|
462
|
+
* access to lower-level {@link RTCPeerConnection} functionality. Including
|
463
|
+
* access to underlying media tracks, data channels, and connection state.
|
464
|
+
*
|
465
|
+
* Usage:
|
466
|
+
* @example `peer.onsession = (session) => {console.log(session.otherPeerId())};`
|
467
|
+
*/
|
468
|
+
interface ISession {
|
469
|
+
/**
|
470
|
+
* Adds a media track to the connection. Typically used for sending audio or video.
|
471
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack}
|
472
|
+
* @returns {RTCRtpSender}
|
473
|
+
*/
|
474
|
+
addTrack(...args: Parameters<RTCPeerConnection["addTrack"]>): RTCRtpSender;
|
475
|
+
/**
|
476
|
+
* Removes a media track from the connection. Useful for stopping
|
477
|
+
* transmission of a specific track.
|
478
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/removeTrack}
|
479
|
+
* @returns {void}
|
480
|
+
*/
|
481
|
+
removeTrack(...args: Parameters<RTCPeerConnection["removeTrack"]>): void;
|
482
|
+
/**
|
483
|
+
* Creates a {@link RTCDataChannel} on the connection for arbitrary data transfer.
|
484
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/createDataChannel}
|
485
|
+
*/
|
486
|
+
createDataChannel(...args: Parameters<RTCPeerConnection["createDataChannel"]>): RTCDataChannel;
|
487
|
+
/**
|
488
|
+
* Retrieves the current connection state of the underlying RTCPeerConnection
|
489
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState}
|
490
|
+
* @returns {RTCPeerConnectionState}
|
491
|
+
*/
|
492
|
+
get connectionState(): RTCPeerConnectionState;
|
493
|
+
/**
|
494
|
+
* Callback triggered when a {@link RTCDataChannel} is created or received.
|
495
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/ondatachannel}
|
496
|
+
* @example ```peer.onsession = (session) => {
|
497
|
+
* session.ondatachannel = (event) => {
|
498
|
+
* const channel = event.channel;
|
499
|
+
* channel.onmessage = (e) => console.log("Received message:", e.data);
|
500
|
+
* };```
|
501
|
+
*/
|
502
|
+
ondatachannel: RTCPeerConnection["ondatachannel"];
|
503
|
+
/**
|
504
|
+
* Callback triggered when the connection state changes.
|
505
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onconnectionstatechange}
|
506
|
+
*/
|
507
|
+
onconnectionstatechange: RTCPeerConnection["onconnectionstatechange"];
|
508
|
+
/**
|
509
|
+
* Callback invoked when a new media track is added to the connection.
|
510
|
+
* See {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/ontrack}
|
511
|
+
*/
|
512
|
+
ontrack: RTCPeerConnection["ontrack"];
|
513
|
+
/**
|
514
|
+
* Closes the session, aborting all pending tasks, and cleaning up resources.
|
515
|
+
* Publishes events and logs about the closure.
|
516
|
+
* @param {string} [reason] - (optional) A reason for closing the session.
|
517
|
+
* @returns {void}
|
518
|
+
* @example `mysession.close("Session ended by user");`
|
519
|
+
*/
|
520
|
+
close(reason?: string): void;
|
521
|
+
/**
|
522
|
+
* Retrieves the identifier of the other peer in the connection.
|
523
|
+
* @returns {string} The peer ID of the connected peer. Valid UTF-8 string of 1-16 characters.
|
524
|
+
* @example ```console.log(`Connected to peer: ${session.otherPeerId()}`);```
|
525
|
+
*/
|
526
|
+
get otherPeerId(): string;
|
527
|
+
/**
|
528
|
+
* Retrieves the connection identifier for the current connection.
|
529
|
+
* Connection IDs are typically unique and help identify connections.
|
530
|
+
* @returns {number} The connection ID for the peer connection.
|
531
|
+
* @example
|
532
|
+
* ```console.log(`Connection ID: ${mySession.otherConnId()}`);```
|
533
|
+
*/
|
534
|
+
get otherConnId(): number;
|
535
|
+
}
|
536
|
+
/**
|
537
|
+
* Options used to configure a Peer.
|
538
|
+
* @interface PeerOptionsFull
|
539
|
+
* @example```
|
540
|
+
* const options: PeerOptionsFull = {
|
541
|
+
* groupId: "group-123", // Valid UTF-8 strings of 1-16 characters.
|
542
|
+
* peerId: "peer-456", // Valid UTF-8 strings of 1-16 characters.
|
543
|
+
* token: "eyJhbGc...49nLmBCg"
|
544
|
+
* };```
|
545
|
+
*/
|
546
|
+
interface PeerOptionsFull {
|
547
|
+
/**
|
548
|
+
* Identifier for the group which the peer belongs to. Must be a valid UTF-8
|
549
|
+
* string of 1-16 characters.
|
550
|
+
* @type {string} groupId
|
551
|
+
*/
|
552
|
+
groupId: string;
|
553
|
+
/**
|
554
|
+
* Identifier for the peer. Must be a valid UTF-8 string of 1-16 characters.
|
555
|
+
* @type {string} peerId
|
556
|
+
*/
|
557
|
+
peerId: string;
|
558
|
+
/**
|
559
|
+
* PulseBeam authentication token for the peer. JWT token generated by `jsr:@pulsebeam/server`
|
560
|
+
* @type {string} token
|
561
|
+
*/
|
562
|
+
token: string;
|
563
|
+
/**
|
564
|
+
* (Optional) Base URL for API calls. Defaults to using our servers: "https://cloud.pulsebeam.dev/twirp".
|
565
|
+
* @type {string | undefined} [baseUrl]
|
566
|
+
*/
|
567
|
+
baseUrl?: string;
|
568
|
+
/**
|
569
|
+
* (Optional) If true, enforces relay-only connections, such as those passed through a TURN server. Defaults to allowing all connection types (such as direct peer to peer). For more details see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection#icetransportpolicy}
|
570
|
+
* @type {boolean | undefined} [forceRelay]
|
571
|
+
*/
|
572
|
+
forceRelay?: boolean;
|
573
|
+
/**
|
574
|
+
* (Optional) Add Ice Servers. Defaults to using our servers. For more details see {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection#iceservers}
|
575
|
+
* @type {RTCIceServer[] | undefined} [iceServers]
|
576
|
+
*/
|
577
|
+
iceServers?: RTCIceServer[];
|
578
|
+
}
|
579
|
+
type PeerOptions = Omit<PeerOptionsFull, "groupId" | "peerId">;
|
580
|
+
/**
|
581
|
+
* Represents the possible states for a Peer.
|
582
|
+
*
|
583
|
+
* @readonly
|
584
|
+
* @enum {string}
|
585
|
+
* Possible values:
|
586
|
+
* - `"new"`: The peer has been created.
|
587
|
+
* - `"closed"`: The peer has been closed.
|
588
|
+
*/
|
589
|
+
type PeerState = "new" | "closed";
|
590
|
+
/**
|
591
|
+
* Peer is a mediator for signaling, connecting, and managing sessions.
|
592
|
+
*/
|
593
|
+
declare class Peer {
|
594
|
+
private transport;
|
595
|
+
private readonly logger;
|
596
|
+
private sessions;
|
597
|
+
private _state;
|
598
|
+
/**
|
599
|
+
* Callback invoked when a new session is established.
|
600
|
+
* @param _s Session object
|
601
|
+
*/
|
602
|
+
onsession: (_s: ISession) => void;
|
603
|
+
/**
|
604
|
+
* Callback invoked when the peer’s state changes.
|
605
|
+
*/
|
606
|
+
onstatechange: () => void;
|
607
|
+
/**
|
608
|
+
* Identifier for the peer. Valid UTF-8 string of 1-16 characters.
|
609
|
+
*/
|
610
|
+
readonly peerId: string;
|
611
|
+
/**
|
612
|
+
* Construct a Peer. Helper available: see {@link createPeer} function
|
613
|
+
* @param logger Logger instance for logging events.
|
614
|
+
* @param client Tunnel client for signaling.
|
615
|
+
* @param opts Configuration options for the peer.
|
616
|
+
* @param isRecoverable Function to determine if an error is recoverable.
|
617
|
+
*/
|
618
|
+
constructor(logger: Logger, client: ITunnelClient, opts: PeerOptionsFull, isRecoverable: (_err: unknown) => boolean);
|
619
|
+
/**
|
620
|
+
* Starts the peer, making it ready to establish connections.
|
621
|
+
* Peers must be started before a connection can occur.
|
622
|
+
*
|
623
|
+
* @returns {void}
|
624
|
+
* @throws {Error} When the peer was previously closed.
|
625
|
+
*/
|
626
|
+
start(): void;
|
627
|
+
/**
|
628
|
+
* Closes the peer. Releases associated resources.
|
629
|
+
* Signals to the AbortController passed to connect if connect was called.
|
630
|
+
*
|
631
|
+
* @async
|
632
|
+
* @returns {Promise<void>} Resolves when the peer has been closed.
|
633
|
+
*/
|
634
|
+
close(): Promise<void>;
|
635
|
+
/**
|
636
|
+
* Establishes a connection with another peer in the specified group.
|
637
|
+
* Peer should be started before calling connect.
|
638
|
+
*
|
639
|
+
* Check the log output for troubleshooting information.
|
640
|
+
*
|
641
|
+
* @async
|
642
|
+
* @param {string} otherGroupId The ID of the group the other peer belongs to.
|
643
|
+
* Valid UTF-8 string of 1-16 characters.
|
644
|
+
* @param {string} otherPeerId The ID of the peer you want to connect to.
|
645
|
+
* Valid UTF-8 string of 1-16 characters.
|
646
|
+
* @param {AbortSignal} signal Handle cancellations or cancel the connection attempt.
|
647
|
+
* @returns {Promise<void>} Resolves when the connection has been established,
|
648
|
+
* an unrecoverable error (e.g., network connection issues, internal errors) occurs,
|
649
|
+
* or the maximum retry attempts are reached.
|
650
|
+
*/
|
651
|
+
connect(otherGroupId: string, otherPeerId: string, signal: AbortSignal): Promise<void>;
|
652
|
+
/**
|
653
|
+
* Gets the current state of the peer. For state info see {@link PeerState}
|
654
|
+
* @returns {PeerState} The current state of the peer
|
655
|
+
*/
|
656
|
+
get state(): PeerState;
|
657
|
+
/** internal @private */
|
658
|
+
private setState;
|
659
|
+
}
|
660
|
+
/**
|
661
|
+
* Helper to create a new Peer instance
|
662
|
+
* @param opts Configuration options for the peer.
|
663
|
+
* @returns {Promise<Peer>} Resolves to the newly created Peer
|
664
|
+
* @throws {Error} When unable to connect to signaling server. Likely networking issue.
|
665
|
+
*/
|
666
|
+
declare function createPeer(opts: PeerOptions): Promise<Peer>;
|
667
|
+
|
668
|
+
export { type ISession, Peer, type PeerOptions, type PeerOptionsFull, type PeerState, createPeer };
|