webtransport demo
WebTransport is the new cool kid in javascript data connection town and most likely to supersede WebSockets for some scenarios. It might be good idea to create a server and addon demo for xterm.js, as it brings several advantages over WebSockets:
- UDP based: less transport overhead (but also more likely to be blocked by restricted firewalls, so might need proper fallback)
- allows real stream spanning from server to client with working flow control (sad truth about 90% of xterm.js integrations out there - they forget about proper flow control and wonder from massive agent outputs, why half of the data got truncated)
- BYOB reader capability
- multiple stream support (interesting for orchestration integrations holding multiple opened terminal sessions at once)
From UDP + BYOB reader I expect a significant throughput gain and much lower latency (it somewhat shortens the long PTY --> ... --> terminal line). The integrated flow control makes backpressure handling much more straight forward up to a point, where we might be able to get rid of our current WriteBuffer event loop stop and go handling, as we could use the promised reader interface.
I have not yet done any tests with WebTranport, if anyone has numbers I'd like to hear them.
No numbers to share yet, but two concrete data points from the current code that back the flow-control and BYOB angles:
No backpressure today, matches your point exactly. AttachAddon.activate() calls terminal.write() unconditionally on every WebSocket message event — there's no signal back to the sender at all. WriteBuffer only has a local safety net (DISCARD_WATERMARK, ~50MB) that throws and drops data past that point; it never throttles the socket. A WritableStream-backed transport whose writer exposes desiredSize/ready would let the receiving side push real backpressure upstream instead of silently discarding once the buffer is already overflowing.
BYOB would also remove a real conversion cost, not just a theoretical one. AttachAddon._sendBinary currently does:
const buffer = new Uint8Array(data.length);
for (let i = 0; i < data.length; ++i) {
buffer[i] = data.charCodeAt(i) & 255;
}
because terminal.onBinary hands back a JS string of char-codes-as-bytes rather than a Uint8Array. A BYOB reader path writing straight into a reusable buffer would skip that per-byte round trip on send, and symmetrically it'd be worth having the receive side avoid the string detour too if this becomes more than a demo.
One scope question: the issue title went from "webtransport addon" to "webtransport demo" — is a new addon (addon-attach-shaped, WebTransport instead of WebSocket) explicitly out of scope for now, or is "demo" just describing where the PoC lives first before an addon API is settled?
"demo" here means, that the demo in the repo needs changes as well, thus an addon + a demo server patch.