demo · v143
Sub-protocol router
The use case ALPN was added for: one WebTransport endpoint, multiple application protocols (game state, chat, telemetry). Pick the client's offered list and the server's supported list; see which protocol gets negotiated and what the dispatched code does next.
1. client offers
2. server supports
handshake
after open: code that runs
the call
const wt = new WebTransport("https://game.example/connect", {
protocols: ["game-v3", "game-v2", "chat-v1"],
});
await wt.ready;
switch (wt.protocol) {
case "game-v3": runV3StateMachine(wt); break;
case "game-v2": runV2StateMachine(wt); break;
case "chat-v1": runChat(wt); break;
}
why this angle
The other concept tests the construction. This shows the router pattern the spec authors had in mind — one endpoint, many sub-protocols, branching on wt.protocol. It's the same pattern WebSocket sub-protocols established years ago.