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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new NetChannel(
transport,opts?):NetChannel
Defined in: net/NetChannel.ts:60
Parameters
Section titled “Parameters”transport
Section titled “transport”NetChannelOptions = {}
Returns
Section titled “Returns”NetChannel
Methods
Section titled “Methods”dispose()
Section titled “dispose()”dispose(
reason?):void
Defined in: net/NetChannel.ts:129
Reject all in-flight requests and drop handlers (call on disconnect).
Parameters
Section titled “Parameters”reason?
Section titled “reason?”string = 'net channel closed'
Returns
Section titled “Returns”void
handle()
Section titled “handle()”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.
Type Parameters
Section titled “Type Parameters”Req = unknown
Res = unknown
Parameters
Section titled “Parameters”string
handler
Section titled “handler”RequestHandler<Req, Res>
Returns
Section titled “Returns”() => void
on<
T>(type,handler): () =>void
Defined in: net/NetChannel.ts:67
Subscribe to a typed event. Returns an unsubscribe function.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”string
handler
Section titled “handler”Returns
Section titled “Returns”() => void
onBinary()
Section titled “onBinary()”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.
Parameters
Section titled “Parameters”channel
Section titled “channel”number
handler
Section titled “handler”Returns
Section titled “Returns”() => void
request()
Section titled “request()”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).
Type Parameters
Section titled “Type Parameters”Res = unknown
Req = unknown
Parameters
Section titled “Parameters”string
payload
Section titled “payload”Req
timeoutMs?
Section titled “timeoutMs?”number
Returns
Section titled “Returns”Promise<Res>
send()
Section titled “send()”send<
T>(type,payload):void
Defined in: net/NetChannel.ts:78
Fire-and-forget a typed event to the peer.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”string
payload
Section titled “payload”T
Returns
Section titled “Returns”void
sendBinary()
Section titled “sendBinary()”sendBinary(
channel,payload):void
Defined in: net/NetChannel.ts:121
Fire-and-forget a binary payload on a channel id (0-255).
Parameters
Section titled “Parameters”channel
Section titled “channel”number
payload
Section titled “payload”Uint8Array
Returns
Section titled “Returns”void