five-on-it / apps/server/src/rtc-peers
apps/server/src/rtc-peers
The RTC worker's peers (rtc-worker.ts runs them on werift; the tests on fakes): one peer connection per client offer, with its data channel.
- Caps. At most
maxPeerspeers, open or on their way: an offer past it is closed at once (full), and the client stays on its WebSocket. At mostmaxHandshakeshandshakes at once; the next offers wait their turn, in order. And one answer at a time: werift finds each peer's UDP port in the range by trying them, and two peers looking at once could pick the same one. - Timeout. A channel that has not opened
connectTimeoutMsafter its offer (waiting included) is closed (timeout); one whose connection fails or whose channel closes is closed (failed). - Candidates. The client's that come before its answer is made wait for it; the server's found while it is made go out after the answer, so the client gets the answer first. A host behind a NAT that forwards the same ports (Docker's published range) announces its public address instead of the local one (announceCandidate).
- Backlog. A channel holding more than MAX_QUEUED bytes not yet sent drops the frames sent to it (they are unreliable), and counts them.
The game thread is told of every answer, candidate, opening and closing (FromWorker); a peer it closes itself is closed without a word.