@kyneta/websocket-transport 1.3.1 → 1.4.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/browser.d.ts +31 -30
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +2 -15
- package/dist/bun.d.ts +18 -18
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +95 -43
- package/dist/bun.js.map +1 -1
- package/dist/client-transport-CKjXedwS.d.ts +134 -0
- package/dist/client-transport-CKjXedwS.d.ts.map +1 -0
- package/dist/client-transport-DIZ-LJxs.js +510 -0
- package/dist/client-transport-DIZ-LJxs.js.map +1 -0
- package/dist/server.d.ts +120 -118
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +296 -303
- package/dist/server.js.map +1 -1
- package/dist/{types-D0lbeevu.d.ts → types-CJAcr1Df.d.ts} +71 -69
- package/dist/types-CJAcr1Df.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/__tests__/client-transport.test.ts +3 -4
- package/src/browser.ts +3 -3
- package/src/client-transport.ts +5 -6
- package/src/connection.ts +1 -1
- package/src/server-transport.ts +7 -7
- package/src/server.ts +5 -1
- package/src/service-client.ts +2 -2
- package/src/types.ts +1 -1
- package/dist/browser.js.map +0 -1
- package/dist/chunk-YZQF5RLV.js +0 -614
- package/dist/chunk-YZQF5RLV.js.map +0 -1
- package/dist/client-transport-DUAFjVbh.d.ts +0 -132
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server-transport.ts","../src/connection.ts","../src/service-client.ts"],"sourcesContent":["// server-adapter — Websocket server adapter for @kyneta/exchange.\n//\n// Manages Websocket connections from clients, encoding/decoding via the\n// kyneta wire format. Framework-agnostic — works with any Websocket\n// library through the Socket interface.\n//\n// Usage with Bun:\n// import { WebsocketServerTransport } from \"@kyneta/websocket-transport/server\"\n// import { createBunWebsocketHandlers } from \"@kyneta/websocket-transport/bun\"\n//\n// const serverAdapter = new WebsocketServerTransport()\n// Bun.serve({\n// websocket: createBunWebsocketHandlers(serverAdapter),\n// fetch(req, server) { server.upgrade(req); return new Response(\"\", { status: 101 }) },\n// })\n//\n// Usage with Node.js `ws`:\n// import { WebsocketServerTransport, wrapNodeWebsocket } from \"@kyneta/websocket-transport/server\"\n// import { WebSocketServer } from \"ws\"\n//\n// const serverAdapter = new WebsocketServerTransport()\n// const wss = new WebSocketServer({ server })\n// wss.on(\"connection\", (ws) => {\n// const { start } = serverAdapter.handleConnection({ socket: wrapNodeWebsocket(ws) })\n// start()\n// })\n//\n// Ported from @loro-extended/adapter-websocket's WsServerNetworkAdapter with\n// kyneta naming conventions and the kyneta 5-message protocol.\n\nimport type { ChannelMsg, GeneratedChannel, PeerId } from \"@kyneta/transport\"\nimport { Transport } from \"@kyneta/transport\"\nimport {\n DEFAULT_FRAGMENT_THRESHOLD,\n WebsocketConnection,\n} from \"./connection.js\"\nimport type {\n WebsocketConnectionOptions,\n WebsocketConnectionResult,\n} from \"./types.js\"\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for the Websocket server adapter.\n */\nexport interface WebsocketServerTransportOptions {\n /**\n * Fragment threshold in bytes. Messages larger than this are fragmented.\n * Set to 0 to disable fragmentation (not recommended for cloud deployments).\n * Default: 100KB (safe for AWS API Gateway's 128KB limit)\n */\n fragmentThreshold?: number\n}\n\n// ---------------------------------------------------------------------------\n// Peer ID generation\n// ---------------------------------------------------------------------------\n\n/**\n * Generate a random peer ID for connections that don't provide one.\n */\nfunction generatePeerId(): PeerId {\n const chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"\n let result = \"ws-\"\n for (let i = 0; i < 12; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length))\n }\n return result\n}\n\n// ---------------------------------------------------------------------------\n// WebsocketServerTransport\n// ---------------------------------------------------------------------------\n\n/**\n * Websocket server network adapter.\n *\n * Framework-agnostic — works with any Websocket library through the\n * `Socket` interface. Use `handleConnection()` to integrate with your\n * framework's Websocket upgrade handler.\n *\n * Each client connection is tracked as a `WebsocketConnection` keyed\n * by peer ID. The adapter creates a channel per connection and routes\n * outbound messages through the connection's send method.\n *\n * The connection handshake follows a two-phase protocol:\n * 1. Server sends text `\"ready\"` signal (transport-level)\n * 2. Client sends `establish-request` (protocol-level)\n * 3. Server responds with `establish-response` (handled by Synchronizer)\n *\n * The server does NOT call `establishChannel()` — it waits for the\n * client's establish-request to avoid a race condition where the binary\n * establish-request could arrive before the client has processed \"ready\".\n */\nexport class WebsocketServerTransport extends Transport<PeerId> {\n #connections = new Map<PeerId, WebsocketConnection>()\n readonly #fragmentThreshold: number\n\n constructor(options?: WebsocketServerTransportOptions) {\n super({ transportType: \"websocket-server\" })\n this.#fragmentThreshold =\n options?.fragmentThreshold ?? DEFAULT_FRAGMENT_THRESHOLD\n }\n\n // ==========================================================================\n // Adapter abstract method implementations\n // ==========================================================================\n\n protected generate(peerId: PeerId): GeneratedChannel {\n return {\n transportType: this.transportType,\n send: (msg: ChannelMsg) => {\n const connection = this.#connections.get(peerId)\n if (connection) {\n connection.send(msg)\n }\n },\n stop: () => {\n this.unregisterConnection(peerId)\n },\n }\n }\n\n async onStart(): Promise<void> {\n // Server adapter starts passively — connections arrive via handleConnection()\n }\n\n async onStop(): Promise<void> {\n // Disconnect all active connections\n for (const connection of this.#connections.values()) {\n connection.close(1001, \"Server shutting down\")\n }\n this.#connections.clear()\n }\n\n // ==========================================================================\n // Connection management\n // ==========================================================================\n\n /**\n * Handle a new Websocket connection.\n *\n * Call this from your framework's Websocket upgrade handler.\n * Returns a connection handle and a `start()` function that begins\n * message processing and sends the \"ready\" signal.\n *\n * @param options - Connection options including the Socket and optional peer ID\n * @returns A connection handle and start function\n *\n * @example Bun\n * ```typescript\n * const { start } = serverAdapter.handleConnection({\n * socket: wrapBunWebsocket(ws),\n * })\n * start()\n * ```\n *\n * @example Node.js ws\n * ```typescript\n * wss.on(\"connection\", (ws) => {\n * const { start } = serverAdapter.handleConnection({\n * socket: wrapNodeWebsocket(ws),\n * })\n * start()\n * })\n * ```\n */\n handleConnection(\n options: WebsocketConnectionOptions,\n ): WebsocketConnectionResult {\n const { socket, peerId: providedPeerId } = options\n\n // Generate peer ID if not provided\n const peerId = providedPeerId ?? generatePeerId()\n\n // Check for existing connection with same peer ID\n const existingConnection = this.#connections.get(peerId)\n if (existingConnection) {\n existingConnection.close(1000, \"Replaced by new connection\")\n this.unregisterConnection(peerId)\n }\n\n // Create channel for this peer\n const channel = this.addChannel(peerId)\n\n // Create connection object with fragmentation config\n const connection = new WebsocketConnection(\n peerId,\n channel.channelId,\n socket,\n {\n fragmentThreshold: this.#fragmentThreshold,\n },\n )\n connection._setChannel(channel)\n\n // Store connection\n this.#connections.set(peerId, connection)\n\n // Set up close handler\n socket.onClose((_code, _reason) => {\n this.unregisterConnection(peerId)\n })\n\n socket.onError(_error => {\n this.unregisterConnection(peerId)\n })\n\n return {\n connection,\n start: () => {\n connection.start()\n\n // Send ready signal to client so it knows the server is ready\n // This is a transport-level signal, separate from protocol-level establishment\n connection.sendReady()\n\n // NOTE: We do NOT call establishChannel() here.\n // The client will send establish-request after receiving \"ready\".\n // Our channel gets established when the Synchronizer receives\n // and processes that establish-request.\n //\n // This prevents a race condition where our binary establish-request\n // could arrive before the client has processed \"ready\" and created\n // its channel.\n },\n }\n }\n\n /**\n * Get an active connection by peer ID.\n */\n getConnection(peerId: PeerId): WebsocketConnection | undefined {\n return this.#connections.get(peerId)\n }\n\n /**\n * Get all active connections.\n */\n getAllConnections(): WebsocketConnection[] {\n return Array.from(this.#connections.values())\n }\n\n /**\n * Check if a peer is connected.\n */\n isConnected(peerId: PeerId): boolean {\n return this.#connections.has(peerId)\n }\n\n /**\n * Unregister a connection, removing its channel and cleaning up state.\n */\n unregisterConnection(peerId: PeerId): void {\n const connection = this.#connections.get(peerId)\n if (connection) {\n this.removeChannel(connection.channelId)\n this.#connections.delete(peerId)\n }\n }\n\n /**\n * Broadcast a message to all connected peers.\n */\n broadcast(msg: ChannelMsg): void {\n for (const connection of this.#connections.values()) {\n connection.send(msg)\n }\n }\n\n /**\n * Get the number of connected peers.\n */\n get connectionCount(): number {\n return this.#connections.size\n }\n}\n","// connection — WebsocketConnection for server-side peer connections.\n//\n// Wraps a Socket + CBOR codec + FragmentReassembler to provide\n// send/receive for ChannelMsg over a single Websocket connection.\n//\n// Used by WebsocketServerTransport to manage individual client connections.\n// The client adapter handles its own encoding/decoding inline since it\n// manages a single socket with reconnection logic.\n//\n// Ported from @loro-extended/adapter-websocket's WsConnection with\n// kyneta naming conventions and the kyneta wire format.\n\nimport type { Channel, ChannelMsg, PeerId } from \"@kyneta/transport\"\nimport {\n decodeBinaryMessages,\n encodeBinaryAndSend,\n FragmentReassembler,\n} from \"@kyneta/wire\"\nimport type { Socket } from \"./types.js\"\n\n/**\n * Default fragment threshold in bytes.\n * Messages larger than this are fragmented for cloud infrastructure compatibility.\n * AWS API Gateway has a 128KB limit, so 100KB provides a safe margin.\n */\nexport const DEFAULT_FRAGMENT_THRESHOLD = 100 * 1024\n\n/**\n * Configuration for creating a WebsocketConnection.\n */\nexport interface WebsocketConnectionConfig {\n /**\n * Fragment threshold in bytes. Messages larger than this are fragmented.\n * Set to 0 to disable fragmentation (not recommended for cloud deployments).\n * Default: 100KB (safe for AWS API Gateway's 128KB limit)\n */\n fragmentThreshold?: number\n}\n\n/**\n * Represents a single Websocket connection to a peer (server-side).\n *\n * Manages encoding, framing, fragmentation, and reassembly for one\n * connected client. Created by `WebsocketServerTransport.handleConnection()`.\n *\n * The connection uses the CBOR codec for binary transport — this is\n * the natural choice for Websocket's binary frame support.\n */\nexport class WebsocketConnection {\n readonly peerId: PeerId\n readonly channelId: number\n\n #socket: Socket\n #channel: Channel | null = null\n #started = false\n\n // Fragmentation support\n readonly #fragmentThreshold: number\n readonly #reassembler: FragmentReassembler\n\n constructor(\n peerId: PeerId,\n channelId: number,\n socket: Socket,\n config?: WebsocketConnectionConfig,\n ) {\n this.peerId = peerId\n this.channelId = channelId\n this.#socket = socket\n this.#fragmentThreshold =\n config?.fragmentThreshold ?? DEFAULT_FRAGMENT_THRESHOLD\n this.#reassembler = new FragmentReassembler({\n timeoutMs: 10_000,\n onTimeout: (frameId: string) => {\n console.warn(\n `[WebsocketConnection] Fragment batch timed out: ${frameId}`,\n )\n },\n })\n }\n\n // ==========================================================================\n // INTERNAL API — for adapter use\n // ==========================================================================\n\n /**\n * Set the channel reference.\n * Called by the adapter when the channel is created.\n * @internal\n */\n _setChannel(channel: Channel): void {\n this.#channel = channel\n }\n\n // ==========================================================================\n // PUBLIC API\n // ==========================================================================\n\n /**\n * Start processing messages on this connection.\n *\n * Sets up the message handler on the socket. Must be called after\n * the connection is fully set up (channel assigned, stored in adapter).\n */\n start(): void {\n if (this.#started) {\n return\n }\n this.#started = true\n\n this.#socket.onMessage(data => {\n this.#handleMessage(data)\n })\n }\n\n /**\n * Send a ChannelMsg through the Websocket.\n *\n * Encodes via CBOR codec → frame → fragment if needed → socket.send().\n */\n send(msg: ChannelMsg): void {\n if (this.#socket.readyState !== \"open\") {\n return\n }\n\n encodeBinaryAndSend(msg, this.#fragmentThreshold, data =>\n this.#socket.send(data),\n )\n }\n\n /**\n * Send a \"ready\" signal to the client.\n *\n * This is a transport-level text message that tells the client the\n * server is ready to receive protocol messages. The client creates\n * its channel and sends establish-request after receiving this.\n */\n sendReady(): void {\n if (this.#socket.readyState !== \"open\") {\n return\n }\n this.#socket.send(\"ready\")\n }\n\n /**\n * Close the connection and clean up resources.\n */\n close(code?: number, reason?: string): void {\n this.#reassembler.dispose()\n this.#socket.close(code, reason)\n }\n\n // ==========================================================================\n // INTERNAL — message handling\n // ==========================================================================\n\n /**\n * Handle an incoming message from the Websocket.\n */\n #handleMessage(data: Uint8Array | string): void {\n // Handle keepalive ping/pong (text frames)\n if (typeof data === \"string\") {\n this.#handleKeepalive(data)\n return\n }\n\n // Handle binary protocol messages through shared decode pipeline\n try {\n const messages = decodeBinaryMessages(data, this.#reassembler)\n if (messages) {\n for (const msg of messages) {\n this.#handleChannelMessage(msg)\n }\n }\n } catch (error) {\n console.error(\"Failed to decode wire message:\", error)\n }\n }\n\n /**\n * Handle a decoded channel message.\n *\n * Delivers messages synchronously. The Synchronizer's receive queue\n * handles recursion prevention by queuing messages and processing\n * them iteratively.\n */\n #handleChannelMessage(msg: ChannelMsg): void {\n if (!this.#channel) {\n console.error(\"Cannot handle message: channel not set\")\n return\n }\n\n // Deliver synchronously — the Synchronizer's receive queue prevents recursion\n this.#channel.onReceive(msg)\n }\n\n /**\n * Handle keepalive ping/pong messages.\n */\n #handleKeepalive(text: string): void {\n if (text === \"ping\") {\n this.#socket.send(\"pong\")\n }\n // Ignore \"pong\" and \"ready\" responses\n }\n}\n","// service-client — service-to-service WebSocket client factory.\n//\n// Extracted from client-transport.ts so that the service client factory\n// lives in the `./server` entry point (where it belongs) rather than\n// the `./browser` entry point. Backend code imports from `./server`;\n// browser code imports from `./browser`.\n\nimport type { TransportFactory } from \"@kyneta/transport\"\nimport {\n WebsocketClientTransport,\n type WebsocketClientOptions,\n} from \"./client-transport.js\"\n\n/**\n * Options for service-to-service Websocket connections.\n *\n * Identical to `WebsocketClientOptions` — the `headers` field is always\n * available on the base options. This alias exists for API clarity:\n * importing `ServiceWebsocketClientOptions` from `./server` signals\n * intent and pairs with `createServiceWebsocketClient`.\n */\nexport type ServiceWebsocketClientOptions = WebsocketClientOptions\n\n/**\n * Create a Websocket client transport for service-to-service connections.\n *\n * This factory is for backend environments (Bun, Node.js) where you need\n * to pass authentication headers during the Websocket upgrade.\n *\n * Note: Headers are a Bun/Node-specific extension. The browser WebSocket API\n * does not support custom headers. For browser clients, use\n * `createWebsocketClient()` and authenticate via URL query parameters.\n *\n * @example\n * ```typescript\n * import { createServiceWebsocketClient } from \"@kyneta/websocket-transport/server\"\n *\n * const exchange = new Exchange({\n * transports: [createServiceWebsocketClient({\n * url: \"ws://primary-server:3000/ws\",\n * WebSocket,\n * headers: { Authorization: \"Bearer token\" },\n * reconnect: { enabled: true },\n * })],\n * })\n * ```\n */\nexport function createServiceWebsocketClient(\n options: ServiceWebsocketClientOptions,\n): TransportFactory {\n return () => new WebsocketClientTransport(options)\n}"],"mappings":";;;;;;;;AA+BA,SAAS,iBAAiB;;;AClB1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQA,IAAM,6BAA6B,MAAM;AAuBzC,IAAM,sBAAN,MAA0B;AAAA,EACtB;AAAA,EACA;AAAA,EAET;AAAA,EACA,WAA2B;AAAA,EAC3B,WAAW;AAAA;AAAA,EAGF;AAAA,EACA;AAAA,EAET,YACE,QACA,WACA,QACA,QACA;AACA,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,UAAU;AACf,SAAK,qBACH,QAAQ,qBAAqB;AAC/B,SAAK,eAAe,IAAI,oBAAoB;AAAA,MAC1C,WAAW;AAAA,MACX,WAAW,CAAC,YAAoB;AAC9B,gBAAQ;AAAA,UACN,mDAAmD,OAAO;AAAA,QAC5D;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,YAAY,SAAwB;AAClC,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,QAAc;AACZ,QAAI,KAAK,UAAU;AACjB;AAAA,IACF;AACA,SAAK,WAAW;AAEhB,SAAK,QAAQ,UAAU,UAAQ;AAC7B,WAAK,eAAe,IAAI;AAAA,IAC1B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAK,KAAuB;AAC1B,QAAI,KAAK,QAAQ,eAAe,QAAQ;AACtC;AAAA,IACF;AAEA;AAAA,MAAoB;AAAA,MAAK,KAAK;AAAA,MAAoB,UAChD,KAAK,QAAQ,KAAK,IAA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AAA,IACF;AACA,eAAW,YAAY,OAAO;AAG9B,SAAK,aAAa,IAAI,QAAQ,UAAU;AAGxC,WAAO,QAAQ,CAAC,OAAO,YAAY;AACjC,WAAK,qBAAqB,MAAM;AAAA,IAClC,CAAC;AAED,WAAO,QAAQ,YAAU;AACvB,WAAK,qBAAqB,MAAM;AAAA,IAClC,CAAC;AAED,WAAO;AAAA,MACL;AAAA,MACA,OAAO,MAAM;AACX,mBAAW,MAAM;AAIjB,mBAAW,UAAU;AAAA,MAUvB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc,QAAiD;AAC7D,WAAO,KAAK,aAAa,IAAI,MAAM;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,oBAA2C;AACzC,WAAO,MAAM,KAAK,KAAK,aAAa,OAAO,CAAC;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKA,YAAY,QAAyB;AACnC,WAAO,KAAK,aAAa,IAAI,MAAM;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,qBAAqB,QAAsB;AACzC,UAAM,aAAa,KAAK,aAAa,IAAI,MAAM;AAC/C,QAAI,YAAY;AACd,WAAK,cAAc,WAAW,SAAS;AACvC,WAAK,aAAa,OAAO,MAAM;AAAA,IACjC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU,KAAuB;AAC/B,eAAW,cAAc,KAAK,aAAa,OAAO,GAAG;AACnD,iBAAW,KAAK,GAAG;AAAA,IACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,kBAA0B;AAC5B,WAAO,KAAK,aAAa;AAAA,EAC3B;AACF;;;AExOO,SAAS,6BACd,SACkB;AAClB,SAAO,MAAM,IAAI,yBAAyB,OAAO;AACnD;","names":[]}
|
|
1
|
+
{"version":3,"file":"server.js","names":["#fragmentThreshold","#reassembler","#socket","#channel","#started","#handleMessage","#handleKeepalive","#handleChannelMessage","#fragmentThreshold","#connections"],"sources":["../src/connection.ts","../src/server-transport.ts","../src/service-client.ts"],"sourcesContent":["// connection — WebsocketConnection for server-side peer connections.\n//\n// Wraps a Socket + CBOR codec + FragmentReassembler to provide\n// send/receive for ChannelMsg over a single Websocket connection.\n//\n// Used by WebsocketServerTransport to manage individual client connections.\n// The client adapter handles its own encoding/decoding inline since it\n// manages a single socket with reconnection logic.\n//\n// Ported from @loro-extended/adapter-websocket's WsConnection with\n// kyneta naming conventions and the kyneta wire format.\n\nimport type { Channel, ChannelMsg, PeerId } from \"@kyneta/transport\"\nimport {\n decodeBinaryMessages,\n encodeBinaryAndSend,\n FragmentReassembler,\n} from \"@kyneta/wire\"\nimport type { Socket } from \"./types.js\"\n\n/**\n * Default fragment threshold in bytes.\n * Messages larger than this are fragmented for cloud infrastructure compatibility.\n * AWS API Gateway has a 128KB limit, so 100KB provides a safe margin.\n */\nexport const DEFAULT_FRAGMENT_THRESHOLD = 100 * 1024\n\n/**\n * Configuration for creating a WebsocketConnection.\n */\nexport interface WebsocketConnectionConfig {\n /**\n * Fragment threshold in bytes. Messages larger than this are fragmented.\n * Set to 0 to disable fragmentation (not recommended for cloud deployments).\n * Default: 100KB (safe for AWS API Gateway's 128KB limit)\n */\n fragmentThreshold?: number\n}\n\n/**\n * Represents a single Websocket connection to a peer (server-side).\n *\n * Manages encoding, framing, fragmentation, and reassembly for one\n * connected client. Created by `WebsocketServerTransport.handleConnection()`.\n *\n * The connection uses the CBOR codec for binary transport — this is\n * the natural choice for Websocket's binary frame support.\n */\nexport class WebsocketConnection {\n readonly peerId: PeerId\n readonly channelId: number\n\n #socket: Socket\n #channel: Channel | null = null\n #started = false\n\n // Fragmentation support\n readonly #fragmentThreshold: number\n readonly #reassembler: FragmentReassembler\n\n constructor(\n peerId: PeerId,\n channelId: number,\n socket: Socket,\n config?: WebsocketConnectionConfig,\n ) {\n this.peerId = peerId\n this.channelId = channelId\n this.#socket = socket\n this.#fragmentThreshold =\n config?.fragmentThreshold ?? DEFAULT_FRAGMENT_THRESHOLD\n this.#reassembler = new FragmentReassembler({\n timeoutMs: 10_000,\n onTimeout: (frameId: string) => {\n console.warn(\n `[WebsocketConnection] Fragment batch timed out: ${frameId}`,\n )\n },\n })\n }\n\n // ==========================================================================\n // INTERNAL API — for adapter use\n // ==========================================================================\n\n /**\n * Set the channel reference.\n * Called by the adapter when the channel is created.\n * @internal\n */\n _setChannel(channel: Channel): void {\n this.#channel = channel\n }\n\n // ==========================================================================\n // PUBLIC API\n // ==========================================================================\n\n /**\n * Start processing messages on this connection.\n *\n * Sets up the message handler on the socket. Must be called after\n * the connection is fully set up (channel assigned, stored in adapter).\n */\n start(): void {\n if (this.#started) {\n return\n }\n this.#started = true\n\n this.#socket.onMessage(data => {\n this.#handleMessage(data)\n })\n }\n\n /**\n * Send a ChannelMsg through the Websocket.\n *\n * Encodes via CBOR codec → frame → fragment if needed → socket.send().\n */\n send(msg: ChannelMsg): void {\n if (this.#socket.readyState !== \"open\") {\n return\n }\n\n encodeBinaryAndSend(msg, this.#fragmentThreshold, data =>\n this.#socket.send(data),\n )\n }\n\n /**\n * Send a \"ready\" signal to the client.\n *\n * This is a transport-level text message that tells the client the\n * server is ready to receive protocol messages. The client creates\n * its channel and sends establish after receiving this.\n */\n sendReady(): void {\n if (this.#socket.readyState !== \"open\") {\n return\n }\n this.#socket.send(\"ready\")\n }\n\n /**\n * Close the connection and clean up resources.\n */\n close(code?: number, reason?: string): void {\n this.#reassembler.dispose()\n this.#socket.close(code, reason)\n }\n\n // ==========================================================================\n // INTERNAL — message handling\n // ==========================================================================\n\n /**\n * Handle an incoming message from the Websocket.\n */\n #handleMessage(data: Uint8Array | string): void {\n // Handle keepalive ping/pong (text frames)\n if (typeof data === \"string\") {\n this.#handleKeepalive(data)\n return\n }\n\n // Handle binary protocol messages through shared decode pipeline\n try {\n const messages = decodeBinaryMessages(data, this.#reassembler)\n if (messages) {\n for (const msg of messages) {\n this.#handleChannelMessage(msg)\n }\n }\n } catch (error) {\n console.error(\"Failed to decode wire message:\", error)\n }\n }\n\n /**\n * Handle a decoded channel message.\n *\n * Delivers messages synchronously. The Synchronizer's receive queue\n * handles recursion prevention by queuing messages and processing\n * them iteratively.\n */\n #handleChannelMessage(msg: ChannelMsg): void {\n if (!this.#channel) {\n console.error(\"Cannot handle message: channel not set\")\n return\n }\n\n // Deliver synchronously — the Synchronizer's receive queue prevents recursion\n this.#channel.onReceive(msg)\n }\n\n /**\n * Handle keepalive ping/pong messages.\n */\n #handleKeepalive(text: string): void {\n if (text === \"ping\") {\n this.#socket.send(\"pong\")\n }\n // Ignore \"pong\" and \"ready\" responses\n }\n}\n","// server-adapter — Websocket server adapter for @kyneta/exchange.\n//\n// Manages Websocket connections from clients, encoding/decoding via the\n// kyneta wire format. Framework-agnostic — works with any Websocket\n// library through the Socket interface.\n//\n// Usage with Bun:\n// import { WebsocketServerTransport } from \"@kyneta/websocket-transport/server\"\n// import { createBunWebsocketHandlers } from \"@kyneta/websocket-transport/bun\"\n//\n// const serverAdapter = new WebsocketServerTransport()\n// Bun.serve({\n// websocket: createBunWebsocketHandlers(serverAdapter),\n// fetch(req, server) { server.upgrade(req); return new Response(\"\", { status: 101 }) },\n// })\n//\n// Usage with Node.js `ws`:\n// import { WebsocketServerTransport, wrapNodeWebsocket } from \"@kyneta/websocket-transport/server\"\n// import { WebSocketServer } from \"ws\"\n//\n// const serverAdapter = new WebsocketServerTransport()\n// const wss = new WebSocketServer({ server })\n// wss.on(\"connection\", (ws) => {\n// const { start } = serverAdapter.handleConnection({ socket: wrapNodeWebsocket(ws) })\n// start()\n// })\n//\n// Ported from @loro-extended/adapter-websocket's WsServerNetworkAdapter with\n// kyneta naming conventions and the kyneta 5-message protocol.\n\nimport type { ChannelMsg, GeneratedChannel, PeerId } from \"@kyneta/transport\"\nimport { Transport } from \"@kyneta/transport\"\nimport {\n DEFAULT_FRAGMENT_THRESHOLD,\n WebsocketConnection,\n} from \"./connection.js\"\nimport type {\n WebsocketConnectionOptions,\n WebsocketConnectionResult,\n} from \"./types.js\"\n\n// ---------------------------------------------------------------------------\n// Options\n// ---------------------------------------------------------------------------\n\n/**\n * Options for the Websocket server adapter.\n */\nexport interface WebsocketServerTransportOptions {\n /**\n * Fragment threshold in bytes. Messages larger than this are fragmented.\n * Set to 0 to disable fragmentation (not recommended for cloud deployments).\n * Default: 100KB (safe for AWS API Gateway's 128KB limit)\n */\n fragmentThreshold?: number\n}\n\n// ---------------------------------------------------------------------------\n// Peer ID generation\n// ---------------------------------------------------------------------------\n\n/**\n * Generate a random peer ID for connections that don't provide one.\n */\nfunction generatePeerId(): PeerId {\n const chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"\n let result = \"ws-\"\n for (let i = 0; i < 12; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length))\n }\n return result\n}\n\n// ---------------------------------------------------------------------------\n// WebsocketServerTransport\n// ---------------------------------------------------------------------------\n\n/**\n * Websocket server network adapter.\n *\n * Framework-agnostic — works with any Websocket library through the\n * `Socket` interface. Use `handleConnection()` to integrate with your\n * framework's Websocket upgrade handler.\n *\n * Each client connection is tracked as a `WebsocketConnection` keyed\n * by peer ID. The adapter creates a channel per connection and routes\n * outbound messages through the connection's send method.\n *\n * The connection handshake follows a two-phase protocol:\n * 1. Server sends text `\"ready\"` signal (transport-level)\n * 2. Client sends `establish` (protocol-level)\n * 3. Server upgrades channel and sends present (handled by Synchronizer)\n *\n * The server does NOT call `establishChannel()` — it waits for the\n * client's establish to avoid a race condition where the binary\n * establish could arrive before the client has processed \"ready\".\n */\nexport class WebsocketServerTransport extends Transport<PeerId> {\n #connections = new Map<PeerId, WebsocketConnection>()\n readonly #fragmentThreshold: number\n\n constructor(options?: WebsocketServerTransportOptions) {\n super({ transportType: \"websocket-server\" })\n this.#fragmentThreshold =\n options?.fragmentThreshold ?? DEFAULT_FRAGMENT_THRESHOLD\n }\n\n // ==========================================================================\n // Adapter abstract method implementations\n // ==========================================================================\n\n protected generate(peerId: PeerId): GeneratedChannel {\n return {\n transportType: this.transportType,\n send: (msg: ChannelMsg) => {\n const connection = this.#connections.get(peerId)\n if (connection) {\n connection.send(msg)\n }\n },\n stop: () => {\n this.unregisterConnection(peerId)\n },\n }\n }\n\n async onStart(): Promise<void> {\n // Server adapter starts passively — connections arrive via handleConnection()\n }\n\n async onStop(): Promise<void> {\n // Disconnect all active connections\n for (const connection of this.#connections.values()) {\n connection.close(1001, \"Server shutting down\")\n }\n this.#connections.clear()\n }\n\n // ==========================================================================\n // Connection management\n // ==========================================================================\n\n /**\n * Handle a new Websocket connection.\n *\n * Call this from your framework's Websocket upgrade handler.\n * Returns a connection handle and a `start()` function that begins\n * message processing and sends the \"ready\" signal.\n *\n * @param options - Connection options including the Socket and optional peer ID\n * @returns A connection handle and start function\n *\n * @example Bun\n * ```typescript\n * const { start } = serverAdapter.handleConnection({\n * socket: wrapBunWebsocket(ws),\n * })\n * start()\n * ```\n *\n * @example Node.js ws\n * ```typescript\n * wss.on(\"connection\", (ws) => {\n * const { start } = serverAdapter.handleConnection({\n * socket: wrapNodeWebsocket(ws),\n * })\n * start()\n * })\n * ```\n */\n handleConnection(\n options: WebsocketConnectionOptions,\n ): WebsocketConnectionResult {\n const { socket, peerId: providedPeerId } = options\n\n // Generate peer ID if not provided\n const peerId = providedPeerId ?? generatePeerId()\n\n // Check for existing connection with same peer ID\n const existingConnection = this.#connections.get(peerId)\n if (existingConnection) {\n existingConnection.close(1000, \"Replaced by new connection\")\n this.unregisterConnection(peerId)\n }\n\n // Create channel for this peer\n const channel = this.addChannel(peerId)\n\n // Create connection object with fragmentation config\n const connection = new WebsocketConnection(\n peerId,\n channel.channelId,\n socket,\n {\n fragmentThreshold: this.#fragmentThreshold,\n },\n )\n connection._setChannel(channel)\n\n // Store connection\n this.#connections.set(peerId, connection)\n\n // Set up close handler\n socket.onClose((_code, _reason) => {\n this.unregisterConnection(peerId)\n })\n\n socket.onError(_error => {\n this.unregisterConnection(peerId)\n })\n\n return {\n connection,\n start: () => {\n connection.start()\n\n // Send ready signal to client so it knows the server is ready\n // This is a transport-level signal, separate from protocol-level establishment\n connection.sendReady()\n\n // NOTE: We do NOT call establishChannel() here.\n // The client will send establish after receiving \"ready\".\n // Our channel gets established when the Synchronizer receives\n // and processes that establish message.\n //\n // This prevents a race condition where our binary establish\n // could arrive before the client has processed \"ready\" and created\n // its channel.\n },\n }\n }\n\n /**\n * Get an active connection by peer ID.\n */\n getConnection(peerId: PeerId): WebsocketConnection | undefined {\n return this.#connections.get(peerId)\n }\n\n /**\n * Get all active connections.\n */\n getAllConnections(): WebsocketConnection[] {\n return Array.from(this.#connections.values())\n }\n\n /**\n * Check if a peer is connected.\n */\n isConnected(peerId: PeerId): boolean {\n return this.#connections.has(peerId)\n }\n\n /**\n * Unregister a connection, removing its channel and cleaning up state.\n */\n unregisterConnection(peerId: PeerId): void {\n const connection = this.#connections.get(peerId)\n if (connection) {\n this.removeChannel(connection.channelId)\n this.#connections.delete(peerId)\n }\n }\n\n /**\n * Broadcast a message to all connected peers.\n */\n broadcast(msg: ChannelMsg): void {\n for (const connection of this.#connections.values()) {\n connection.send(msg)\n }\n }\n\n /**\n * Get the number of connected peers.\n */\n get connectionCount(): number {\n return this.#connections.size\n }\n}\n","// service-client — service-to-service WebSocket client factory.\n//\n// Extracted from client-transport.ts so that the service client factory\n// lives in the `./server` entry point (where it belongs) rather than\n// the `./browser` entry point. Backend code imports from `./server`;\n// browser code imports from `./browser`.\n\nimport type { TransportFactory } from \"@kyneta/transport\"\nimport {\n type WebsocketClientOptions,\n WebsocketClientTransport,\n} from \"./client-transport.js\"\n\n/**\n * Options for service-to-service Websocket connections.\n *\n * Identical to `WebsocketClientOptions` — the `headers` field is always\n * available on the base options. This alias exists for API clarity:\n * importing `ServiceWebsocketClientOptions` from `./server` signals\n * intent and pairs with `createServiceWebsocketClient`.\n */\nexport type ServiceWebsocketClientOptions = WebsocketClientOptions\n\n/**\n * Create a Websocket client transport for service-to-service connections.\n *\n * This factory is for backend environments (Bun, Node.js) where you need\n * to pass authentication headers during the Websocket upgrade.\n *\n * Note: Headers are a Bun/Node-specific extension. The browser WebSocket API\n * does not support custom headers. For browser clients, use\n * `createWebsocketClient()` and authenticate via URL query parameters.\n *\n * @example\n * ```typescript\n * import { createServiceWebsocketClient } from \"@kyneta/websocket-transport/server\"\n *\n * const exchange = new Exchange({\n * transports: [createServiceWebsocketClient({\n * url: \"ws://primary-server:3000/ws\",\n * WebSocket,\n * headers: { Authorization: \"Bearer token\" },\n * reconnect: { enabled: true },\n * })],\n * })\n * ```\n */\nexport function createServiceWebsocketClient(\n options: ServiceWebsocketClientOptions,\n): TransportFactory {\n return () => new WebsocketClientTransport(options)\n}\n"],"mappings":";;;;;;;;;AAyBA,MAAa,6BAA6B,MAAM;;;;;;;;;;AAuBhD,IAAa,sBAAb,MAAiC;CAC/B;CACA;CAEA;CACA,WAA2B;CAC3B,WAAW;CAGX;CACA;CAEA,YACE,QACA,WACA,QACA,QACA;AACA,OAAK,SAAS;AACd,OAAK,YAAY;AACjB,QAAA,SAAe;AACf,QAAA,oBACE,QAAQ,qBAAA;AACV,QAAA,cAAoB,IAAI,oBAAoB;GAC1C,WAAW;GACX,YAAY,YAAoB;AAC9B,YAAQ,KACN,mDAAmD,UACpD;;GAEJ,CAAC;;;;;;;CAYJ,YAAY,SAAwB;AAClC,QAAA,UAAgB;;;;;;;;CAalB,QAAc;AACZ,MAAI,MAAA,QACF;AAEF,QAAA,UAAgB;AAEhB,QAAA,OAAa,WAAU,SAAQ;AAC7B,SAAA,cAAoB,KAAK;IACzB;;;;;;;CAQJ,KAAK,KAAuB;AAC1B,MAAI,MAAA,OAAa,eAAe,OAC9B;AAGF,sBAAoB,KAAK,MAAA,oBAAyB,SAChD,MAAA,OAAa,KAAK,KAAK,CACxB;;;;;;;;;CAUH,YAAkB;AAChB,MAAI,MAAA,OAAa,eAAe,OAC9B;AAEF,QAAA,OAAa,KAAK,QAAQ;;;;;CAM5B,MAAM,MA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AAI,yBAAyB,QAAQ"}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PeerId, StateTransition, TransitionListener } from "@kyneta/transport";
|
|
2
2
|
|
|
3
|
+
//#region src/types.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* WebSocket readyState constants per the WHATWG WebSocket spec.
|
|
5
6
|
* Replaces references to `WebSocket.CONNECTING`, `WebSocket.OPEN`, etc.
|
|
6
7
|
* so that shared code never depends on the browser global.
|
|
7
8
|
*/
|
|
8
9
|
declare const READY_STATE: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
readonly CONNECTING: 0;
|
|
11
|
+
readonly OPEN: 1;
|
|
12
|
+
readonly CLOSING: 2;
|
|
13
|
+
readonly CLOSED: 3;
|
|
13
14
|
};
|
|
14
15
|
/** Minimal message event — only the fields the transport accesses. */
|
|
15
16
|
interface WebSocketMessageEvent {
|
|
16
|
-
|
|
17
|
+
readonly data: string | ArrayBuffer;
|
|
17
18
|
}
|
|
18
19
|
/** Minimal close event — only the fields the transport accesses. */
|
|
19
20
|
interface WebSocketCloseEvent {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
readonly code: number;
|
|
22
|
+
readonly reason: string;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* Structural type for a constructed WebSocket instance.
|
|
@@ -32,12 +33,12 @@ interface WebSocketCloseEvent {
|
|
|
32
33
|
* `Socket` interface (which uses single-callback registration).
|
|
33
34
|
*/
|
|
34
35
|
interface WebSocketLike {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
readonly readyState: number;
|
|
37
|
+
binaryType: string;
|
|
38
|
+
send(data: string | ArrayBuffer): void;
|
|
39
|
+
close(code?: number, reason?: string): void;
|
|
40
|
+
addEventListener(type: string, listener: (event: any) => void): void;
|
|
41
|
+
removeEventListener(type: string, listener: (event: any) => void): void;
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
43
44
|
* Structural type for a WebSocket constructor.
|
|
@@ -65,67 +66,67 @@ type SocketReadyState = "connecting" | "open" | "closing" | "closed";
|
|
|
65
66
|
* adapter needs are exposed.
|
|
66
67
|
*/
|
|
67
68
|
interface Socket {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
69
|
+
/** Send binary or text data through the Websocket. */
|
|
70
|
+
send(data: Uint8Array | string): void;
|
|
71
|
+
/** Close the Websocket connection. */
|
|
72
|
+
close(code?: number, reason?: string): void;
|
|
73
|
+
/** Register a handler for incoming messages (binary or text). */
|
|
74
|
+
onMessage(handler: (data: Uint8Array | string) => void): void;
|
|
75
|
+
/** Register a handler for connection close. */
|
|
76
|
+
onClose(handler: (code: number, reason: string) => void): void;
|
|
77
|
+
/** Register a handler for errors. */
|
|
78
|
+
onError(handler: (error: Error) => void): void;
|
|
79
|
+
/** The current ready state of the Websocket. */
|
|
80
|
+
readonly readyState: SocketReadyState;
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
83
|
* Options for handling a new Websocket connection on the server.
|
|
83
84
|
*/
|
|
84
85
|
interface WebsocketConnectionOptions {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
/** The Websocket instance, wrapped in the Socket interface. */
|
|
87
|
+
socket: Socket;
|
|
88
|
+
/** Optional peer ID extracted from the upgrade request. */
|
|
89
|
+
peerId?: PeerId;
|
|
90
|
+
/** Optional authentication token from the upgrade request. */
|
|
91
|
+
authToken?: string;
|
|
91
92
|
}
|
|
92
93
|
/**
|
|
93
94
|
* Handle for an active Websocket connection.
|
|
94
95
|
*/
|
|
95
96
|
interface WebsocketConnectionHandle {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
/** The peer ID for this connection. */
|
|
98
|
+
readonly peerId: PeerId;
|
|
99
|
+
/** The channel ID for this connection. */
|
|
100
|
+
readonly channelId: number;
|
|
101
|
+
/** Close the connection. */
|
|
102
|
+
close(code?: number, reason?: string): void;
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Result of handling a Websocket connection on the server.
|
|
105
106
|
*/
|
|
106
107
|
interface WebsocketConnectionResult {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
/** The connection handle for managing this peer. */
|
|
109
|
+
connection: WebsocketConnectionHandle;
|
|
110
|
+
/** Call this to start processing messages. */
|
|
111
|
+
start(): void;
|
|
111
112
|
}
|
|
112
113
|
/**
|
|
113
114
|
* Discriminated union describing why a Websocket connection was lost.
|
|
114
115
|
*/
|
|
115
116
|
type DisconnectReason = {
|
|
116
|
-
|
|
117
|
+
type: "intentional";
|
|
117
118
|
} | {
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
type: "error";
|
|
120
|
+
error: Error;
|
|
120
121
|
} | {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
type: "closed";
|
|
123
|
+
code: number;
|
|
124
|
+
reason: string;
|
|
124
125
|
} | {
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
type: "max-retries-exceeded";
|
|
127
|
+
attempts: number;
|
|
127
128
|
} | {
|
|
128
|
-
|
|
129
|
+
type: "not-started";
|
|
129
130
|
};
|
|
130
131
|
/**
|
|
131
132
|
* All possible states of the Websocket client.
|
|
@@ -142,19 +143,19 @@ type DisconnectReason = {
|
|
|
142
143
|
* ```
|
|
143
144
|
*/
|
|
144
145
|
type WebsocketClientState = {
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
status: "disconnected";
|
|
147
|
+
reason?: DisconnectReason;
|
|
147
148
|
} | {
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
status: "connecting";
|
|
150
|
+
attempt: number;
|
|
150
151
|
} | {
|
|
151
|
-
|
|
152
|
+
status: "connected";
|
|
152
153
|
} | {
|
|
153
|
-
|
|
154
|
+
status: "ready";
|
|
154
155
|
} | {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
status: "reconnecting";
|
|
157
|
+
attempt: number;
|
|
158
|
+
nextAttemptMs: number;
|
|
158
159
|
};
|
|
159
160
|
/**
|
|
160
161
|
* A state transition event for websocket client states.
|
|
@@ -165,7 +166,7 @@ type WebsocketClientStateTransition = StateTransition<WebsocketClientState>;
|
|
|
165
166
|
* Listener for websocket client state transitions.
|
|
166
167
|
* Specialized from the generic `TransitionListener<S>`.
|
|
167
168
|
*/
|
|
168
|
-
type TransitionListener = TransitionListener
|
|
169
|
+
type TransitionListener$1 = TransitionListener<WebsocketClientState>;
|
|
169
170
|
/**
|
|
170
171
|
* Wrap a standard `WebSocket` (browser or Node.js `ws` via `ws` package
|
|
171
172
|
* in `WebSocket`-compatible mode) into the `Socket` interface.
|
|
@@ -180,12 +181,12 @@ declare function wrapStandardWebsocket(ws: WebSocket): Socket;
|
|
|
180
181
|
* the actual `ws` instance, we just need these methods.
|
|
181
182
|
*/
|
|
182
183
|
interface NodeWebsocketLike {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
send(data: Uint8Array | string): void;
|
|
185
|
+
close(code?: number, reason?: string): void;
|
|
186
|
+
on(event: "message", handler: (data: Buffer | ArrayBuffer | string, isBinary: boolean) => void): void;
|
|
187
|
+
on(event: "close", handler: (code: number, reason: Buffer) => void): void;
|
|
188
|
+
on(event: "error", handler: (error: Error) => void): void;
|
|
189
|
+
readyState: number;
|
|
189
190
|
}
|
|
190
191
|
/**
|
|
191
192
|
* Wrap a Node.js `ws` library WebSocket into the `Socket` interface.
|
|
@@ -193,5 +194,6 @@ interface NodeWebsocketLike {
|
|
|
193
194
|
* Handles `Buffer` → `Uint8Array` conversion for binary messages.
|
|
194
195
|
*/
|
|
195
196
|
declare function wrapNodeWebsocket(ws: NodeWebsocketLike): Socket;
|
|
196
|
-
|
|
197
|
-
export {
|
|
197
|
+
//#endregion
|
|
198
|
+
export { wrapStandardWebsocket as _, SocketReadyState as a, WebSocketConstructor as c, WebsocketClientState as d, WebsocketClientStateTransition as f, wrapNodeWebsocket as g, WebsocketConnectionResult as h, Socket as i, WebSocketLike as l, WebsocketConnectionOptions as m, NodeWebsocketLike as n, TransitionListener$1 as o, WebsocketConnectionHandle as p, READY_STATE as r, WebSocketCloseEvent as s, DisconnectReason as t, WebSocketMessageEvent as u };
|
|
199
|
+
//# sourceMappingURL=types-CJAcr1Df.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CJAcr1Df.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;AAyBA;;;cAAa,WAAA;EAAA;;;;;;UAYI,qBAAA;EAAA,SACN,IAAA,WAAe,WAAA;AAAA;;UAIT,mBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;AAAA;;;AAkBX;;;;;;;;;UAAiB,aAAA;EAAA,SACN,UAAA;EACT,UAAA;EACA,IAAA,CAAK,IAAA,WAAe,WAAA;EACpB,KAAA,CAAM,IAAA,WAAe,MAAA;EACrB,gBAAA,CAAiB,IAAA,UAAc,QAAA,GAAW,KAAA;EAC1C,mBAAA,CAAoB,IAAA,UAAc,QAAA,GAAW,KAAA;AAAA;;;;;;AAW/C;;;KAAY,oBAAA,QACV,GAAA,aACG,IAAA,YACA,aAAA;;;;;KAUO,gBAAA;AAAZ;;;;;AAiBA;;;;;;AAjBA,UAiBiB,MAAA;EAiBsB;EAfrC,IAAA,CAAK,IAAA,EAAM,UAAA;EAAX;EAGA,KAAA,CAAM,IAAA,WAAe,MAAA;EAHhB;EAML,SAAA,CAAU,OAAA,GAAU,IAAA,EAAM,UAAA;EAHpB;EAMN,OA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AAA;EACnD,EAAA,CAAG,KAAA,WAAgB,OAAA,GAAU,KAAA,EAAO,KAAA;EACpC,UAAA;AAAA;;;;;;iBAQc,iBAAA,CAAkB,EAAA,EAAI,iBAAA,GAAoB,MAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyneta/websocket-transport",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Websocket network adapter for @kyneta/exchange — browser, server, and Bun integration",
|
|
5
5
|
"author": "Duane Johnson",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,24 +33,24 @@
|
|
|
33
33
|
"./src/*": "./src/*"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@kyneta/
|
|
37
|
-
"@kyneta/
|
|
38
|
-
"@kyneta/wire": "^1.
|
|
36
|
+
"@kyneta/machine": "^1.4.0",
|
|
37
|
+
"@kyneta/transport": "^1.4.0",
|
|
38
|
+
"@kyneta/wire": "^1.4.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^22",
|
|
42
42
|
"bun-types": "latest",
|
|
43
|
-
"
|
|
43
|
+
"tsdown": "^0.21.9",
|
|
44
44
|
"typescript": "^5.9.2",
|
|
45
45
|
"vitest": "^4.0.17",
|
|
46
|
-
"@kyneta/exchange": "^1.
|
|
47
|
-
"@kyneta/
|
|
48
|
-
"@kyneta/
|
|
49
|
-
"@kyneta/
|
|
50
|
-
"@kyneta/
|
|
46
|
+
"@kyneta/exchange": "^1.4.0",
|
|
47
|
+
"@kyneta/schema": "^1.4.0",
|
|
48
|
+
"@kyneta/transport": "^1.4.0",
|
|
49
|
+
"@kyneta/wire": "^1.4.0",
|
|
50
|
+
"@kyneta/machine": "^1.4.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"build": "
|
|
53
|
+
"build": "tsdown",
|
|
54
54
|
"test": "verify logic",
|
|
55
55
|
"verify": "verify"
|
|
56
56
|
}
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
// 2. When `headers` are provided, they're passed as `{ headers }` in the
|
|
7
7
|
// second argument. When absent, the constructor is called with just the URL.
|
|
8
8
|
|
|
9
|
+
import type { PeerIdentityDetails, TransportContext } from "@kyneta/transport"
|
|
9
10
|
import { describe, expect, it, vi } from "vitest"
|
|
10
|
-
import type { TransportContext } from "@kyneta/transport"
|
|
11
|
-
import type { PeerIdentityDetails } from "@kyneta/transport"
|
|
12
11
|
import { WebsocketClientTransport } from "../client-transport.js"
|
|
13
12
|
import type { WebSocketConstructor, WebSocketLike } from "../types.js"
|
|
14
13
|
|
|
@@ -102,7 +101,7 @@ describe("WebsocketClientTransport — constructor injection", () => {
|
|
|
102
101
|
const { MockWebSocket, calls } = createMockWebSocketClass()
|
|
103
102
|
|
|
104
103
|
const transport = new WebsocketClientTransport({
|
|
105
|
-
url:
|
|
104
|
+
url: peerId => `ws://localhost:9999/ws/${peerId}`,
|
|
106
105
|
WebSocket: MockWebSocket,
|
|
107
106
|
reconnect: { enabled: false },
|
|
108
107
|
})
|
|
@@ -165,4 +164,4 @@ describe("WebsocketClientTransport — header passing", () => {
|
|
|
165
164
|
expect(calls).toHaveLength(1)
|
|
166
165
|
expect(calls[0]!.rest).toEqual([])
|
|
167
166
|
})
|
|
168
|
-
})
|
|
167
|
+
})
|
package/src/browser.ts
CHANGED
|
@@ -37,13 +37,13 @@ export type {
|
|
|
37
37
|
DisconnectReason,
|
|
38
38
|
Socket,
|
|
39
39
|
SocketReadyState,
|
|
40
|
-
WebsocketClientState,
|
|
41
|
-
WebsocketClientStateTransition,
|
|
42
40
|
TransitionListener,
|
|
43
41
|
WebSocketCloseEvent,
|
|
44
42
|
WebSocketConstructor,
|
|
45
43
|
WebSocketLike,
|
|
46
44
|
WebSocketMessageEvent,
|
|
45
|
+
WebsocketClientState,
|
|
46
|
+
WebsocketClientStateTransition,
|
|
47
47
|
} from "./types.js"
|
|
48
48
|
|
|
49
|
-
export { READY_STATE } from "./types.js"
|
|
49
|
+
export { READY_STATE } from "./types.js"
|
package/src/client-transport.ts
CHANGED
|
@@ -31,6 +31,11 @@ import {
|
|
|
31
31
|
type WsClientEffect,
|
|
32
32
|
type WsClientMsg,
|
|
33
33
|
} from "./client-program.js"
|
|
34
|
+
import type {
|
|
35
|
+
DisconnectReason,
|
|
36
|
+
WebsocketClientState,
|
|
37
|
+
WebsocketClientStateTransition,
|
|
38
|
+
} from "./types.js"
|
|
34
39
|
import {
|
|
35
40
|
READY_STATE,
|
|
36
41
|
type WebSocketCloseEvent,
|
|
@@ -38,11 +43,6 @@ import {
|
|
|
38
43
|
type WebSocketLike,
|
|
39
44
|
type WebSocketMessageEvent,
|
|
40
45
|
} from "./types.js"
|
|
41
|
-
import type {
|
|
42
|
-
DisconnectReason,
|
|
43
|
-
WebsocketClientState,
|
|
44
|
-
WebsocketClientStateTransition,
|
|
45
|
-
} from "./types.js"
|
|
46
46
|
|
|
47
47
|
// Re-export state types for convenience
|
|
48
48
|
export type {
|
|
@@ -600,4 +600,3 @@ export function createWebsocketClient(
|
|
|
600
600
|
): TransportFactory {
|
|
601
601
|
return () => new WebsocketClientTransport(options)
|
|
602
602
|
}
|
|
603
|
-
|
package/src/connection.ts
CHANGED
|
@@ -133,7 +133,7 @@ export class WebsocketConnection {
|
|
|
133
133
|
*
|
|
134
134
|
* This is a transport-level text message that tells the client the
|
|
135
135
|
* server is ready to receive protocol messages. The client creates
|
|
136
|
-
* its channel and sends establish
|
|
136
|
+
* its channel and sends establish after receiving this.
|
|
137
137
|
*/
|
|
138
138
|
sendReady(): void {
|
|
139
139
|
if (this.#socket.readyState !== "open") {
|
package/src/server-transport.ts
CHANGED
|
@@ -88,12 +88,12 @@ function generatePeerId(): PeerId {
|
|
|
88
88
|
*
|
|
89
89
|
* The connection handshake follows a two-phase protocol:
|
|
90
90
|
* 1. Server sends text `"ready"` signal (transport-level)
|
|
91
|
-
* 2. Client sends `establish
|
|
92
|
-
* 3. Server
|
|
91
|
+
* 2. Client sends `establish` (protocol-level)
|
|
92
|
+
* 3. Server upgrades channel and sends present (handled by Synchronizer)
|
|
93
93
|
*
|
|
94
94
|
* The server does NOT call `establishChannel()` — it waits for the
|
|
95
|
-
* client's establish
|
|
96
|
-
* establish
|
|
95
|
+
* client's establish to avoid a race condition where the binary
|
|
96
|
+
* establish could arrive before the client has processed "ready".
|
|
97
97
|
*/
|
|
98
98
|
export class WebsocketServerTransport extends Transport<PeerId> {
|
|
99
99
|
#connections = new Map<PeerId, WebsocketConnection>()
|
|
@@ -219,11 +219,11 @@ export class WebsocketServerTransport extends Transport<PeerId> {
|
|
|
219
219
|
connection.sendReady()
|
|
220
220
|
|
|
221
221
|
// NOTE: We do NOT call establishChannel() here.
|
|
222
|
-
// The client will send establish
|
|
222
|
+
// The client will send establish after receiving "ready".
|
|
223
223
|
// Our channel gets established when the Synchronizer receives
|
|
224
|
-
// and processes that establish
|
|
224
|
+
// and processes that establish message.
|
|
225
225
|
//
|
|
226
|
-
// This prevents a race condition where our binary establish
|
|
226
|
+
// This prevents a race condition where our binary establish
|
|
227
227
|
// could arrive before the client has processed "ready" and created
|
|
228
228
|
// its channel.
|
|
229
229
|
},
|
package/src/server.ts
CHANGED
package/src/service-client.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import type { TransportFactory } from "@kyneta/transport"
|
|
9
9
|
import {
|
|
10
|
-
WebsocketClientTransport,
|
|
11
10
|
type WebsocketClientOptions,
|
|
11
|
+
WebsocketClientTransport,
|
|
12
12
|
} from "./client-transport.js"
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -49,4 +49,4 @@ export function createServiceWebsocketClient(
|
|
|
49
49
|
options: ServiceWebsocketClientOptions,
|
|
50
50
|
): TransportFactory {
|
|
51
51
|
return () => new WebsocketClientTransport(options)
|
|
52
|
-
}
|
|
52
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -63,7 +63,7 @@ export interface WebSocketCloseEvent {
|
|
|
63
63
|
export interface WebSocketLike {
|
|
64
64
|
readonly readyState: number
|
|
65
65
|
binaryType: string
|
|
66
|
-
send(data: string |
|
|
66
|
+
send(data: string | ArrayBuffer): void
|
|
67
67
|
close(code?: number, reason?: string): void
|
|
68
68
|
addEventListener(type: string, listener: (event: any) => void): void
|
|
69
69
|
removeEventListener(type: string, listener: (event: any) => void): void
|
package/dist/browser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|