@dimchansky/meshpost 0.0.0-stage → 0.2.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 +355 -2
- package/dist/blob.d.ts +45 -0
- package/dist/blob.js +364 -0
- package/dist/channel.d.ts +26 -0
- package/dist/channel.js +51 -0
- package/dist/combine.d.ts +7 -0
- package/dist/combine.js +249 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +9 -0
- package/dist/manual.d.ts +13 -0
- package/dist/manual.js +109 -0
- package/dist/mqtt.d.ts +20 -0
- package/dist/mqtt.js +610 -0
- package/dist/room.d.ts +99 -0
- package/dist/room.js +1130 -0
- package/dist/signaling.d.ts +70 -0
- package/dist/signaling.js +118 -0
- package/dist/tabs.d.ts +3 -0
- package/dist/tabs.js +94 -0
- package/dist/ws.d.ts +14 -0
- package/dist/ws.js +272 -0
- package/docs/behavior.md +237 -0
- package/package.json +65 -4
package/dist/room.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type Signaling, type SignalingErrorCode, type SignalingState } from './signaling.js';
|
|
2
|
+
/** Built-in Cloudflare and Google public STUN servers used by default. */
|
|
3
|
+
export declare const defaultIceServers: readonly RTCIceServer[];
|
|
4
|
+
/** Delivery guarantee for a packet: fast unordered (`'unreliable'`) or ordered reliable (`'reliable'`). */
|
|
5
|
+
export type Delivery = 'unreliable' | 'reliable';
|
|
6
|
+
export interface RoomOptions {
|
|
7
|
+
/** Signaling adapter used to discover peers and exchange WebRTC setup messages. */
|
|
8
|
+
signaling: Signaling;
|
|
9
|
+
/** Application namespace isolating rooms across different apps. @default 'meshpost' */
|
|
10
|
+
appId?: string;
|
|
11
|
+
/** Optional non-empty shared password isolating (and on MQTT, encrypting) room signaling. */
|
|
12
|
+
password?: string;
|
|
13
|
+
/** Custom WebRTC configuration. Keeps `defaultIceServers` unless `iceServers` is specified. */
|
|
14
|
+
rtcConfig?: RTCConfiguration;
|
|
15
|
+
/** Additional TURN (or STUN) servers appended to `rtcConfig.iceServers` or `defaultIceServers`. */
|
|
16
|
+
turnConfig?: readonly RTCIceServer[];
|
|
17
|
+
/** Max time in milliseconds per connection attempt before retrying. @default 35000 */
|
|
18
|
+
handshakeTimeoutMs?: number;
|
|
19
|
+
/** Soft cap in milliseconds for ICE candidate gathering on non-trickle adapters (such as `manualSignaling()`). @default 2500 */
|
|
20
|
+
iceGatheringTimeoutMs?: number;
|
|
21
|
+
/** Maximum simultaneous peer connections in this room. @default 32 */
|
|
22
|
+
maxPeers?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SendOptions {
|
|
25
|
+
/** Optional target peer ID. Omit to broadcast to all connected peers. */
|
|
26
|
+
to?: string;
|
|
27
|
+
/** Delivery mode for this packet. @default 'unreliable' */
|
|
28
|
+
delivery?: Delivery;
|
|
29
|
+
}
|
|
30
|
+
/** Immediate per-recipient outcome returned by `room.send()` and `channel.send()`. */
|
|
31
|
+
export type SendResult = 'accepted' | 'unavailable' | 'busy' | 'too-large';
|
|
32
|
+
/** Network path used by an active peer connection. */
|
|
33
|
+
export type PeerRoute = 'direct' | 'relay' | 'unknown';
|
|
34
|
+
/** Read-only connection statistics snapshot returned by `room.getStats()`. */
|
|
35
|
+
export interface PeerStats {
|
|
36
|
+
/** Current round-trip ping in whole milliseconds, or `null` if not measured yet. */
|
|
37
|
+
readonly rttMs: number | null;
|
|
38
|
+
/** `'direct'` for peer-to-peer, `'relay'` through a TURN server, or `'unknown'`. */
|
|
39
|
+
readonly route: PeerRoute;
|
|
40
|
+
/** Total app payload bytes sent on this connection across both delivery modes. */
|
|
41
|
+
readonly bytesSent: number;
|
|
42
|
+
/** Total app payload bytes received on this connection across both delivery modes. */
|
|
43
|
+
readonly bytesReceived: number;
|
|
44
|
+
/** Bytes currently queued in the unreliable send buffer. */
|
|
45
|
+
readonly bufferedUnreliable: number;
|
|
46
|
+
/** Bytes currently queued in the reliable send buffer. */
|
|
47
|
+
readonly bufferedReliable: number;
|
|
48
|
+
}
|
|
49
|
+
/** Structured error codes emitted via `room.onError()`. */
|
|
50
|
+
export type RoomErrorCode = 'room-full' | 'ice-failed' | 'media-error' | SignalingErrorCode;
|
|
51
|
+
/** Structured diagnostic error emitted via `room.onError()`. */
|
|
52
|
+
export interface RoomError {
|
|
53
|
+
readonly code: RoomErrorCode;
|
|
54
|
+
readonly message: string;
|
|
55
|
+
readonly peerId?: string;
|
|
56
|
+
}
|
|
57
|
+
/** Options for subscribing to room or channel events. */
|
|
58
|
+
export interface ListenOptions {
|
|
59
|
+
/** Automatically unsubscribe after the listener is invoked once. */
|
|
60
|
+
once?: boolean;
|
|
61
|
+
/** Automatically unsubscribe when the given AbortSignal aborts. */
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
}
|
|
64
|
+
export interface Room {
|
|
65
|
+
/** Local peer ID (random UUID v4). A page reload creates a new peer ID. */
|
|
66
|
+
readonly id: string;
|
|
67
|
+
/** Snapshot array of currently connected remote peer IDs. */
|
|
68
|
+
readonly peers: readonly string[];
|
|
69
|
+
/** Current state of the signaling adapter. */
|
|
70
|
+
readonly signalingState: SignalingState;
|
|
71
|
+
/** Send a binary packet (max 16 KiB) synchronously. Returns a per-recipient result map. */
|
|
72
|
+
send(bytes: Uint8Array, options?: SendOptions): ReadonlyMap<string, SendResult>;
|
|
73
|
+
/** Read current ping, route, byte counts, and buffer sizes for a connected peer, or `null` if unavailable. */
|
|
74
|
+
getStats(peerId: string): Promise<PeerStats | null>;
|
|
75
|
+
/** Subscribe to incoming binary packets. Returns an unsubscribe function. */
|
|
76
|
+
onPacket(fn: (from: string, bytes: Uint8Array, delivery: Delivery) => void, options?: ListenOptions): () => void;
|
|
77
|
+
/** Subscribe to send-buffer drain events (fires after `'busy'` clears). Returns an unsubscribe function. */
|
|
78
|
+
onDrain(fn: (id: string, delivery: Delivery) => void, options?: ListenOptions): () => void;
|
|
79
|
+
/** Subscribe to peer connection events. Returns an unsubscribe function. */
|
|
80
|
+
onPeerJoin(fn: (id: string) => void, options?: ListenOptions): () => void;
|
|
81
|
+
/** Subscribe to peer disconnection events. Returns an unsubscribe function. */
|
|
82
|
+
onPeerLeave(fn: (id: string) => void, options?: ListenOptions): () => void;
|
|
83
|
+
/** Subscribe to future signaling state changes. Returns an unsubscribe function. */
|
|
84
|
+
onSignalingChange(fn: (state: SignalingState, reason?: string) => void, options?: ListenOptions): () => void;
|
|
85
|
+
/** Subscribe to structured room and signaling errors. Returns an unsubscribe function. */
|
|
86
|
+
onError(fn: (error: RoomError) => void, options?: ListenOptions): () => void;
|
|
87
|
+
/** Attach a local MediaStream to all connected/future peers (broadcast), or selectively to one peer (`to`). Broadcast and per-peer registrations are tracked independently. */
|
|
88
|
+
addStream(stream: MediaStream, to?: string): void;
|
|
89
|
+
/** Detach a previously added local MediaStream from broadcast (`to` omitted) or from one peer (`to`). Does not stop local tracks. */
|
|
90
|
+
removeStream(stream: MediaStream, to?: string): void;
|
|
91
|
+
/** Subscribe to incoming remote MediaStreams. Fires strictly after `onPeerJoin`. */
|
|
92
|
+
onPeerStream(fn: (peerId: string, stream: MediaStream) => void, options?: ListenOptions): () => void;
|
|
93
|
+
/** Subscribe to remote MediaStream removals (explicit removal or peer disconnect). */
|
|
94
|
+
onPeerStreamEnd(fn: (peerId: string, stream: MediaStream) => void, options?: ListenOptions): () => void;
|
|
95
|
+
/** Leave the room, notify peers, and close all connections. Safe to call more than once. */
|
|
96
|
+
leave(): void;
|
|
97
|
+
}
|
|
98
|
+
/** Start discovery immediately. Membership becomes observable as peer links open. */
|
|
99
|
+
export declare function joinRoom(name: string, options: RoomOptions): Room;
|