defineRoom() function
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe defineRoom() function checks a room definition and returns it. A room module’s default export is its result.
Syntax
defineRoom(definition)
Parameters
definition- A
RoomDefinition: the room’s schema, tick rate, stepper, interest and other settings, and its hooks.
Return value
The same definition, typed without its entity kinds, which only type its writes handlers.
Exceptions
RangeError- Thrown for a
tickRatethat isn’t an integer from 1 to 120, asleep.afterthat isn’t a positive number of milliseconds, or aprivateRetentionthat isn’t a positive number of milliseconds or"forever". Error- Thrown for
onTick, astepper, ahistoryor a bot behaviour with atickhook in a room without atickRate; for ahistoryof a kind that isn’t one of the schema’s entity kinds; and for awriteskey that isn’t the private kind or an entity kind with writable fields.
The types reject most of these too.
Examples
A turn-based room without ticks
// checkers.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";
const Game = entity("game", { turn: "string", moves: "u16" });
export default defineRoom({
schema: defineSchema({ state: Game }),
onJoin(room, connection) {
if (room.state.turn === "") room.state.turn = connection.player;
},
onMessage(room, connection) {
if (room.state.turn === connection.player) room.state.moves++;
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
defineRoom() | 0.1 | 0.1 | 0.1 | 0.1 |