Real-time protocol
During a match, clients talk to Arbitas over the play WebSocket. It carries every move, each seat’s view of the match, who is connected, and quick chat. The hosted web player uses it, and so can your own client. Every message is listed in the protocol reference, which is generated from the protocol’s contract.
“Real-time” here means the connection: updates arrive as they happen. The games themselves are turn-based; real-time games, where every player acts at any moment, aren’t in platform v1 (see live and asynchronous play).
Before you connect
Section titled “Before you connect”Your client needs a signed-in player’s access token for the game, from the Player API’s sign-in
(POST /v1/auth/token, as a guest or with an emailed code), and the ID of a match the player sits in or may watch,
which they get when their lobby starts or from listMyMatches.
Connect
Section titled “Connect”The socket is at wss://play.arbitas.dev/v1/play. There are two ways to authenticate:
- With a header, from an app, a game engine or a server: send the access token as
Authorization: Bearer …on the upgrade request. - With a ticket, for browsers, which can’t set headers on a WebSocket: ask for a single-use ticket with
POST /v1/play-tickets, then open/v1/play?ticket=…within 30 seconds. The ticket opens one socket, once, so the access token never appears in a URL. The hosted web player connects this way. Web pages on other sites can’t ask for a ticket yet, because the Player API doesn’t answer them.
Either way, the socket lives as long as the access token it was opened with. When that token expires, about every 15
minutes, the server closes the socket with code 4001 (tokenExpired): refresh the token, reconnect at once, and
resume each match. Code 4003 (accountSuspended) means don’t reconnect. The server also sends WebSocket pings to
keep the connection open.
using var socket = new ClientWebSocket();socket.Options.SetRequestHeader("Authorization", $"Bearer {accessToken}");await socket.ConnectAsync(new Uri("wss://play.arbitas.dev/v1/play"), cancellationToken);var subscribe = JsonSerializer.SerializeToUtf8Bytes(new { type = "subscribe", match = matchId });await socket.SendAsync(subscribe, WebSocketMessageType.Text, true, cancellationToken);Frames
Section titled “Frames”Each frame is a JSON text message holding one object, whose type names the message. A frame may be at most 16 KiB;
the server closes the connection with 1009 on a bigger one. A frame the server doesn’t understand is answered with an
error frame with the code validationFailed, and the connection stays open.
One socket can follow several matches: every frame about a match names it in match.
Follow a match
Section titled “Follow a match”Send subscribe with the match’s ID. The server answers with:
snapshot: the match as your seat sees it. It holds the match’sversion, your seat (yourSeat, absent for a spectator), each seat, your seat’s view of the state (view), its hash (stateHash), the clocks of a timed match, the result once there is one (outcome), and, when your seat can act, the moves it may make (moves).seats: every seat’s controller and whether its player is connected. A newseatsframe replaces the last one each time a player connects or goes, a grace period starts, or a bot takes a seat over or gives it back.chattedframes for recent quick-chat phrases, if the game allows chat and you’re seated.
From then on, the server sends a delta each time the match’s log grows: a move, or a change of who drives a seat.
Each delta has the next version, the move and the seat that made it (absent for a move the platform makes, such as a
clock running out), your seat’s view after it, the new state hash, and your seat’s legal moves. Apply deltas in
version order; each one’s version is one more than the last.
Make a move
Section titled “Make a move”Send submitMove with:
move: the action and its choices, in order, as one of the legal moves the server listed;baseVersion: the version your client was looking at;clientSeq: a number of your own that identifies this move. Resending a move with the sameclientSeq, after a reconnect for example, is recognized as the same move and isn’t applied twice. The web player uses its base version plus one.
If the server applies the move, it arrives as a delta like any other. If not, you get moveRejected with your
clientSeq and a code, as the Player API’s move endpoint gives them:
| Code | Meaning |
|---|---|
staleVersion |
The match moved on since baseVersion; catch up and choose again |
notYourTurn |
Your seat can’t take that action now |
illegalMove |
The rules didn’t accept the move’s choices |
matchEnded |
The match is over |
A rejection is routine, not a failure: when another seat’s move or a bot takeover lands first, your move is stale.
Clients that can rebuild the state, because the game hides nothing, can show a move before the server confirms it and check the delta’s state hash; see server authority and prediction.
Reconnect
Section titled “Reconnect”When the connection drops, reconnect (with a new ticket, from a browser) and send resume with the match and the
last version you applied. The server sends the deltas after it, in order, then carries on as before. Back off between
attempts if reconnecting fails.
A seated player who stays away from a live casual match for 90 seconds has their seat played by a bot until they come
back; reconnecting gives it back. The seats frame’s reconnectBy says when a grace period ends.
Keep alive
Section titled “Keep alive”Send ping, optionally with a sentAt number of your own; the server answers pong with the same sentAt, so you
can measure the round trip.
Quick chat
Section titled “Quick chat”Seated players can send preset phrases with a chat frame, if the game’s rules allow chat. The other seated players
get a chatted frame; spectators don’t. More than 3 phrases in 10 seconds are refused with tooFast. The phrases, and
which the game allows, are in the reference; a seat’s snapshot lists the
ones it may send in quickChat.
Without a socket
Section titled “Without a socket”Asynchronous clients, or any client between sessions, can use the Player API instead:
GET /v1/matches/{matchId} for the snapshot, GET /v1/matches/{matchId}/log?since=… for the deltas after a version,
and POST /v1/matches/{matchId}/moves to make a move. They use the same shapes and the same codes as the socket.