@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.
@@ -0,0 +1,16 @@
1
+ export { defaultIceServers, joinRoom } from './room.js';
2
+ export type { Delivery, ListenOptions, PeerRoute, PeerStats, Room, RoomError, RoomErrorCode, RoomOptions, SendOptions, SendResult } from './room.js';
3
+ export { createChannel } from './channel.js';
4
+ export type { Channel, ChannelOptions, ChannelSendOptions } from './channel.js';
5
+ export { createBlobChannel } from './blob.js';
6
+ export type { BlobChannel, BlobChannelOptions, BlobProgress, BlobSendOptions, BlobSendStatus } from './blob.js';
7
+ export { tabSignaling } from './tabs.js';
8
+ export { manualSignaling } from './manual.js';
9
+ export type { ManualSignaling } from './manual.js';
10
+ export { defaultMqttRelays, mqttSignaling } from './mqtt.js';
11
+ export type { MqttSignalingOptions } from './mqtt.js';
12
+ export { wsSignaling } from './ws.js';
13
+ export type { WsSignalingOptions } from './ws.js';
14
+ export { combineSignaling } from './combine.js';
15
+ export { isSignal, isUuid, withLoopbackFallback } from './signaling.js';
16
+ export type { Discovery, IceCandidatePayload, Signal, Signaling, SignalingErrorCode, SignalingSession, SignalingState } from './signaling.js';
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { defaultIceServers, joinRoom } from './room.js';
2
+ export { createChannel } from './channel.js';
3
+ export { createBlobChannel } from './blob.js';
4
+ export { tabSignaling } from './tabs.js';
5
+ export { manualSignaling } from './manual.js';
6
+ export { defaultMqttRelays, mqttSignaling } from './mqtt.js';
7
+ export { wsSignaling } from './ws.js';
8
+ export { combineSignaling } from './combine.js';
9
+ export { isSignal, isUuid, withLoopbackFallback } from './signaling.js';
@@ -0,0 +1,13 @@
1
+ import { type Signaling } from './signaling.js';
2
+ export interface ManualSignaling {
3
+ /** Pass this adapter into `joinRoom(name, { signaling: manual.signaling })`. */
4
+ readonly signaling: Signaling;
5
+ /** Return your contact card JSON to share with another peer. */
6
+ contact(): string;
7
+ /** Apply an incoming contact card or reply JSON from another peer. */
8
+ accept(text: string): void;
9
+ /** Stop requesting new attempts for this contact. Existing data channels stay open. */
10
+ forget(peerId: string): void;
11
+ }
12
+ /** One instance per room. Users carry the generated text between trusted browsers. */
13
+ export declare function manualSignaling(outgoing: (to: string, text: string) => void): ManualSignaling;
package/dist/manual.js ADDED
@@ -0,0 +1,109 @@
1
+ import { isSignal, isUuid, namespaceHash } from './signaling.js';
2
+ function authTag(d) {
3
+ return d.password !== undefined
4
+ ? namespaceHash(d.appId + ':' + d.room + ':' + d.password)
5
+ : undefined;
6
+ }
7
+ /** One instance per room. Users carry the generated text between trusted browsers. */
8
+ export function manualSignaling(outgoing) {
9
+ let active;
10
+ let suppressNeedFor;
11
+ const known = new Set();
12
+ const lastNeed = new Map();
13
+ const encode = (d, fields) => {
14
+ const auth = authTag(d);
15
+ return JSON.stringify({
16
+ v: 1,
17
+ app: d.appId,
18
+ room: d.room,
19
+ from: d.self,
20
+ ...(auth !== undefined ? { auth } : {}),
21
+ ...fields
22
+ });
23
+ };
24
+ const signaling = (d) => {
25
+ if (active)
26
+ throw new Error('Manual adapter already in use');
27
+ active = d;
28
+ queueMicrotask(() => {
29
+ if (active === d)
30
+ d.status('online');
31
+ });
32
+ return {
33
+ send(to, signal) {
34
+ if (active !== d)
35
+ return false;
36
+ const text = encode(d, { to, signal });
37
+ if (signal.kind === 'need') {
38
+ if (suppressNeedFor === to || lastNeed.get(to) === text)
39
+ return true;
40
+ lastNeed.set(to, text);
41
+ }
42
+ else {
43
+ lastNeed.delete(to);
44
+ }
45
+ outgoing(to, text);
46
+ return true;
47
+ },
48
+ close() {
49
+ if (active !== d)
50
+ return;
51
+ active = undefined;
52
+ suppressNeedFor = undefined;
53
+ known.clear();
54
+ lastNeed.clear();
55
+ }
56
+ };
57
+ };
58
+ return {
59
+ signaling,
60
+ contact() {
61
+ if (!active)
62
+ throw new Error('Join a room first');
63
+ return encode(active, {});
64
+ },
65
+ accept(text) {
66
+ const d = active;
67
+ if (!d)
68
+ throw new Error('Join a room first');
69
+ if (text.length > 128 * 1024)
70
+ throw new RangeError('Connection text is too large');
71
+ const msg = JSON.parse(text);
72
+ if (!msg ||
73
+ msg.v !== 1 ||
74
+ msg.app !== d.appId ||
75
+ msg.room !== d.room ||
76
+ msg.auth !== authTag(d) ||
77
+ !isUuid(msg.from) ||
78
+ msg.from === d.self)
79
+ throw new Error('Wrong room, app, password, or sender');
80
+ if (msg.signal !== undefined || msg.to !== undefined) {
81
+ if (msg.to !== d.self || !isSignal(msg.signal))
82
+ throw new Error('Invalid or misaddressed signal');
83
+ }
84
+ if (!known.has(msg.from)) {
85
+ known.add(msg.from);
86
+ if (msg.signal?.kind === 'offer') {
87
+ suppressNeedFor = msg.from;
88
+ try {
89
+ d.roster([...known]);
90
+ }
91
+ finally {
92
+ suppressNeedFor = undefined;
93
+ }
94
+ }
95
+ else {
96
+ d.roster([...known]);
97
+ }
98
+ }
99
+ if (msg.signal)
100
+ d.receive(msg.from, msg.signal);
101
+ },
102
+ /** Stop requesting new attempts for this contact. Existing data channels stay open. */
103
+ forget(peer) {
104
+ lastNeed.delete(peer);
105
+ if (known.delete(peer))
106
+ active?.roster([...known]);
107
+ }
108
+ };
109
+ }
package/dist/mqtt.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { type Signaling } from './signaling.js';
2
+ /** Built-in public MQTT-over-WebSocket relay URLs used by default. */
3
+ export declare const defaultMqttRelays: readonly string[];
4
+ export interface MqttSignalingOptions {
5
+ /** MQTT-over-WebSocket broker URLs to connect to in parallel for redundancy. @default defaultMqttRelays */
6
+ urls?: readonly string[];
7
+ /** Application namespace mixed into the hashed room topic. */
8
+ appId?: string;
9
+ /** Optional shared password to encrypt signaling payloads with AES-256-GCM (requires secure context). */
10
+ password?: string;
11
+ /** Maximum time in milliseconds to wait for CONNECT -> CONNACK -> SUBACK per broker. @default 10000 */
12
+ handshakeTimeoutMs?: number;
13
+ }
14
+ /**
15
+ * Zero-backend signaling over public (or custom) MQTT-over-WebSocket brokers.
16
+ * Connects to multiple brokers in parallel for redundancy, splits presence and unicast topics,
17
+ * deduplicates multi-broker traffic, works even from `file://`, and optionally encrypts
18
+ * handshakes with AES-256-GCM (+ topic AAD and timestamp anti-replay) when `password` is provided.
19
+ */
20
+ export declare function mqttSignaling(options?: MqttSignalingOptions): Signaling;