Room Lifecycle and State
Use this reference for room hook sequencing and synchronized state design.
Lifecycle Sequence
onCreate(options)initializes state and room metadata.onAuth(client, options, context)validates join eligibility.onJoin(client, options, auth)adds player state.onDrop(client)handles transient disconnect.onLeave(client, code)removes player permanently.onDispose()performs cleanup/persistence.
Schema Guidance
- Use Schema classes for every client-visible gameplay value.
- Prefer
MapSchema<Player>keyed bysessionIdfor per-player state. - Keep non-synced operational details outside gameplay state.
Verification Checklist
- Joining a room creates exactly one player entry.
- Leaving removes that entry.
- Client receives updates only for Schema mutations.