five-on-it / packages/protocol/src/rtc
packages/protocol/src/rtc
The WebRTC data channel's signalling (TECHNICAL_SPECS §6.4, phase 2): text frames over the WebSocket that set up a channel beside it for the unreliable frames (the inputs and the snapshots), the WebSocket keeping the reliable ones and taking everything back when the channel fails. A server that offers the channel says so in its welcome (rtc); the client then offers (its SDP), the server answers, both send their ICE candidates as they find them, and either side says close when it falls back to the WebSocket (reason: why). Both ends create the same channel by its id (RTC_CHANNEL: negotiated, unordered, never retransmitted), so no in-band message opens it. No STUN server: the server's host candidates (or the address it announces) and the peer-reflexive ones its checks find are enough to reach a game server, which has a public address.