@dimchansky/meshpost 0.4.0 → 0.4.2
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 +51 -45
- package/dist/blob.js +5 -44
- package/dist/channel.js +4 -2
- package/dist/combine.js +15 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +2 -1
- package/dist/listeners.d.ts +4 -0
- package/dist/listeners.js +97 -0
- package/dist/public.d.ts +52 -0
- package/dist/public.js +133 -0
- package/dist/room.js +25 -44
- package/dist/rpc.js +7 -4
- package/dist/state.d.ts +5 -2
- package/dist/state.js +5 -50
- package/dist/voice.d.ts +3 -0
- package/dist/voice.js +36 -56
- package/dist/ws.d.ts +29 -0
- package/dist/ws.js +59 -0
- package/docs/behavior.md +11 -3
- package/package.json +5 -1
package/docs/behavior.md
CHANGED
|
@@ -85,7 +85,8 @@ Note: when `privateTopic` is `false` (default), `mqttSignaling()`, `nostrSignali
|
|
|
85
85
|
- `createRpc()` throws `TypeError` for an invalid `room`, `requestCodec`, `responseCodec`, or `handle` callback, `Error` if a second active `handle()` is registered on the same `RpcEndpoint`, and `RangeError` for out-of-range `timeoutMs`, `maxPendingCalls`, or `maxConcurrentPerPeer`. `rpc.call()` rejects with `TypeError`/`RangeError` for invalid `peerId`/`timeoutMs`, or with `RpcError`.
|
|
86
86
|
- `createPeerState()` throws `TypeError` for an invalid `room`, `delivery`, `coalesce`, `codec`, `undefined` state value, or non-function `onChange` listener; `RangeError` if `initial` or `set(value)` encodes past the 16 KiB packet limit; and `Error` when calling `set()` or `clear()` after `close()` or `room.leave()`.
|
|
87
87
|
- `createBlobChannel()` throws `RangeError` for invalid `maxReceiveBytes`, `chunkSize`, `receiveTimeoutMs`, or `maxConcurrentPerPeer`. `blobChannel.send()` rejects with `Error` when closed and `TypeError` for non-`Uint8Array` payloads.
|
|
88
|
-
- `wsSignaling()`
|
|
88
|
+
- `wsSignaling()` and `optionalWsSignaling()` throw `TypeError` for non-`ws:`/`wss:` URLs, non-boolean `encrypt`/`privateTopic`, `privateTopic: true` without `password`, or a non-function `WebSocket` option; `Error` if `privateTopic: true` is combined with `encrypt: false` or if `WebSocket` is unavailable at session startup; and `RangeError` for invalid `handshakeTimeoutMs` or `pingIntervalMs`.
|
|
89
|
+
- `publicSignaling()` throws `TypeError` for invalid options, non-`ws:`/`wss:` or empty-string `wsUrls`, non-boolean `localTabs`/`wsEncrypt`/`privateTopic`, invalid `mqtt`/`nostr`/`appId`, or a non-function `WebSocket` option; and `RangeError` when both `mqtt: false` and `nostr: false`, when `mqtt`/`nostr` is an empty array, when `wsUrls` exceeds `8` unique (`64` raw) entries, or when `wsHandshakeTimeoutMs` / `handshakeTimeoutMs` is out of range.
|
|
89
90
|
- `combineSignaling()` throws `RangeError` when given 0 adapters and `TypeError` if any argument is not a function; `withLocalTabs()` throws `TypeError` if `primary` is not a function.
|
|
90
91
|
- `mqttSignaling()` throws `RangeError` for empty `urls` or invalid `handshakeTimeoutMs`, `TypeError` for an empty `password`, non-boolean `privateTopic`, `privateTopic: true` without `password`, or a non-function `WebSocket` option, and `Error` if `WebSocket` is unavailable at session startup.
|
|
91
92
|
- `nostrSignaling()` throws `RangeError` for empty `urls` or invalid `handshakeTimeoutMs`, `TypeError` for non-`ws:`/`wss:` `urls`, invalid `appId`, empty `password`, non-boolean `privateTopic`, `privateTopic: true` without `password`, or a non-function `WebSocket` option, and `Error` if `WebSocket` is unavailable at session startup.
|
|
@@ -192,7 +193,7 @@ Each `RTCPeerConnection` creates two pre-negotiated channels with `protocol` set
|
|
|
192
193
|
- `0x01` `SET`: `[0x01, seq, ...codec.encode(value)]`
|
|
193
194
|
- `0x02` `CLEAR`: `[0x02, seq]` (exact 5 bytes).
|
|
194
195
|
- Live `set(value)` uses `options.delivery` (`'reliable'` default or `'unreliable'`), while `options.initial`, `onPeerJoin` hydration, and `clear()` always transmit on the `'reliable'` channel for `name`. Both channels feed a single per-peer RFC 1982 `u32` sequence table (`lastSeqByPeer`), updated only after `codec.decode` succeeds (`!== undefined`), so out-of-order unreliable packets or racing hydration frames never regress state or resurrect cleared state.
|
|
195
|
-
- When `coalesce` is `true` (default), `createPeerState` retains only the single latest encoded frame (`O(1)` memory) and flushes `'busy'` peers on `room.onDrain` (keeping `dirtyReliable` independent of unreliable `'accepted'` returns so UDP loss cannot drop pending reliable hydrations).
|
|
196
|
+
- When `coalesce` is `true` (default), `createPeerState` retains only the single latest encoded frame (`O(1)` memory) and flushes `'busy'` peers on `room.onDrain` (keeping `dirtyReliable` independent of unreliable `'accepted'` returns so UDP loss cannot drop pending reliable hydrations). `onChange(peerId, next, prev, reason)` passes `reason` (`'set' | 'clear' | 'leave'`) so apps can distinguish explicit `clear()` from `onPeerLeave` without relying on listener registration order; disconnecting peers (`onPeerLeave`) are automatically removed and emit `onChange(peerId, undefined, prev, 'leave')`.
|
|
196
197
|
|
|
197
198
|
### Chunked transfers (`createBlobChannel`)
|
|
198
199
|
|
|
@@ -251,13 +252,20 @@ Each `RTCPeerConnection` creates two pre-negotiated channels with `protocol` set
|
|
|
251
252
|
- Server sends `{ type: 'roster', peers: string[] }` (validated UUIDs, capped at `256`), `{ type: 'signal', from, signal | box }`, and `{ type: 'pong' }`. Incoming frames larger than `128 KiB` are ignored.
|
|
252
253
|
- Tracks `awaitingPong`: if no `{ type: 'pong' }` (or other valid server message) arrives before the next ping interval, the socket is closed to trigger reconnect.
|
|
253
254
|
- Reconnects with jittered exponential backoff (`500 ms` to `10 s`, `±25%` jitter) when `reconnect` is `true` (default), emitting `'offline'` and `'signaling-error'` once per offline transition.
|
|
255
|
+
- `optionalWsSignaling(url, options?)` wraps `wsSignaling` with `reconnect: false` and a `4,000 ms` default `handshakeTimeoutMs`, forwarding `'online'` while healthy and transitioning cleanly to `'closed'` (closing the underlying session and suppressing `'signaling-error'`) on any non-`'online'` transition while still forwarding `'decrypt-failed'` and `'clock-skew'`.
|
|
256
|
+
|
|
257
|
+
### `publicSignaling(options?)`
|
|
258
|
+
|
|
259
|
+
- Flattens zero or more `optionalWsSignaling(url, ...)` children (`wsUrls?: string | readonly string[]`, validated `ws:`/`wss:`, deduplicated, capped at `8` unique URLs and `64` raw entries) together with `mqttSignaling()` (`mqtt: true` default) and `nostrSignaling()` (`nostr: true` default) into a single `combineSignaling(...)` instance, wrapped in `withLocalTabs(...)` when `localTabs` is `true` (default).
|
|
260
|
+
- Treats enabled transports as a single redundant pool: suppresses per-transport `'signaling-error'` while any sibling transport is `'online'` or `'connecting'` (e.g. when corporate Wi-Fi blocks MQTT ports while port-443 Nostr or `wsUrls` succeeds) and emits `'signaling-error'` once per aggregate `'offline'` transition, while forwarding `'decrypt-failed'` and `'clock-skew'`.
|
|
261
|
+
- Requires at least one persistent public relay transport (`mqtt !== false || nostr !== false`).
|
|
254
262
|
|
|
255
263
|
### `combineSignaling(...adapters)`
|
|
256
264
|
|
|
257
265
|
- Composes one or more `Signaling` adapters into a single adapter (returning the single adapter directly when given one).
|
|
258
266
|
- Pre-initializes all child states as `'connecting'` and buffers synchronous startup callbacks until every child factory returns without throwing (closing already-started children if any factory throws).
|
|
259
267
|
- Aggregate `SignalingState` is `'online'` if any child is `'online'`, `'connecting'` if none is `'online'` and any is `'connecting'`, `'offline'` if none is `'online'`/`'connecting'` and any is `'offline'`, and `'closed'` when all children are `'closed'`.
|
|
260
|
-
- Maintains per-child peer sets, publishes their union to `Discovery.roster`, clears unreachable entries when a child goes `'offline'`/`'closed'` (preserving already-open WebRTC links and any peers still reachable via nested `canReach`), routes `send(to, signal)` to every reachable child advertising `to`, and forwards child `error` reports.
|
|
268
|
+
- Maintains per-child peer sets, publishes their union to `Discovery.roster`, clears unreachable entries when a child goes `'offline'`/`'closed'` (preserving already-open WebRTC links and any peers still reachable via nested `canReach`), routes `send(to, signal)` to every reachable child advertising `to`, and forwards child `error` reports (throttling `'decrypt-failed'` and `'clock-skew'` across children to at most one event per `15 s` each).
|
|
261
269
|
- Advertises `trickle: true` only when every child session advertises `trickle === true`, and deduplicates incoming `{ kind: 'ice' }` candidates per `(from, attempt)` across child adapters.
|
|
262
270
|
|
|
263
271
|
### `withLocalTabs(primary)`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimchansky/meshpost",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"author": "Dmitrij Koniajev",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -99,6 +99,10 @@
|
|
|
99
99
|
"types": "./dist/combine.d.ts",
|
|
100
100
|
"import": "./dist/combine.js"
|
|
101
101
|
},
|
|
102
|
+
"./public": {
|
|
103
|
+
"types": "./dist/public.d.ts",
|
|
104
|
+
"import": "./dist/public.js"
|
|
105
|
+
},
|
|
102
106
|
"./signaling": {
|
|
103
107
|
"types": "./dist/signaling.d.ts",
|
|
104
108
|
"import": "./dist/signaling.js"
|