Wire protocol
Every message is a single JSON object with a type field. Over WebSocket, send one message per text frame. Over UDP, send one message per datagram.
Client to server
join
{ "type": "join", "roomId": "lobby-1", "playerId": "alice", "apiKey": "ns_api_..." }
apiKey identifies the project for UDP clients. WebSocket clients are identified by the subdomain they connect to.
leave
{ "type": "leave" }
call
{ "type": "call", "callId": "1", "function": "useItem", "args": { "itemId": "potion" } }
callId is any string you choose. The matching result echoes it.
ping
{ "type": "ping", "t": 1729600000000 }
UDP clients must ping at least every 20 seconds. t is optional: the server echoes it back in pong with its own clock, so you can measure round-trip time and sync clocks.
state
{ "type": "state", "seq": 42, "data": { "pos": [1.5, 0, -3], "yaw": 1.57 } }
The player's realtime state. seq must increase with every message; older or repeated ones are ignored. data is any JSON object up to the plan's state size (512 bytes on Free; see Limits). States are not acknowledged. See Fast-paced games.
Server to client
joined
{
"type": "joined",
"roomId": "lobby-1",
"playerId": "alice",
"session": "...",
"room": { "roomId": "lobby-1", "properties": {}, "players": [{ "playerId": "alice", "properties": {} }] },
"time": 1729600000000,
"realtime": { "tickRate": 30, "maxStateBytes": 512, "statesPerSecond": 70 }
}
snapshot
{ "type": "snapshot", "tick": 1801, "time": 1729600000033, "states": [["alice", 42, { "pos": [1.5, 0, -3] }]] }
Sent every tick to everyone in the room. Each entry is [playerId, seq, data]. Only states that changed recently are included, and every second a snapshot with "full": true includes everyone. Large rooms are split across several snapshot messages with the same tick, so each fits in one UDP packet.
result
{ "type": "result", "callId": "1", "ok": true, "result": { "remaining": 1 } }
{ "type": "result", "callId": "1", "ok": false, "error": { "code": "ITEM_NOT_OWNED", "message": "You do not own that item." } }
event
{ "type": "event", "name": "itemUsed", "data": { "playerId": "alice", "itemId": "potion" } }
property and propertyDelete
{ "type": "property", "scope": "player", "playerId": "alice", "key": "inventory", "value": ["sword"] }
{ "type": "propertyDelete", "scope": "room", "key": "round" }
scope is player or room. Global properties are delivered as room properties.
left, pong and error
{ "type": "left" }
{ "type": "pong", "t": 1729600000000, "time": 1729600000021 }
{ "type": "error", "code": "NOT_JOINED", "message": "Join a room first." }