Rooms and shared state
A room is one session of your game. Each room has its own state and connected clients. A schema describes the state; the server and client import the same schema so their types agree.
| File | Runs where | Purpose |
|---|---|---|
irtio/schema.ts | Server and client | Declares collections and field types |
irtio/rpc.ts | Server and client | Declares typed calls |
irtio/room.ts | Server | Implements lifecycle handlers and game rules |
main.ts | Browser | Reads state, handles input, and renders your game |
Writing state
Each entity instance has an owner. A client writes the instances it owns; the server can validate those writes and update state itself. Server-owned collections and singletons keep outcomes such as scores and turn order under server control.
const player = room.state.players[room.me];
if (player) player.x += 1; This is a client-side excerpt using the room from the quickstart. irtio batches the write and synchronizes it. Use a typed RPC when a client needs to ask the server to perform an action.
Reading and rendering
Use room.state for game logic and room.render for drawing. The render view smooths remote movement; both follow the shape of your schema.
Choose an authority model based on which values players may control. You can combine client-owned movement with server-owned scores in the same game.