Skip to content

NetChannel

Defined in: net/NetChannel.ts:50

Typed messaging over a NetTransport. Subscribes to the transport’s message events (it is the message router). Events are fire-and-forget; requests await a matching response by id (or reject on timeout / remote error).

Two planes share the one transport: string frames carry the JSON control envelope; binary frames carry a 1-byte channel id + payload for high-rate data (replication snapshots claim channel 1). A binary frame with no registered channel handler is dropped.

new NetChannel(transport, opts?): NetChannel

Defined in: net/NetChannel.ts:60

NetTransport

NetChannelOptions = {}

NetChannel

dispose(reason?): void

Defined in: net/NetChannel.ts:129

Reject all in-flight requests and drop handlers (call on disconnect).

string = 'net channel closed'

void


handle<Req, Res>(type, handler): () => void

Defined in: net/NetChannel.ts:84

Register the single handler that answers request(type, …) from the peer. Returns an unregister function.

Req = unknown

Res = unknown

string

RequestHandler<Req, Res>

() => void


on<T>(type, handler): () => void

Defined in: net/NetChannel.ts:67

Subscribe to a typed event. Returns an unsubscribe function.

T = unknown

string

MessageHandler<T>

() => void


onBinary(channel, handler): () => void

Defined in: net/NetChannel.ts:111

Register the single handler for a binary channel id (0-255). Returns an unregister function.

number

BinaryHandler

() => void


request<Res, Req>(type, payload, timeoutMs?): Promise<Res>

Defined in: net/NetChannel.ts:94

Send a request and await the peer’s response (rejects on timeout / remote error).

Res = unknown

Req = unknown

string

Req

number

Promise<Res>


send<T>(type, payload): void

Defined in: net/NetChannel.ts:78

Fire-and-forget a typed event to the peer.

T = unknown

string

T

void


sendBinary(channel, payload): void

Defined in: net/NetChannel.ts:121

Fire-and-forget a binary payload on a channel id (0-255).

number

Uint8Array

void