@kyneta/webrtc-transport 1.8.0 → 2.0.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/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneratedChannel, Transport
|
|
1
|
+
import { GeneratedChannel, Transport } from "@kyneta/transport";
|
|
2
2
|
|
|
3
3
|
//#region src/data-channel-like.d.ts
|
|
4
4
|
/**
|
|
@@ -229,7 +229,7 @@ declare class WebrtcTransport extends Transport<DataChannelContext> {
|
|
|
229
229
|
* })
|
|
230
230
|
* ```
|
|
231
231
|
*/
|
|
232
|
-
declare function createWebrtcTransport(options?: WebrtcTransportOptions):
|
|
232
|
+
declare function createWebrtcTransport(options?: WebrtcTransportOptions): WebrtcTransport;
|
|
233
233
|
//#endregion
|
|
234
234
|
export { DEFAULT_FRAGMENT_THRESHOLD, type DataChannelLike, WebrtcTransport, type WebrtcTransportOptions, createWebrtcTransport };
|
|
235
235
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/data-channel-like.ts","../src/webrtc-transport.ts"],"mappings":";;;;;;AA6CA;;;;;;;;;;;;;;;;;;AAyDkE;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/data-channel-like.ts","../src/webrtc-transport.ts"],"mappings":";;;;;;AA6CA;;;;;;;;;;;;;;;;;;AAyDkE;;;;ACvElE;UDciB,eAAA;;;ACdmC;AASpD;;;;AAOmB;AAClB;;;WDSU,UAAA;ECCT;;;;AACwB;AAuD1B;;;;;;ED5CE,UAAA;ECgGiB;;;;;;;;EDtFjB,IAAA,CAAK,IAAA,EAAM,UAAU;;;;;;;;;;;;EAarB,gBAAA,CAAiB,IAAA,UAAc,QAAA,GAAW,KAAA;ECyGxC;;;;;;;EDhGF,mBAAA,CAAoB,IAAA,UAAc,QAAA,GAAW,KAAA;AAAA;;;AAzD/C;;;;;;;;;AAAA,cCda,0BAAA;;;;UASI,sBAAA;ED8DK;;;;AAA4C;;ECvDhE,iBAAiB;AAAA;AAhBnB;;;AAAA,KA0BK,kBAAA;EACH,YAAA;EACA,OAAA,EAAS,eAAe;AAAA;;;AAZP;AAClB;;;;;;;;AAWyB;AAuD1B;;;;;;;;;;;;;;;;;;;;;;;;;cAAa,eAAA,SAAwB,SAAA,CAAU,kBAAA;EAAA;cAWjC,OAAA,GAAU,sBAAA;EAyEpB;;;;;;EAAA,UAzDQ,QAAA,CAAS,OAAA,EAAS,kBAAA,GAAqB,gBAAA;EA0KjD;;AAAkB;AAyHpB;;;EA1QQ,OAAA,CAAA,GAAW,OAAA;EA2QP;;;;AACM;EArQV,MAAA,CAAA,GAAU,OAAA;;;;;;;;;;;;;;;EAwBhB,iBAAA,CACE,YAAA,UACA,OAAA,EAAS,eAAA;;;;;;;;;;EAqFX,iBAAA,CAAkB,YAAA;;;;EAoBlB,cAAA,CAAe,YAAA;;;;EAOf,kBAAA,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;iBAyHc,qBAAA,CACd,OAAA,GAAU,sBAAA,GACT,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -115,7 +115,8 @@ var WebrtcTransport = class extends Transport {
|
|
|
115
115
|
opts: {
|
|
116
116
|
threshold: this.#fragmentThreshold,
|
|
117
117
|
reassemblyTimeoutMs: 1e4,
|
|
118
|
-
onError: (e, dir) => console.warn(`[webrtc-transport] wire error (${dir}) for peer ${remotePeerId}:`, e)
|
|
118
|
+
onError: (e, dir) => console.warn(`[webrtc-transport] wire error (${dir}) for peer ${remotePeerId}:`, e),
|
|
119
|
+
onFrame: (ev) => this.frameObserver?.(ev)
|
|
119
120
|
}
|
|
120
121
|
});
|
|
121
122
|
const onOpen = () => {
|
|
@@ -253,7 +254,7 @@ var WebrtcTransport = class extends Transport {
|
|
|
253
254
|
* ```
|
|
254
255
|
*/
|
|
255
256
|
function createWebrtcTransport(options) {
|
|
256
|
-
return
|
|
257
|
+
return new WebrtcTransport(options);
|
|
257
258
|
}
|
|
258
259
|
//#endregion
|
|
259
260
|
export { DEFAULT_FRAGMENT_THRESHOLD, WebrtcTransport, createWebrtcTransport };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#attachedChannels","#fragmentThreshold","#createSyncChannel","#removeSyncChannel","#handleMessage"],"sources":["../src/webrtc-transport.ts"],"sourcesContent":["// webrtc-transport — BYODC WebRTC data channel transport for @kyneta/exchange.\n//\n// \"Bring Your Own Data Channel\" design: the application manages WebRTC\n// connections (signaling, ICE, media streams). This transport attaches\n// to already-established data channels for kyneta document sync.\n//\n// Uses the shared Pipeline from @kyneta/transport (same as WebSocket):\n// pipeline.send(msg) — outbound: alias → encode → fragment\n// pipeline.receive(data) — inbound: reassemble → decode → alias → ChannelMsg\n//\n// The transport accepts any object satisfying `DataChannelLike` — a\n// 5-member interface that native RTCDataChannel satisfies structurally\n// and that libraries like simple-peer can conform to via a trivial bridge.\n\nimport type {\n ChannelId,\n ChannelMsg,\n GeneratedChannel,\n TransportFactory,\n} from \"@kyneta/transport\"\nimport { Pipeline, Transport } from \"@kyneta/transport\"\nimport type { DataChannelLike } from \"./data-channel-like.js\"\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\n/**\n * Default fragment threshold in bytes.\n *\n * SCTP (the underlying transport for WebRTC data channels) has a message\n * size limit of approximately 256KB. 200KB provides a safe margin.\n *\n * This differs from the WebSocket transport's 100KB default, which\n * targets AWS API Gateway's 128KB limit. WebRTC has no such gateway.\n */\nexport const DEFAULT_FRAGMENT_THRESHOLD = 200 * 1024\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/**\n * Configuration options for the WebRTC transport.\n */\nexport interface WebrtcTransportOptions {\n /**\n * Fragment threshold in bytes. Messages larger than this are fragmented\n * for SCTP compatibility. Set to 0 to disable fragmentation (not recommended).\n *\n * @default 204800 (200KB)\n */\n fragmentThreshold?: number\n}\n\n// ---------------------------------------------------------------------------\n// Internal types\n// ---------------------------------------------------------------------------\n\n/**\n * Context for each attached data channel — stored per remotePeerId.\n */\ntype DataChannelContext = {\n remotePeerId: string\n channel: DataChannelLike\n}\n\n/**\n * Internal tracking for an attached data channel.\n */\ntype AttachedChannel = {\n remotePeerId: string\n channel: DataChannelLike\n channelId: ChannelId | null\n pipeline: Pipeline<\"binary\">\n cleanup: () => void\n}\n\n// ---------------------------------------------------------------------------\n// WebrtcTransport\n// ---------------------------------------------------------------------------\n\n/**\n * WebRTC data channel transport for @kyneta/exchange.\n *\n * Follows a \"Bring Your Own Data Channel\" (BYODC) design — the application\n * manages WebRTC connections and attaches data channels to this transport\n * for kyneta document synchronization.\n *\n * Uses binary CBOR encoding with transport-level fragmentation via\n * `@kyneta/wire` — the same pipeline as the WebSocket transport.\n *\n * ## Usage\n *\n * ```typescript\n * import { Exchange } from \"@kyneta/exchange\"\n * import { createWebrtcTransport } from \"@kyneta/webrtc-transport\"\n *\n * const webrtcTransport = createWebrtcTransport()\n *\n * const exchange = new Exchange({\n * id: { peerId: \"alice\", name: \"Alice\" },\n * transports: [webrtcTransport],\n * })\n *\n * // When a WebRTC connection is established:\n * const cleanup = transport.attachDataChannel(remotePeerId, dataChannel)\n *\n * // When done:\n * cleanup() // or transport.detachDataChannel(remotePeerId)\n * ```\n *\n * ## Ownership\n *\n * The transport does NOT own the data channel. `detachDataChannel()`\n * removes the sync channel and event listeners but does not close the\n * data channel or the peer connection. The application manages the\n * WebRTC connection lifecycle independently.\n */\nexport class WebrtcTransport extends Transport<DataChannelContext> {\n /**\n * Map of remotePeerId → attached channel tracking.\n */\n readonly #attachedChannels = new Map<string, AttachedChannel>()\n\n /**\n * Fragment threshold in bytes.\n */\n readonly #fragmentThreshold: number\n\n constructor(options?: WebrtcTransportOptions) {\n super({ transportType: \"webrtc-datachannel\" })\n this.#fragmentThreshold =\n options?.fragmentThreshold ?? DEFAULT_FRAGMENT_THRESHOLD\n }\n\n // ==========================================================================\n // Transport abstract method implementations\n // ==========================================================================\n\n /**\n * Generate a channel for a data channel context.\n *\n * Called internally by the `Transport` base class when `addChannel()` is\n * invoked. Users never call this directly — use `attachDataChannel()`.\n */\n protected generate(context: DataChannelContext): GeneratedChannel {\n const { channel } = context\n\n return {\n transportType: this.transportType,\n send: (msg: ChannelMsg) => {\n const attached = this.#attachedChannels.get(context.remotePeerId)\n if (!attached || channel.readyState !== \"open\") return\n for (const r of attached.pipeline.send(msg)) {\n if (r.ok) channel.send(r.value)\n }\n },\n stop: () => {\n // Cleanup is handled by detachDataChannel().\n // This callback fires when the internal channel is removed.\n },\n }\n }\n\n /**\n * Called when the transport starts.\n *\n * No-op for WebRTC — channels are added dynamically via\n * `attachDataChannel()`, not at start time.\n */\n async onStart(): Promise<void> {}\n\n /**\n * Called when the transport stops.\n *\n * Detaches all attached data channels and cleans up resources.\n */\n async onStop(): Promise<void> {\n for (const remotePeerId of [...this.#attachedChannels.keys()]) {\n this.detachDataChannel(remotePeerId)\n }\n }\n\n // ==========================================================================\n // Public API — data channel management\n // ==========================================================================\n\n /**\n * Attach a data channel for a remote peer.\n *\n * Creates an internal sync channel when the data channel is open\n * (or waits for the `\"open\"` event if still connecting). The sync\n * channel triggers the establishment handshake with the remote peer.\n *\n * If a data channel is already attached for this peer, the old one\n * is detached first.\n *\n * @param remotePeerId - The stable peer ID of the remote peer\n * @param channel - Any object satisfying `DataChannelLike`\n * @returns A cleanup function that calls `detachDataChannel(remotePeerId)`\n */\n attachDataChannel(\n remotePeerId: string,\n channel: DataChannelLike,\n ): () => void {\n // Detach existing channel for this peer if any\n if (this.#attachedChannels.has(remotePeerId)) {\n this.detachDataChannel(remotePeerId)\n }\n\n // Best-effort: request arraybuffer mode for incoming data.\n // The message handler doesn't depend on this — it accepts both\n // ArrayBuffer and Uint8Array regardless.\n channel.binaryType = \"arraybuffer\"\n\n // Create pipeline for this data channel\n const pipeline = new Pipeline<\"binary\">({\n send: \"binary\",\n opts: {\n threshold: this.#fragmentThreshold,\n reassemblyTimeoutMs: 10_000,\n onError: (e, dir) =>\n console.warn(\n `[webrtc-transport] wire error (${dir}) for peer ${remotePeerId}:`,\n e,\n ),\n },\n })\n\n // Event handlers — stored as named functions for removeEventListener\n const onOpen = () => {\n this.#createSyncChannel(remotePeerId)\n }\n\n const onClose = () => {\n this.#removeSyncChannel(remotePeerId)\n }\n\n const onError = () => {\n this.#removeSyncChannel(remotePeerId)\n }\n\n const onMessage = (event: any) => {\n this.#handleMessage(remotePeerId, event)\n }\n\n // Cleanup function to remove all event listeners\n const cleanup = () => {\n channel.removeEventListener(\"open\", onOpen)\n channel.removeEventListener(\"close\", onClose)\n channel.removeEventListener(\"error\", onError)\n channel.removeEventListener(\"message\", onMessage)\n }\n\n // Register event listeners\n channel.addEventListener(\"open\", onOpen)\n channel.addEventListener(\"close\", onClose)\n channel.addEventListener(\"error\", onError)\n channel.addEventListener(\"message\", onMessage)\n\n // Track the attached channel\n const attached: AttachedChannel = {\n remotePeerId,\n channel,\n channelId: null,\n pipeline,\n cleanup,\n }\n this.#attachedChannels.set(remotePeerId, attached)\n\n // If the channel is already open, create the sync channel immediately\n if (channel.readyState === \"open\") {\n this.#createSyncChannel(remotePeerId)\n }\n\n return () => this.detachDataChannel(remotePeerId)\n }\n\n /**\n * Detach a data channel for a remote peer.\n *\n * Removes the sync channel, cleans up event listeners, and disposes\n * the reassembler. Does NOT close the data channel — the application\n * manages the WebRTC connection lifecycle.\n *\n * @param remotePeerId - The peer ID to detach\n */\n detachDataChannel(remotePeerId: string): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached) return\n\n // Remove the sync channel if it exists\n this.#removeSyncChannel(remotePeerId)\n\n // Dispose the pipeline to clean up timers and state\n attached.pipeline.dispose()\n\n // Remove event listeners from the data channel\n attached.cleanup()\n\n // Remove from tracking\n this.#attachedChannels.delete(remotePeerId)\n }\n\n /**\n * Check if a data channel is attached for a peer.\n */\n hasDataChannel(remotePeerId: string): boolean {\n return this.#attachedChannels.has(remotePeerId)\n }\n\n /**\n * Get all peer IDs with attached data channels.\n */\n getAttachedPeerIds(): string[] {\n return [...this.#attachedChannels.keys()]\n }\n\n // ==========================================================================\n // Internal — sync channel lifecycle\n // ==========================================================================\n\n /**\n * Create an internal sync channel for an attached data channel.\n *\n * Called when the data channel's `\"open\"` event fires (or immediately\n * if already open on attach). The sync channel is registered with the\n * Transport base class, which triggers the establishment handshake.\n */\n #createSyncChannel(remotePeerId: string): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached) return\n\n // Don't create if already exists\n if (attached.channelId !== null) return\n\n // addChannel() creates and registers the sync channel\n const syncChannel = this.addChannel({\n remotePeerId,\n channel: attached.channel,\n })\n attached.channelId = syncChannel.channelId\n\n // Start the establishment handshake\n this.establishChannel(syncChannel.channelId)\n }\n\n /**\n * Remove the internal sync channel for a peer.\n */\n #removeSyncChannel(remotePeerId: string): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached || attached.channelId === null) return\n\n this.removeChannel(attached.channelId)\n attached.channelId = null\n }\n\n // ==========================================================================\n // Internal — message handling\n // ==========================================================================\n\n /**\n * Handle an incoming message from a data channel.\n *\n * Extracts binary data from the event, feeding both `ArrayBuffer`\n * (native RTCDataChannel with binaryType \"arraybuffer\") and\n * `Uint8Array` (simple-peer and other wrappers) into the shared\n * decode pipeline.\n */\n #handleMessage(remotePeerId: string, event: any): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached || attached.channelId === null) return\n\n const syncChannel = this.channels.get(attached.channelId)\n if (!syncChannel) return\n\n // Extract bytes — robust to both ArrayBuffer and Uint8Array.\n // Both paths produce Uint8Array<ArrayBuffer> for the pipeline.\n const raw = event.data\n const bytes: Uint8Array<ArrayBuffer> | null =\n raw instanceof ArrayBuffer\n ? new Uint8Array(raw)\n : raw instanceof Uint8Array\n ? new Uint8Array(\n raw.buffer as ArrayBuffer,\n raw.byteOffset,\n raw.byteLength,\n )\n : null\n\n if (!bytes) {\n // Unexpected data type (e.g. string) — ignore silently\n return\n }\n\n try {\n for (const r of attached.pipeline.receive(bytes)) {\n if (r.ok) syncChannel.onReceive(r.value)\n }\n } catch (error) {\n console.error(\n `[webrtc-transport] Failed to decode message from peer ${remotePeerId}:`,\n error,\n )\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Create a WebRTC transport factory for use with `Exchange`.\n *\n * Returns a `TransportFactory` — pass directly to\n * `Exchange({ transports: [...] })`. The returned transport instance\n * exposes `attachDataChannel()` / `detachDataChannel()` for BYODC\n * data channel management.\n *\n * To access the transport instance after creation, use\n * `exchange.getTransport(\"webrtc-datachannel\")`.\n *\n * @example\n * ```typescript\n * import { Exchange } from \"@kyneta/exchange\"\n * import { createWebrtcTransport } from \"@kyneta/webrtc-transport\"\n *\n * const exchange = new Exchange({\n * id: { peerId: \"alice\", name: \"Alice\" },\n * transports: [createWebrtcTransport()],\n * })\n * ```\n */\nexport function createWebrtcTransport(\n options?: WebrtcTransportOptions,\n): TransportFactory {\n return () => new WebrtcTransport(options)\n}\n"],"mappings":";;;;;;;;;;;AAoCA,MAAa,6BAA6B,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFhD,IAAa,kBAAb,cAAqC,UAA8B;;;;CAIjE,oCAA6B,IAAI,IAA6B;;;;CAK9D;CAEA,YAAY,SAAkC;EAC5C,MAAM,EAAE,eAAe,qBAAqB,CAAC;EAC7C,KAAKC,qBACH,SAAS,qBAAA;CACb;;;;;;;CAYA,SAAmB,SAA+C;EAChE,MAAM,EAAE,YAAY;EAEpB,OAAO;GACL,eAAe,KAAK;GACpB,OAAO,QAAoB;IACzB,MAAM,WAAW,KAAKD,kBAAkB,IAAI,QAAQ,YAAY;IAChE,IAAI,CAAC,YAAY,QAAQ,eAA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AAI,CAAC,OAEH;EAGF,IAAI;GACF,KAAK,MAAM,KAAK,SAAS,SAAS,QAAQ,KAAK,GAC7C,IAAI,EAAE,IAAI,YAAY,UAAU,EAAE,KAAK;EAE3C,SAAS,OAAO;GACd,QAAQ,MACN,yDAAyD,aAAa,IACtE,KACF;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,sBACd,SACkB;CAClB,aAAa,IAAI,gBAAgB,OAAO;AAC1C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#attachedChannels","#fragmentThreshold","#createSyncChannel","#removeSyncChannel","#handleMessage"],"sources":["../src/webrtc-transport.ts"],"sourcesContent":["// webrtc-transport — BYODC WebRTC data channel transport for @kyneta/exchange.\n//\n// \"Bring Your Own Data Channel\" design: the application manages WebRTC\n// connections (signaling, ICE, media streams). This transport attaches\n// to already-established data channels for kyneta document sync.\n//\n// Uses the shared Pipeline from @kyneta/transport (same as WebSocket):\n// pipeline.send(msg) — outbound: alias → encode → fragment\n// pipeline.receive(data) — inbound: reassemble → decode → alias → ChannelMsg\n//\n// The transport accepts any object satisfying `DataChannelLike` — a\n// 5-member interface that native RTCDataChannel satisfies structurally\n// and that libraries like simple-peer can conform to via a trivial bridge.\n\nimport type { ChannelId, ChannelMsg, GeneratedChannel } from \"@kyneta/transport\"\nimport { Pipeline, Transport } from \"@kyneta/transport\"\nimport type { DataChannelLike } from \"./data-channel-like.js\"\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\n/**\n * Default fragment threshold in bytes.\n *\n * SCTP (the underlying transport for WebRTC data channels) has a message\n * size limit of approximately 256KB. 200KB provides a safe margin.\n *\n * This differs from the WebSocket transport's 100KB default, which\n * targets AWS API Gateway's 128KB limit. WebRTC has no such gateway.\n */\nexport const DEFAULT_FRAGMENT_THRESHOLD = 200 * 1024\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/**\n * Configuration options for the WebRTC transport.\n */\nexport interface WebrtcTransportOptions {\n /**\n * Fragment threshold in bytes. Messages larger than this are fragmented\n * for SCTP compatibility. Set to 0 to disable fragmentation (not recommended).\n *\n * @default 204800 (200KB)\n */\n fragmentThreshold?: number\n}\n\n// ---------------------------------------------------------------------------\n// Internal types\n// ---------------------------------------------------------------------------\n\n/**\n * Context for each attached data channel — stored per remotePeerId.\n */\ntype DataChannelContext = {\n remotePeerId: string\n channel: DataChannelLike\n}\n\n/**\n * Internal tracking for an attached data channel.\n */\ntype AttachedChannel = {\n remotePeerId: string\n channel: DataChannelLike\n channelId: ChannelId | null\n pipeline: Pipeline<\"binary\">\n cleanup: () => void\n}\n\n// ---------------------------------------------------------------------------\n// WebrtcTransport\n// ---------------------------------------------------------------------------\n\n/**\n * WebRTC data channel transport for @kyneta/exchange.\n *\n * Follows a \"Bring Your Own Data Channel\" (BYODC) design — the application\n * manages WebRTC connections and attaches data channels to this transport\n * for kyneta document synchronization.\n *\n * Uses binary CBOR encoding with transport-level fragmentation via\n * `@kyneta/wire` — the same pipeline as the WebSocket transport.\n *\n * ## Usage\n *\n * ```typescript\n * import { Exchange } from \"@kyneta/exchange\"\n * import { createWebrtcTransport } from \"@kyneta/webrtc-transport\"\n *\n * const webrtcTransport = createWebrtcTransport()\n *\n * const exchange = new Exchange({\n * id: { peerId: \"alice\", name: \"Alice\" },\n * transports: [webrtcTransport],\n * })\n *\n * // When a WebRTC connection is established:\n * const cleanup = transport.attachDataChannel(remotePeerId, dataChannel)\n *\n * // When done:\n * cleanup() // or transport.detachDataChannel(remotePeerId)\n * ```\n *\n * ## Ownership\n *\n * The transport does NOT own the data channel. `detachDataChannel()`\n * removes the sync channel and event listeners but does not close the\n * data channel or the peer connection. The application manages the\n * WebRTC connection lifecycle independently.\n */\nexport class WebrtcTransport extends Transport<DataChannelContext> {\n /**\n * Map of remotePeerId → attached channel tracking.\n */\n readonly #attachedChannels = new Map<string, AttachedChannel>()\n\n /**\n * Fragment threshold in bytes.\n */\n readonly #fragmentThreshold: number\n\n constructor(options?: WebrtcTransportOptions) {\n super({ transportType: \"webrtc-datachannel\" })\n this.#fragmentThreshold =\n options?.fragmentThreshold ?? DEFAULT_FRAGMENT_THRESHOLD\n }\n\n // ==========================================================================\n // Transport abstract method implementations\n // ==========================================================================\n\n /**\n * Generate a channel for a data channel context.\n *\n * Called internally by the `Transport` base class when `addChannel()` is\n * invoked. Users never call this directly — use `attachDataChannel()`.\n */\n protected generate(context: DataChannelContext): GeneratedChannel {\n const { channel } = context\n\n return {\n transportType: this.transportType,\n send: (msg: ChannelMsg) => {\n const attached = this.#attachedChannels.get(context.remotePeerId)\n if (!attached || channel.readyState !== \"open\") return\n for (const r of attached.pipeline.send(msg)) {\n if (r.ok) channel.send(r.value)\n }\n },\n stop: () => {\n // Cleanup is handled by detachDataChannel().\n // This callback fires when the internal channel is removed.\n },\n }\n }\n\n /**\n * Called when the transport starts.\n *\n * No-op for WebRTC — channels are added dynamically via\n * `attachDataChannel()`, not at start time.\n */\n async onStart(): Promise<void> {}\n\n /**\n * Called when the transport stops.\n *\n * Detaches all attached data channels and cleans up resources.\n */\n async onStop(): Promise<void> {\n for (const remotePeerId of [...this.#attachedChannels.keys()]) {\n this.detachDataChannel(remotePeerId)\n }\n }\n\n // ==========================================================================\n // Public API — data channel management\n // ==========================================================================\n\n /**\n * Attach a data channel for a remote peer.\n *\n * Creates an internal sync channel when the data channel is open\n * (or waits for the `\"open\"` event if still connecting). The sync\n * channel triggers the establishment handshake with the remote peer.\n *\n * If a data channel is already attached for this peer, the old one\n * is detached first.\n *\n * @param remotePeerId - The stable peer ID of the remote peer\n * @param channel - Any object satisfying `DataChannelLike`\n * @returns A cleanup function that calls `detachDataChannel(remotePeerId)`\n */\n attachDataChannel(\n remotePeerId: string,\n channel: DataChannelLike,\n ): () => void {\n // Detach existing channel for this peer if any\n if (this.#attachedChannels.has(remotePeerId)) {\n this.detachDataChannel(remotePeerId)\n }\n\n // Best-effort: request arraybuffer mode for incoming data.\n // The message handler doesn't depend on this — it accepts both\n // ArrayBuffer and Uint8Array regardless.\n channel.binaryType = \"arraybuffer\"\n\n // Create pipeline for this data channel\n const pipeline = new Pipeline<\"binary\">({\n send: \"binary\",\n opts: {\n threshold: this.#fragmentThreshold,\n reassemblyTimeoutMs: 10_000,\n onError: (e, dir) =>\n console.warn(\n `[webrtc-transport] wire error (${dir}) for peer ${remotePeerId}:`,\n e,\n ),\n onFrame: ev => this.frameObserver?.(ev),\n },\n })\n\n // Event handlers — stored as named functions for removeEventListener\n const onOpen = () => {\n this.#createSyncChannel(remotePeerId)\n }\n\n const onClose = () => {\n this.#removeSyncChannel(remotePeerId)\n }\n\n const onError = () => {\n this.#removeSyncChannel(remotePeerId)\n }\n\n const onMessage = (event: any) => {\n this.#handleMessage(remotePeerId, event)\n }\n\n // Cleanup function to remove all event listeners\n const cleanup = () => {\n channel.removeEventListener(\"open\", onOpen)\n channel.removeEventListener(\"close\", onClose)\n channel.removeEventListener(\"error\", onError)\n channel.removeEventListener(\"message\", onMessage)\n }\n\n // Register event listeners\n channel.addEventListener(\"open\", onOpen)\n channel.addEventListener(\"close\", onClose)\n channel.addEventListener(\"error\", onError)\n channel.addEventListener(\"message\", onMessage)\n\n // Track the attached channel\n const attached: AttachedChannel = {\n remotePeerId,\n channel,\n channelId: null,\n pipeline,\n cleanup,\n }\n this.#attachedChannels.set(remotePeerId, attached)\n\n // If the channel is already open, create the sync channel immediately\n if (channel.readyState === \"open\") {\n this.#createSyncChannel(remotePeerId)\n }\n\n return () => this.detachDataChannel(remotePeerId)\n }\n\n /**\n * Detach a data channel for a remote peer.\n *\n * Removes the sync channel, cleans up event listeners, and disposes\n * the reassembler. Does NOT close the data channel — the application\n * manages the WebRTC connection lifecycle.\n *\n * @param remotePeerId - The peer ID to detach\n */\n detachDataChannel(remotePeerId: string): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached) return\n\n // Remove the sync channel if it exists\n this.#removeSyncChannel(remotePeerId)\n\n // Dispose the pipeline to clean up timers and state\n attached.pipeline.dispose()\n\n // Remove event listeners from the data channel\n attached.cleanup()\n\n // Remove from tracking\n this.#attachedChannels.delete(remotePeerId)\n }\n\n /**\n * Check if a data channel is attached for a peer.\n */\n hasDataChannel(remotePeerId: string): boolean {\n return this.#attachedChannels.has(remotePeerId)\n }\n\n /**\n * Get all peer IDs with attached data channels.\n */\n getAttachedPeerIds(): string[] {\n return [...this.#attachedChannels.keys()]\n }\n\n // ==========================================================================\n // Internal — sync channel lifecycle\n // ==========================================================================\n\n /**\n * Create an internal sync channel for an attached data channel.\n *\n * Called when the data channel's `\"open\"` event fires (or immediately\n * if already open on attach). The sync channel is registered with the\n * Transport base class, which triggers the establishment handshake.\n */\n #createSyncChannel(remotePeerId: string): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached) return\n\n // Don't create if already exists\n if (attached.channelId !== null) return\n\n // addChannel() creates and registers the sync channel\n const syncChannel = this.addChannel({\n remotePeerId,\n channel: attached.channel,\n })\n attached.channelId = syncChannel.channelId\n\n // Start the establishment handshake\n this.establishChannel(syncChannel.channelId)\n }\n\n /**\n * Remove the internal sync channel for a peer.\n */\n #removeSyncChannel(remotePeerId: string): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached || attached.channelId === null) return\n\n this.removeChannel(attached.channelId)\n attached.channelId = null\n }\n\n // ==========================================================================\n // Internal — message handling\n // ==========================================================================\n\n /**\n * Handle an incoming message from a data channel.\n *\n * Extracts binary data from the event, feeding both `ArrayBuffer`\n * (native RTCDataChannel with binaryType \"arraybuffer\") and\n * `Uint8Array` (simple-peer and other wrappers) into the shared\n * decode pipeline.\n */\n #handleMessage(remotePeerId: string, event: any): void {\n const attached = this.#attachedChannels.get(remotePeerId)\n if (!attached || attached.channelId === null) return\n\n const syncChannel = this.channels.get(attached.channelId)\n if (!syncChannel) return\n\n // Extract bytes — robust to both ArrayBuffer and Uint8Array.\n // Both paths produce Uint8Array<ArrayBuffer> for the pipeline.\n const raw = event.data\n const bytes: Uint8Array<ArrayBuffer> | null =\n raw instanceof ArrayBuffer\n ? new Uint8Array(raw)\n : raw instanceof Uint8Array\n ? new Uint8Array(\n raw.buffer as ArrayBuffer,\n raw.byteOffset,\n raw.byteLength,\n )\n : null\n\n if (!bytes) {\n // Unexpected data type (e.g. string) — ignore silently\n return\n }\n\n try {\n for (const r of attached.pipeline.receive(bytes)) {\n if (r.ok) syncChannel.onReceive(r.value)\n }\n } catch (error) {\n console.error(\n `[webrtc-transport] Failed to decode message from peer ${remotePeerId}:`,\n error,\n )\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory function\n// ---------------------------------------------------------------------------\n\n/**\n * Create a WebRTC transport factory for use with `Exchange`.\n *\n * Returns a `TransportFactory` — pass directly to\n * `Exchange({ transports: [...] })`. The returned transport instance\n * exposes `attachDataChannel()` / `detachDataChannel()` for BYODC\n * data channel management.\n *\n * To access the transport instance after creation, use\n * `exchange.getTransport(\"webrtc-datachannel\")`.\n *\n * @example\n * ```typescript\n * import { Exchange } from \"@kyneta/exchange\"\n * import { createWebrtcTransport } from \"@kyneta/webrtc-transport\"\n *\n * const exchange = new Exchange({\n * id: { peerId: \"alice\", name: \"Alice\" },\n * transports: [createWebrtcTransport()],\n * })\n * ```\n */\nexport function createWebrtcTransport(\n options?: WebrtcTransportOptions,\n): WebrtcTransport {\n return new WebrtcTransport(options)\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAa,6BAA6B,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFhD,IAAa,kBAAb,cAAqC,UAA8B;;;;CAIjE,oCAA6B,IAAI,IAA6B;;;;CAK9D;CAEA,YAAY,SAAkC;EAC5C,MAAM,EAAE,eAAe,qBAAqB,CAAC;EAC7C,KAAKC,qBACH,SAAS,qBAAA;CACb;;;;;;;CAYA,SAAmB,SAA+C;EAChE,MAAM,EAAE,YAAY;EAEpB,OAAO;GACL,eAAe,KAAK;GACpB,OAAO,QAAoB;IACzB,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AClB,MAAM,QACJ,eAAe,cACX,IAAI,WAAW,GAAG,IAClB,eAAe,aACb,IAAI,WACF,IAAI,QACJ,IAAI,YACJ,IAAI,UACN,IACA;EAER,IAAI,CAAC,OAEH;EAGF,IAAI;GACF,KAAK,MAAM,KAAK,SAAS,SAAS,QAAQ,KAAK,GAC7C,IAAI,EAAE,IAAI,YAAY,UAAU,EAAE,KAAK;EAE3C,SAAS,OAAO;GACd,QAAQ,MACN,yDAAyD,aAAa,IACtE,KACF;EACF;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,sBACd,SACiB;CACjB,OAAO,IAAI,gBAAgB,OAAO;AACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyneta/webrtc-transport",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "WebRTC data channel transport for @kyneta/exchange — BYODC (Bring Your Own Data Channel) with DataChannelLike interface",
|
|
5
5
|
"author": "Duane Johnson",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,17 +24,17 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@kyneta/transport": "^
|
|
27
|
+
"@kyneta/transport": "^2.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22",
|
|
31
31
|
"tsdown": "^0.22.0",
|
|
32
32
|
"typescript": "^5.9.2",
|
|
33
33
|
"vitest": "^4.0.17",
|
|
34
|
-
"@kyneta/
|
|
35
|
-
"@kyneta/
|
|
36
|
-
"@kyneta/
|
|
37
|
-
"@kyneta/
|
|
34
|
+
"@kyneta/exchange": "^2.0.0",
|
|
35
|
+
"@kyneta/transport": "^2.0.0",
|
|
36
|
+
"@kyneta/schema": "^2.0.0",
|
|
37
|
+
"@kyneta/wire": "^2.0.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsdown",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// channel management.
|
|
6
6
|
|
|
7
7
|
import type { ChannelMsg } from "@kyneta/transport"
|
|
8
|
-
import { Pipeline } from "@kyneta/transport"
|
|
8
|
+
import { Pipeline, PROTOCOL_VERSION } from "@kyneta/transport"
|
|
9
9
|
import { createTestTransportContext } from "@kyneta/transport/testing"
|
|
10
10
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
11
11
|
import { WebrtcTransport } from "../webrtc-transport.js"
|
|
@@ -41,6 +41,7 @@ async function initializeTransport(
|
|
|
41
41
|
const TEST_MSG: ChannelMsg = {
|
|
42
42
|
type: "establish",
|
|
43
43
|
identity: { peerId: "remote", name: "R", type: "user" },
|
|
44
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
/** Encode a ChannelMsg through the wire pipeline to a binary frame. */
|
|
@@ -309,6 +310,7 @@ describe("Fragmentation", () => {
|
|
|
309
310
|
name: `A Long Name ${"y".repeat(200)}`,
|
|
310
311
|
type: "user",
|
|
311
312
|
},
|
|
313
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
syncChannel.send(largeMsg)
|
|
@@ -332,6 +334,7 @@ describe("Fragmentation", () => {
|
|
|
332
334
|
name: `Name-${"w".repeat(200)}`,
|
|
333
335
|
type: "user",
|
|
334
336
|
},
|
|
337
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
335
338
|
}
|
|
336
339
|
|
|
337
340
|
// Use a Pipeline to produce properly-framed fragments (same as
|
package/src/webrtc-transport.ts
CHANGED
|
@@ -12,12 +12,7 @@
|
|
|
12
12
|
// 5-member interface that native RTCDataChannel satisfies structurally
|
|
13
13
|
// and that libraries like simple-peer can conform to via a trivial bridge.
|
|
14
14
|
|
|
15
|
-
import type {
|
|
16
|
-
ChannelId,
|
|
17
|
-
ChannelMsg,
|
|
18
|
-
GeneratedChannel,
|
|
19
|
-
TransportFactory,
|
|
20
|
-
} from "@kyneta/transport"
|
|
15
|
+
import type { ChannelId, ChannelMsg, GeneratedChannel } from "@kyneta/transport"
|
|
21
16
|
import { Pipeline, Transport } from "@kyneta/transport"
|
|
22
17
|
import type { DataChannelLike } from "./data-channel-like.js"
|
|
23
18
|
|
|
@@ -225,6 +220,7 @@ export class WebrtcTransport extends Transport<DataChannelContext> {
|
|
|
225
220
|
`[webrtc-transport] wire error (${dir}) for peer ${remotePeerId}:`,
|
|
226
221
|
e,
|
|
227
222
|
),
|
|
223
|
+
onFrame: ev => this.frameObserver?.(ev),
|
|
228
224
|
},
|
|
229
225
|
})
|
|
230
226
|
|
|
@@ -436,6 +432,6 @@ export class WebrtcTransport extends Transport<DataChannelContext> {
|
|
|
436
432
|
*/
|
|
437
433
|
export function createWebrtcTransport(
|
|
438
434
|
options?: WebrtcTransportOptions,
|
|
439
|
-
):
|
|
440
|
-
return
|
|
435
|
+
): WebrtcTransport {
|
|
436
|
+
return new WebrtcTransport(options)
|
|
441
437
|
}
|