RoomClient: schema property

Available since @irtio/client 5.0BrowsersNode

The schema read-only property of the RoomClient interface is the Schema the client was given: the room’s kinds and calls, from the same defineSchema() module the room uses.

Value

A Schema: the schema passed to connect() or the constructor, or an empty schema, with no kinds and no calls, when it was left out.

Description

The client sends the schema’s hash when it connects. A room whose build has a schema with another hash closes the connection with 4004, and the client fails with an IrtError named VersionError; see reloadForNewBuild().

The client types its state, private and calls from the schema, and entities decodes each kind’s fields with it.

Examples

Listening to the shared state’s changes

The schema’s state kind is the kind of the shared state, so code that has only the client can listen to it.

// scoreboard.ts
import { connect, defineSchema, entity } from "@irtio/client";

const Match = entity("match", { red: "u16", blue: "u16" });
const room = await connect("main", { schema: defineSchema({ state: Match }) });

room.entities.onChange(room.schema.state, (match, changed) => {
  if (changed.includes("red") || changed.includes("blue")) console.log(`${match.red} : ${match.blue}`);
});

See also

Runtime availability

BrowsersNode
schema5.05.0