5 minutes
Build the Room Server
Last lesson drew the handshake: an offer goes to a signaling server, an answer comes back, and only then does a DataChannel open between two peers. But the diagram had a gap — the signaling server itself. Two browsers behind two routers can't hand each other an offer directly; something both can reach has to hold it for a moment. And before any of that, someone has to decide who sits in which chair.
That something is the smallest server in the whole course. It has two jobs — hand out seats, and act as a mailbox for SDP messages — and it never sees a card, holds no game logic, and fits in well under a hundred lines. Nothing changes on screen this lesson: you build one backend module and one dev server, and run that server next to the game.
Every function in roomStore.ts is pure: each takes one plain value, a RoomState, and returns a new one, with no Prisma, no HTTP, no globals, and no hidden clock. That is deliberate — if you can't test the seat logic on its own, you end up debugging it in four browser tabs at once.
Here are the constants and one small helper, in src/server/roomStore.ts:
Continue reading
Unlock the Full Course
Every lesson, the runnable examples, and the finished build — yours to keep.