Schema

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The Schema interface of the Room API is a room’s declared kinds and calls, as defineSchema() returns them. The room passes it as schema to defineRoom(), and its clients pass the same one to connect.

Instance properties

Schema.hash
A number computed from the kinds, their fields and the input kind, which clients send when they connect. A client whose schema has another hash is refused with close code 4004. Read only.
Schema.state
The shared state kind. Read only.
Schema.private
The private state kind. Read only.
Schema.entities
An array of the entity kinds. Read only.
Schema.calls
The calls from defineCalls(). They aren’t part of the hash. Read only.
Schema.input
The input kind, or undefined. It’s part of the hash when set. Read only.

Description

RoomOf<typeof schema> is the type of the Room a room declared with the schema gets, for typing helpers, and CallsOf<typeof schema> the type of a client’s room.calls.

Examples

Typing a helper from the schema

// rounds.ts
import { defineRoom, defineSchema, entity, type RoomOf } from "@irtio/room";

const Round = entity("round", { number: "u8", phase: "string" });
const schema = defineSchema({ state: Round });

function nextRound(room: RoomOf<typeof schema>) {
  room.state.number++;
  room.state.phase = "countdown";
}

export default defineRoom({
  schema,
  onMessage(room, _connection, message) {
    if (message === "next") nextRound(room);
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
Schema0.10.10.10.1