@dimchansky/meshpost 0.4.2 → 0.6.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/README.md +66 -550
- package/dist/bip340.d.ts +1 -0
- package/dist/bip340.js +346 -0
- package/dist/blob.d.ts +1 -1
- package/dist/blob.js +15 -16
- package/dist/channel.js +15 -44
- package/dist/combine.js +25 -39
- package/dist/crypto.js +10 -9
- package/dist/identity.d.ts +45 -0
- package/dist/identity.js +188 -28
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -3
- package/dist/listeners.js +18 -3
- package/dist/mqtt.js +193 -408
- package/dist/nostr.js +163 -745
- package/dist/public.d.ts +19 -1
- package/dist/public.js +26 -9
- package/dist/relay-core.d.ts +1 -0
- package/dist/relay-core.js +323 -0
- package/dist/room-hello.d.ts +1 -0
- package/dist/room-hello.js +129 -0
- package/dist/room-ice.d.ts +1 -0
- package/dist/room-ice.js +115 -0
- package/dist/room-media.d.ts +1 -0
- package/dist/room-media.js +477 -0
- package/dist/room-reclaim.d.ts +1 -0
- package/dist/room-reclaim.js +111 -0
- package/dist/room-stats.d.ts +1 -0
- package/dist/room-stats.js +75 -0
- package/dist/room.js +109 -919
- package/dist/signaling.d.ts +8 -0
- package/dist/signaling.js +64 -0
- package/dist/state.js +1 -2
- package/dist/voice-helpers.d.ts +1 -0
- package/dist/voice-helpers.js +100 -0
- package/dist/voice-meter.d.ts +1 -0
- package/dist/voice-meter.js +79 -0
- package/dist/voice.d.ts +41 -0
- package/dist/voice.js +205 -273
- package/dist/ws.js +60 -146
- package/docs/api.md +217 -0
- package/docs/behavior.md +16 -9
- package/docs/guide.md +404 -0
- package/docs/signaling-and-production.md +312 -0
- package/docs/voice-and-media.md +193 -0
- package/package.json +3 -2
package/dist/identity.d.ts
CHANGED
|
@@ -27,6 +27,41 @@ export interface SerializedIdentity {
|
|
|
27
27
|
/** 32-byte canonical base64url private scalar (43 chars). */
|
|
28
28
|
readonly d: string;
|
|
29
29
|
}
|
|
30
|
+
/** Minimal synchronous `Storage`-compatible interface accepted by `createIdentityStore()`. */
|
|
31
|
+
export interface IdentityStorage {
|
|
32
|
+
getItem(key: string): string | null;
|
|
33
|
+
setItem(key: string, value: string): void;
|
|
34
|
+
removeItem(key: string): void;
|
|
35
|
+
}
|
|
36
|
+
/** Options passed to `createIdentityStore()`. */
|
|
37
|
+
export interface IdentityStoreOptions {
|
|
38
|
+
/** Required storage key isolating identities across apps on the same origin (`1..256` chars). */
|
|
39
|
+
key: string;
|
|
40
|
+
/**
|
|
41
|
+
* Storage backend (`localStorage`, `sessionStorage`, or custom `IdentityStorage`).
|
|
42
|
+
* Defaults to safely probing `globalThis.localStorage` inside `try/catch` (degrading to
|
|
43
|
+
* ephemeral in-memory caching when unavailable or throwing `SecurityError`).
|
|
44
|
+
* Pass `null` for strictly ephemeral in-memory caching without persistence.
|
|
45
|
+
*/
|
|
46
|
+
storage?: IdentityStorage | null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Race-safe persistent identity manager backed by `createIdentity()` / `importIdentity()` / `exportIdentity()`.
|
|
50
|
+
*
|
|
51
|
+
* Security note: persisting serialized keys in `localStorage` stores an extractable JWK readable by
|
|
52
|
+
* same-origin scripts (XSS). For stronger key isolation, use `createIdentity({ extractable: false })`
|
|
53
|
+
* with IndexedDB directly.
|
|
54
|
+
*/
|
|
55
|
+
export interface IdentityStore {
|
|
56
|
+
/** Most recently loaded or rotated identity cached in memory, or `null` before `load()` or after `clear()`. */
|
|
57
|
+
readonly current: PeerIdentity | null;
|
|
58
|
+
/** Load the stored identity or generate and persist a fresh one (coalesces concurrent calls; self-heals corrupt storage). */
|
|
59
|
+
load(): Promise<PeerIdentity>;
|
|
60
|
+
/** Generate a fresh identity, persist it, and supersede any in-flight `load()` or earlier `rotate()`. */
|
|
61
|
+
rotate(): Promise<PeerIdentity>;
|
|
62
|
+
/** Clear the in-memory cache, remove the stored key (best-effort), and invalidate in-flight operations. */
|
|
63
|
+
clear(): void;
|
|
64
|
+
}
|
|
30
65
|
/**
|
|
31
66
|
* Generate a fresh WebCrypto `ECDSA P-256` peer identity with a deterministic 128-bit `userId`.
|
|
32
67
|
*/
|
|
@@ -43,3 +78,13 @@ export declare function isSerializedIdentity(value: unknown): value is Serialize
|
|
|
43
78
|
* Import and cryptographically self-verify a `SerializedIdentity` (`(x, y)` verified against `d`).
|
|
44
79
|
*/
|
|
45
80
|
export declare function importIdentity(data: unknown, options?: CreateIdentityOptions): Promise<PeerIdentity>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a race-safe persistent `PeerIdentity` store backed by `localStorage` (by default) or a custom `IdentityStorage`.
|
|
83
|
+
*
|
|
84
|
+
* - Coalesces concurrent `load()` calls and uses a monotonic `epoch` guard so `rotate()` or `clear()`
|
|
85
|
+
* cannot be overwritten by an earlier in-flight operation.
|
|
86
|
+
* - Caps stored JSON reads at `1,024` chars, cryptographically verifies imported keys, and silently
|
|
87
|
+
* regenerates corrupt entries (preserving stored entries untouched if `crypto.subtle` is unavailable).
|
|
88
|
+
* - Degrades cleanly to in-memory caching when `localStorage` throws `SecurityError` or is unavailable.
|
|
89
|
+
*/
|
|
90
|
+
export declare function createIdentityStore(options: IdentityStoreOptions): IdentityStore;
|
package/dist/identity.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { toBase64Url } from './crypto.js';
|
|
1
|
+
import { decodeBase64UrlBytes, toBase64Url } from './crypto.js';
|
|
2
2
|
const encoder = new TextEncoder();
|
|
3
|
-
const base64UrlPattern = /^[A-Za-z0-9_-]+$/;
|
|
4
3
|
const userIdDomainPrefix = encoder.encode('meshpost/1/userid:');
|
|
5
4
|
const dtlsFingerprintLinePattern = /^a=fingerprint:(sha-256|sha-384|sha-512)\s+([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2})+)\s*$/i;
|
|
6
5
|
const expectedFingerprintHexLength = {
|
|
@@ -11,25 +10,10 @@ const expectedFingerprintHexLength = {
|
|
|
11
10
|
const identityInternals = new WeakMap();
|
|
12
11
|
/** @internal */
|
|
13
12
|
export function decodeCanonicalBase64Url(value, expectedChars, expectedBytes) {
|
|
14
|
-
if (typeof value !== 'string' ||
|
|
15
|
-
value.length !== expectedChars ||
|
|
16
|
-
!base64UrlPattern.test(value)) {
|
|
13
|
+
if (typeof value !== 'string' || value.length !== expectedChars)
|
|
17
14
|
return null;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const base64 = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
21
|
-
const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4);
|
|
22
|
-
const binary = atob(padded);
|
|
23
|
-
if (binary.length !== expectedBytes)
|
|
24
|
-
return null;
|
|
25
|
-
const out = new Uint8Array(expectedBytes);
|
|
26
|
-
for (let i = 0; i < expectedBytes; i++)
|
|
27
|
-
out[i] = binary.charCodeAt(i);
|
|
28
|
-
return toBase64Url(out) === value ? out : null;
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
15
|
+
const out = decodeBase64UrlBytes(value);
|
|
16
|
+
return out && out.byteLength === expectedBytes && toBase64Url(out) === value ? out : null;
|
|
33
17
|
}
|
|
34
18
|
async function deriveUserIdFromRawPublicKey(subtle, rawPub) {
|
|
35
19
|
const input = new Uint8Array(userIdDomainPrefix.byteLength + rawPub.byteLength);
|
|
@@ -121,15 +105,17 @@ export function isSerializedIdentity(value) {
|
|
|
121
105
|
*/
|
|
122
106
|
export async function importIdentity(data, options) {
|
|
123
107
|
const extractable = parseExtractableOption(options);
|
|
124
|
-
if (!
|
|
108
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
125
109
|
throw new TypeError('Invalid serialized identity');
|
|
126
110
|
}
|
|
127
|
-
const
|
|
128
|
-
const xBytes = decodeCanonicalBase64Url(
|
|
129
|
-
const yBytes = decodeCanonicalBase64Url(
|
|
130
|
-
|
|
111
|
+
const rec = data;
|
|
112
|
+
const xBytes = rec.v === 1 && rec.crv === 'P-256' ? decodeCanonicalBase64Url(rec.x, 43, 32) : null;
|
|
113
|
+
const yBytes = xBytes ? decodeCanonicalBase64Url(rec.y, 43, 32) : null;
|
|
114
|
+
const dBytes = yBytes ? decodeCanonicalBase64Url(rec.d, 43, 32) : null;
|
|
115
|
+
if (!xBytes || !yBytes || !dBytes) {
|
|
131
116
|
throw new TypeError('Invalid serialized identity');
|
|
132
117
|
}
|
|
118
|
+
const subtle = requireSubtleCrypto();
|
|
133
119
|
const rawCandidate = new Uint8Array(65);
|
|
134
120
|
rawCandidate[0] = 0x04;
|
|
135
121
|
rawCandidate.set(xBytes, 1);
|
|
@@ -139,9 +125,9 @@ export async function importIdentity(data, options) {
|
|
|
139
125
|
subtle.importKey('jwk', {
|
|
140
126
|
kty: 'EC',
|
|
141
127
|
crv: 'P-256',
|
|
142
|
-
x:
|
|
143
|
-
y:
|
|
144
|
-
d:
|
|
128
|
+
x: rec.x,
|
|
129
|
+
y: rec.y,
|
|
130
|
+
d: rec.d,
|
|
145
131
|
key_ops: ['sign'],
|
|
146
132
|
ext: extractable
|
|
147
133
|
}, { name: 'ECDSA', namedCurve: 'P-256' }, extractable, ['sign']),
|
|
@@ -262,3 +248,177 @@ export async function sha256Base64Url(input) {
|
|
|
262
248
|
return null;
|
|
263
249
|
}
|
|
264
250
|
}
|
|
251
|
+
const maxStoredIdentityChars = 1024;
|
|
252
|
+
function isValidIdentityStorage(value) {
|
|
253
|
+
return (Boolean(value) &&
|
|
254
|
+
typeof value === 'object' &&
|
|
255
|
+
typeof value.getItem === 'function' &&
|
|
256
|
+
typeof value.setItem === 'function' &&
|
|
257
|
+
typeof value.removeItem === 'function');
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create a race-safe persistent `PeerIdentity` store backed by `localStorage` (by default) or a custom `IdentityStorage`.
|
|
261
|
+
*
|
|
262
|
+
* - Coalesces concurrent `load()` calls and uses a monotonic `epoch` guard so `rotate()` or `clear()`
|
|
263
|
+
* cannot be overwritten by an earlier in-flight operation.
|
|
264
|
+
* - Caps stored JSON reads at `1,024` chars, cryptographically verifies imported keys, and silently
|
|
265
|
+
* regenerates corrupt entries (preserving stored entries untouched if `crypto.subtle` is unavailable).
|
|
266
|
+
* - Degrades cleanly to in-memory caching when `localStorage` throws `SecurityError` or is unavailable.
|
|
267
|
+
*/
|
|
268
|
+
export function createIdentityStore(options) {
|
|
269
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
|
270
|
+
throw new TypeError('Invalid identity store options');
|
|
271
|
+
}
|
|
272
|
+
const { key, storage: customStorage } = options;
|
|
273
|
+
if (typeof key !== 'string' || key.length === 0 || key.length > 256) {
|
|
274
|
+
throw new TypeError('Expected identity store key to be a non-empty string (1..256 chars)');
|
|
275
|
+
}
|
|
276
|
+
if (customStorage !== undefined &&
|
|
277
|
+
customStorage !== null &&
|
|
278
|
+
!isValidIdentityStorage(customStorage)) {
|
|
279
|
+
throw new TypeError('Invalid identity storage backend');
|
|
280
|
+
}
|
|
281
|
+
let cached = null;
|
|
282
|
+
let inFlightLoad = null;
|
|
283
|
+
let inFlightRotate = null;
|
|
284
|
+
let epoch = 0;
|
|
285
|
+
const resolveStorage = () => {
|
|
286
|
+
if (customStorage === null)
|
|
287
|
+
return null;
|
|
288
|
+
if (customStorage !== undefined)
|
|
289
|
+
return customStorage;
|
|
290
|
+
try {
|
|
291
|
+
const candidate = globalThis.localStorage;
|
|
292
|
+
return isValidIdentityStorage(candidate) ? candidate : null;
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const safeRead = (storage) => {
|
|
299
|
+
if (!storage)
|
|
300
|
+
return null;
|
|
301
|
+
try {
|
|
302
|
+
const raw = storage.getItem(key);
|
|
303
|
+
return typeof raw === 'string' ? raw : null;
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const safeWrite = (storage, serialized) => {
|
|
310
|
+
if (!storage)
|
|
311
|
+
return;
|
|
312
|
+
try {
|
|
313
|
+
storage.setItem(key, JSON.stringify(serialized));
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
// Ignore quota or restricted-storage errors; keep identity cached in memory.
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const safeRemove = (storage) => {
|
|
320
|
+
if (!storage)
|
|
321
|
+
return;
|
|
322
|
+
try {
|
|
323
|
+
storage.removeItem(key);
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
// Ignore restricted-storage errors.
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
const resolveStale = (fallback, selfPromise) => {
|
|
330
|
+
if (cached)
|
|
331
|
+
return cached;
|
|
332
|
+
if (inFlightRotate && inFlightRotate !== selfPromise)
|
|
333
|
+
return inFlightRotate;
|
|
334
|
+
return fallback;
|
|
335
|
+
};
|
|
336
|
+
const createAndPersist = async (myEpoch, storage, selfPromise) => {
|
|
337
|
+
const fresh = await createIdentity();
|
|
338
|
+
if (myEpoch !== epoch)
|
|
339
|
+
return resolveStale(fresh, selfPromise?.());
|
|
340
|
+
if (storage) {
|
|
341
|
+
const exported = await exportIdentity(fresh);
|
|
342
|
+
if (myEpoch !== epoch)
|
|
343
|
+
return resolveStale(fresh, selfPromise?.());
|
|
344
|
+
safeWrite(storage, exported);
|
|
345
|
+
}
|
|
346
|
+
cached = fresh;
|
|
347
|
+
return fresh;
|
|
348
|
+
};
|
|
349
|
+
return {
|
|
350
|
+
get current() {
|
|
351
|
+
return cached;
|
|
352
|
+
},
|
|
353
|
+
load() {
|
|
354
|
+
if (cached)
|
|
355
|
+
return Promise.resolve(cached);
|
|
356
|
+
if (inFlightRotate)
|
|
357
|
+
return inFlightRotate;
|
|
358
|
+
if (inFlightLoad)
|
|
359
|
+
return inFlightLoad;
|
|
360
|
+
const myEpoch = epoch;
|
|
361
|
+
const promise = (async () => {
|
|
362
|
+
// Verify WebCrypto availability before touching storage so non-secure contexts
|
|
363
|
+
// never misclassify a missing SubtleCrypto error as corrupt storage and delete the key.
|
|
364
|
+
requireSubtleCrypto();
|
|
365
|
+
const storage = resolveStorage();
|
|
366
|
+
const raw = safeRead(storage);
|
|
367
|
+
if (raw !== null) {
|
|
368
|
+
let loaded = null;
|
|
369
|
+
if (raw.length > 0 && raw.length <= maxStoredIdentityChars) {
|
|
370
|
+
try {
|
|
371
|
+
const parsed = JSON.parse(raw);
|
|
372
|
+
if (isSerializedIdentity(parsed)) {
|
|
373
|
+
loaded = await importIdentity(parsed);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
loaded = null;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (myEpoch !== epoch) {
|
|
381
|
+
if (cached)
|
|
382
|
+
return cached;
|
|
383
|
+
if (inFlightRotate)
|
|
384
|
+
return inFlightRotate;
|
|
385
|
+
return loaded ?? createIdentity();
|
|
386
|
+
}
|
|
387
|
+
if (loaded) {
|
|
388
|
+
cached = loaded;
|
|
389
|
+
return loaded;
|
|
390
|
+
}
|
|
391
|
+
safeRemove(storage);
|
|
392
|
+
}
|
|
393
|
+
return createAndPersist(myEpoch, storage);
|
|
394
|
+
})().finally(() => {
|
|
395
|
+
if (inFlightLoad === promise)
|
|
396
|
+
inFlightLoad = null;
|
|
397
|
+
});
|
|
398
|
+
inFlightLoad = promise;
|
|
399
|
+
return promise;
|
|
400
|
+
},
|
|
401
|
+
rotate() {
|
|
402
|
+
const myEpoch = ++epoch;
|
|
403
|
+
cached = null;
|
|
404
|
+
inFlightLoad = null;
|
|
405
|
+
let promise = null;
|
|
406
|
+
promise = (async () => {
|
|
407
|
+
requireSubtleCrypto();
|
|
408
|
+
return createAndPersist(myEpoch, resolveStorage(), () => promise);
|
|
409
|
+
})().finally(() => {
|
|
410
|
+
if (inFlightRotate === promise)
|
|
411
|
+
inFlightRotate = null;
|
|
412
|
+
});
|
|
413
|
+
inFlightRotate = promise;
|
|
414
|
+
return promise;
|
|
415
|
+
},
|
|
416
|
+
clear() {
|
|
417
|
+
epoch++;
|
|
418
|
+
cached = null;
|
|
419
|
+
inFlightLoad = null;
|
|
420
|
+
inFlightRotate = null;
|
|
421
|
+
safeRemove(resolveStorage());
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { defaultIceServers, joinRoom } from './room.js';
|
|
2
|
-
export { createIdentity, exportIdentity, importIdentity, isSerializedIdentity } from './identity.js';
|
|
3
|
-
export type { CreateIdentityOptions, PeerIdentity, SerializedIdentity } from './identity.js';
|
|
2
|
+
export { createIdentity, createIdentityStore, exportIdentity, importIdentity, isSerializedIdentity } from './identity.js';
|
|
3
|
+
export type { CreateIdentityOptions, IdentityStorage, IdentityStore, IdentityStoreOptions, PeerIdentity, SerializedIdentity } from './identity.js';
|
|
4
4
|
export type { AddStreamOptions, Delivery, ListenOptions, PeerRoute, PeerStats, PeerStreamMeta, RemoveStreamOptions, Room, RoomError, RoomErrorCode, RoomOptions, RTCPeerConnectionConstructor, SendOptions, SendResult } from './room.js';
|
|
5
5
|
export { binaryCodec, createChannel, createCodecChannel, jsonCodec, textCodec } from './channel.js';
|
|
6
6
|
export type { Channel, ChannelOptions, ChannelSendOptions, Codec, CodecChannel } from './channel.js';
|
|
@@ -10,8 +10,8 @@ export { createPeerState } from './state.js';
|
|
|
10
10
|
export type { PeerState, PeerStateChangeReason, PeerStateOptions } from './state.js';
|
|
11
11
|
export { createBlobChannel } from './blob.js';
|
|
12
12
|
export type { BlobChannel, BlobChannelOptions, BlobProgress, BlobSendOptions, BlobSendStatus } from './blob.js';
|
|
13
|
-
export { createVoice } from './voice.js';
|
|
14
|
-
export type { MicError, MicErrorCode, MicStatus, Voice, VoiceOptions, VoiceSnapshot } from './voice.js';
|
|
13
|
+
export { createVoice, listAudioInputs, onAudioInputsChange } from './voice.js';
|
|
14
|
+
export type { AudioInputDevice, AudioInputsChangeOptions, MicError, MicErrorCode, MicStatus, Voice, VoiceOptions, VoiceSnapshot } from './voice.js';
|
|
15
15
|
export { fetchTurnCredentials } from './turn.js';
|
|
16
16
|
export type { FetchTurnOptions } from './turn.js';
|
|
17
17
|
export { tabSignaling } from './tabs.js';
|
|
@@ -24,7 +24,7 @@ export type { NostrSignalingOptions } from './nostr.js';
|
|
|
24
24
|
export { optionalWsSignaling, wsSignaling } from './ws.js';
|
|
25
25
|
export type { OptionalWsSignalingOptions, WsSignalingOptions } from './ws.js';
|
|
26
26
|
export { publicSignaling } from './public.js';
|
|
27
|
-
export type { PublicSignalingOptions } from './public.js';
|
|
27
|
+
export type { PublicSignalingOptions, PublicTransportEvent, PublicTransportKind } from './public.js';
|
|
28
28
|
export { combineSignaling, withLocalTabs } from './combine.js';
|
|
29
|
-
export { isSignal, isUuid, withLoopbackFallback } from './signaling.js';
|
|
29
|
+
export { isSignal, isUuid, observeSignaling, withLoopbackFallback } from './signaling.js';
|
|
30
30
|
export type { Discovery, IceCandidatePayload, Signal, Signaling, SignalingErrorCode, SignalingSession, SignalingState, WebSocketConstructor } from './signaling.js';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { defaultIceServers, joinRoom } from './room.js';
|
|
2
|
-
export { createIdentity, exportIdentity, importIdentity, isSerializedIdentity } from './identity.js';
|
|
2
|
+
export { createIdentity, createIdentityStore, exportIdentity, importIdentity, isSerializedIdentity } from './identity.js';
|
|
3
3
|
export { binaryCodec, createChannel, createCodecChannel, jsonCodec, textCodec } from './channel.js';
|
|
4
4
|
export { createRpc, RpcError } from './rpc.js';
|
|
5
5
|
export { createPeerState } from './state.js';
|
|
6
6
|
export { createBlobChannel } from './blob.js';
|
|
7
|
-
export { createVoice } from './voice.js';
|
|
7
|
+
export { createVoice, listAudioInputs, onAudioInputsChange } from './voice.js';
|
|
8
8
|
export { fetchTurnCredentials } from './turn.js';
|
|
9
9
|
export { tabSignaling } from './tabs.js';
|
|
10
10
|
export { manualSignaling } from './manual.js';
|
|
@@ -13,4 +13,4 @@ export { defaultNostrRelays, nostrSignaling } from './nostr.js';
|
|
|
13
13
|
export { optionalWsSignaling, wsSignaling } from './ws.js';
|
|
14
14
|
export { publicSignaling } from './public.js';
|
|
15
15
|
export { combineSignaling, withLocalTabs } from './combine.js';
|
|
16
|
-
export { isSignal, isUuid, withLoopbackFallback } from './signaling.js';
|
|
16
|
+
export { isSignal, isUuid, observeSignaling, withLoopbackFallback } from './signaling.js';
|
package/dist/listeners.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
const abortHub = new WeakMap();
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function reportAsyncError(error) {
|
|
4
|
+
if (typeof globalThis.reportError === 'function') {
|
|
5
|
+
globalThis.reportError(error);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
queueMicrotask(() => {
|
|
9
|
+
throw error;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
2
13
|
/**
|
|
3
14
|
* Subscribe `fn` to an `AbortSignal` while attaching at most ONE native `'abort'`
|
|
4
15
|
* listener per `AbortSignal` across all Meshpost primitives (preventing Node.js
|
|
@@ -25,7 +36,7 @@ export function bindAbort(signal, fn) {
|
|
|
25
36
|
cb();
|
|
26
37
|
}
|
|
27
38
|
catch (error) {
|
|
28
|
-
|
|
39
|
+
reportAsyncError(error);
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
};
|
|
@@ -50,10 +61,13 @@ export function bindAbort(signal, fn) {
|
|
|
50
61
|
};
|
|
51
62
|
}
|
|
52
63
|
/** @internal */
|
|
53
|
-
export function createListeners() {
|
|
64
|
+
export function createListeners(onRemove) {
|
|
54
65
|
const entries = new Set();
|
|
55
66
|
let closed = false;
|
|
56
67
|
return {
|
|
68
|
+
get size() {
|
|
69
|
+
return entries.size;
|
|
70
|
+
},
|
|
57
71
|
add(fn, options) {
|
|
58
72
|
if (typeof fn !== 'function')
|
|
59
73
|
throw new TypeError('Expected a listener function');
|
|
@@ -68,6 +82,7 @@ export function createListeners() {
|
|
|
68
82
|
if (!entries.delete(entry))
|
|
69
83
|
return;
|
|
70
84
|
unbindAbort?.();
|
|
85
|
+
onRemove?.();
|
|
71
86
|
}
|
|
72
87
|
};
|
|
73
88
|
entries.add(entry);
|
|
@@ -84,7 +99,7 @@ export function createListeners() {
|
|
|
84
99
|
entry.fn(...args);
|
|
85
100
|
}
|
|
86
101
|
catch (error) {
|
|
87
|
-
|
|
102
|
+
reportAsyncError(error);
|
|
88
103
|
}
|
|
89
104
|
}
|
|
90
105
|
},
|