actions/transports_ws.ts

Frontend WebSocket transport — thin adapter over WebsocketRpcConnection.

Delegates request/response correlation, the durable queue, the heartbeat, and AbortSignal-driven cancel to the underlying connection (the canonical implementation is FrontendWebsocketClient). The transport's own job is the Transport contract: route inbound server-pushed messages into peer.receive, send the resulting response back over the socket (the server→client ActionPeer receive loop), and translate the connection's Promise<R>/ThrownJsonrpcError shape into JsonrpcResponseOrError envelopes. No parallel pending-request map.

Inbound peer/ping requests are answered directly via the built-in peer_ping_responder — a protocol-liveness concern that works with zero consumer wiring, the same way the server runs the heartbeat echo.

view source

Declarations
#

3 declarations

FrontendWebsocketTransport
#

actions/transports_ws.ts view source

import {FrontendWebsocketTransport} from '@fuzdev/fuz_app/actions/transports_ws.js';

Thin adapter over WebsocketRpcConnection (canonical implementation: FrontendWebsocketClient). Routes inbound server-pushed requests and notifications into the supplied receive callback and sends the request response back over the socket; an inbound peer/ping is answered by the built-in responder before receive. Responses to requests *we* sent are owned by the connection's own request() pending map and are ignored here.

inheritance

implements: Transport

transport_name

type "frontend_websocket_rpc"

readonly

constructor

type new (connection: WebsocketRpcConnection, receive: (data: unknown) => Promise<unknown>): FrontendWebsocketTransport

connection

receive

type (data: unknown) => Promise<unknown>

send

type (message: { [x: string]: unknown; jsonrpc: "2.0"; id: string | number; method: string; params?: { [x: string]: unknown; } | undefined; }, options?: TransportSendOptions | undefined): Promise<...>

message

type { [x: string]: unknown; jsonrpc: "2.0"; id: string | number; method: string; params?: { [x: string]: unknown; } | undefined; }

options?

type TransportSendOptions | undefined
optional
returns Promise<{ [x: string]: unknown; jsonrpc: "2.0"; id: string | number; result: JSONType; } | { [x: string]: unknown; jsonrpc: "2.0"; id: string | number | null; error: { [x: string]: unknown; code: -32700 | -32600 | -32601 | -32602 | -32603 | (number & $brand<...>); message: string; data?: unknown; }; }>

is_ready

type (): boolean

returns boolean

dispose

Detach the inbound message and error handlers registered on the connection. Idempotent — subsequent calls no-op. Does not close the underlying connection (that lifecycle is owned by the caller).

type (): void

returns void

WebsocketConnection
#

actions/transports_ws.ts view source

WebsocketConnection import type {WebsocketConnection} from '@fuzdev/fuz_app/actions/transports_ws.js';

Minimal interface for a WebSocket connection, decoupled from the concrete Socket Cell.

send

type (data: object) => boolean

connected

type boolean

readonly

add_message_handler

type (handler: (event: MessageEvent) => void) => () => void

add_error_handler

type (handler: (event: Event) => void) => () => void

WebsocketRpcConnection
#

actions/transports_ws.ts view source

WebsocketRpcConnection import type {WebsocketRpcConnection} from '@fuzdev/fuz_app/actions/transports_ws.js';

RPC-capable WebSocket connection — a WebsocketConnection that also handles request/response correlation with timeout, queue, AbortSignal cancel, and explicit-id support. Required by FrontendWebsocketTransport so it can delegate the pending-map bookkeeping to one canonical implementation (FrontendWebsocketClient) instead of running a parallel one.

Consumer wrappers around FrontendWebsocketClient (e.g. zzz's Socket) implement this by adding a one-line delegate to the underlying client's request.

inheritance

request

type ( method: string, params: unknown, options?: { signal?: AbortSignal; queue?: boolean; id?: JsonrpcRequestId } ) => Promise<unknown>

Depends on
#

Imported by
#