WebSocket protocol
Games run over Socket.IO on /ws. This page covers the player side, to build your own client, like an ESP32 buzzer. Sessions and joining go through the HTTP API.
After a disconnection:
Connect
Section titled “Connect”io("http://<host>:<port>", { path: "/ws", auth: { token } })- Get
tokenfromPOST /api/auth/session, and store it. - Refresh it with the same route before every connection. The
clientIdis kept, so is the player’s seat. - The token is only checked on connect: expiring mid-game is fine.
- Answer Socket.IO pings (every 25 s, 20 s timeout) or you get disconnected.
If the token is refused, you get connect_error with a data.code:
data.code |
Fix |
|---|---|
TOKEN_MISSING |
Get a token, reconnect. |
TOKEN_EXPIRED |
Refresh it, reconnect. |
TOKEN_INVALID |
Get a new one with an empty body, reconnect. |
Socket.IO doesn’t retry after these: call connect() yourself, with a retry limit.
Join a game
Section titled “Join a game”POST /api/games/joinwith{ inviteCode, username }and the token as bearer. Returns{ gameId, ticket, username }.emit player:login { ticket }.- Wait for
game:successJoin { gameId, username, gameMode }.
ticket: nullmeans you already have a seat: reconnect instead.game:reset <key>means the ticket or game is no longer valid: start over.- When the game generates nicknames,
usernameisnullin step 1. Read it from step 3.
Game statuses
Section titled “Game statuses”Sent with game:status { name, data }.
name |
data |
Notes |
|---|---|---|
SHOW_START |
{ time, subject } |
Countdown before the first question. |
SHOW_PREPARED |
{ totalAnswers, questionNumber, questionType } |
totalAnswers is 0 for estimation. |
SHOW_QUESTION |
{ question, media?, cooldown } |
Answers open in cooldown seconds. |
SELECT_ANSWER |
{ question, answers, media?, time, totalPlayer, questionType, options?, answersOnly } |
Answers are open. |
SHOW_RESULT |
{ correct, message, points, myPoints, rank, aheadOfMe } |
Quiz mode only. |
WAIT |
{ text } |
Waiting screen. |
FINISHED |
{ subject, top, rank? } |
End of a quiz. |
SUMMARY |
{ subject, totalPlayers, totalQuestions } |
End of a survey. |
In survey mode, SHOW_RESULT is replaced by WAIT { text: "game:answerNoted" }, and the game ends with SUMMARY. Treat SHOW_RESULT and FINISHED as optional and your client works in both modes.
Answer
Section titled “Answer”emit player:selectedAnswer { gameId, data: { answerKeys: number[] } }| Question type | answerKeys |
|---|---|
single |
The button index, from 0: [1] |
multi |
Every selected button: [0, 2] |
estimation |
The value, clamped to options.min/max: [27] |
Only accepted during SELECT_ANSWER, and only the first answer counts.
Reconnect
Section titled “Reconnect”Refresh the token, connect, then emit player:reconnect { gameId }. Store gameId with the token to survive a reboot.
- Success:
player:successReconnect { gameId, gameMode, status, player, currentQuestion }.statusis the currentgame:status. - Failure:
game:reset <key>. Join again.
Before the game starts, a disconnected player loses their seat and must join again.
emit player:leave { gameId }Before the start, the player is removed. After, they are marked disconnected and keep their seat.
Events
Section titled “Events”Client to server
| Event | Payload |
|---|---|
player:login |
{ ticket } |
player:reconnect |
{ gameId } |
player:leave |
{ gameId } |
player:selectedAnswer |
{ gameId, data: { answerKeys } } |
Server to client
| Event | Payload |
|---|---|
game:successJoin |
{ gameId, username, gameMode } |
player:successReconnect |
{ gameId, gameMode, status, player, currentQuestion } |
game:status |
{ name, data } |
game:updateQuestion |
{ current, total } |
game:totalPlayers |
count |
game:playerAnswer |
count of players who answered |
game:errorMessage |
error key |
game:reset |
error key: back to the join screen |
Error keys like errors:game.notFound are codes, not messages. Full types: socket.ts, constants.ts.
Manager events
Section titled “Manager events”Only the client that created the game with POST /api/games can send them. Others get game:errorMessage errors:auth.unauthorized.
| Event | Effect |
|---|---|
manager:startGame |
Starts the game. |
manager:advance { gameId } |
Moves to the next step, or closes open answers early. |
manager:kickPlayer |
Removes a player. |
manager:setLock { gameId, locked } |
Locks or unlocks the room. Confirmed with manager:lockUpdated. |
With auto-advance on, the manager receives manager:autoAdvance { seconds, total }, or null when the countdown is cleared.