Skip to content

five-on-it / apps/client/src/renderer/rtc

apps/client/src/renderer/rtc ​

The page's side of the WebRTC data channel (@foi/protocol's rtc.ts): withRtc wraps the WebSocket transport (net.ts) in one whose unreliable frames (the inputs) go over a data channel while one is open, everything else over the WebSocket, and which delivers what comes either way to every receiver (as the WebSocket transport does).

  • Offering. Once the welcome says the server offers the channel (RtcTransport.start; the page's ?rtc=0 refuses it), the page offers one (no STUN server: the server is reached at its own address), sends its candidates as it finds them and applies the server's answer, holding the server's candidates that come before it. When the channel opens the transport is RtcTransport.lossy and sends its unreliable frames on it.
  • Falling back. Everything goes over the WebSocket again when the channel has not opened RTC_CLIENT.connectTimeoutMs after the offer, when the connection fails or the channel closes, when nothing has come on the open channel for RTC_CLIENT.silenceMs (the server sends twenty snapshots a second; not while the room is frozen, which its pause message says), and when the server says close. The page tells the server close when it is the one to notice. It offers again only after a channel that had opened: a few seconds later, twice as long after each fall back in a row (the count forgotten once a channel stays open a minute).

The HUD says which way the frames go ("connected via udp" or "ws") and window.__poc().net shows it (RtcTransport.view).

Interfaces ​

Type Aliases ​

Variables ​

Functions ​