@statewalker/webrun-streams-port
v0.1.1
Published
MessagePort-backed Connect/Serve adapter + typed-JSON RPC primitives in the webrun-streams-* family
Readme
@statewalker/webrun-streams-port
Two layers on the same MessagePort:
Duplex/Connect/Servetier — byte streams multiplexed viaemulateMux. Use for Worker / SharedWorker / ServiceWorker comms where you want the canonicalDuplexseam.- Typed-JSON RPC tier —
callPort/listenPort/callBidi/listenBidi/ioSend/ioHandlere-exported from the legacywebrun-portspackage. Use when you want typed JSON arguments per call and don't need byte-stream semantics.
import { connect, serve } from "@statewalker/webrun-streams-port";
const channel = new MessageChannel();
const server = await serve({ port: channel.port2 }, async function* echo(input) {
for await (const chunk of input) yield chunk;
});
const { call } = await connect({ port: channel.port1 });Both take an optional side: "initiator" | "responder" — the emulateMux
stream-id allocation side. It defaults asymmetrically ("initiator" on
connect, "responder" on serve) so the ordinary pairing above needs no
configuration; set it explicitly only when both ends of a port are connects
or both are serves.
Conformance
Passes every level of @statewalker/webrun-streams-conformance against a MessageChannel pair.
License
MIT
