Tutorials
Build a Counter Room
From connect to state sync in one minimal loop.
Build a Counter Room
This tutorial walks through the full loop your game will use repeatedly:
- connect
- join room
- send room message
- receive patch
- update local UI state
Step 1: Connect with SDK
import { connect } from '@triformine/nexis-sdk'
const client = await connect('ws://localhost:4000', {
projectId,
token
})Step 2: Join or Create Room
const room = await client.joinOrCreate('counter_plugin_room', { roomId: 'counter_plugin_room:default' })After join, the client should receive an initial state.snapshot.
Step 3: Listen to State Changes
room.onStateChange((state) => {
renderCounter(state.counter ?? 0)
})Step 4: Send Increment Message
room.send('inc', {})Server/plugin processes room.message and emits:
state.patchfor new state- optional
rpc.responsewhen called through RPC wrapper
Step 5: Validate Correctness
Expected behavior:
- sequence (
seq) increases monotonically - state checksum stays coherent when provided
- reconnect with same
session_idcan resume room session within TTL
For protocol details see Protocol.
Typed Counter Action
const = ({ : 3 }, { : 1 });
.(.);