NEXIS
Getting started

Room Basics

Join/create, state subscriptions, room messages, and cleanup.

Room Basics

Join or create

const room = await client.joinOrCreate("counter_plugin_room", { roomId: "counter_plugin_room:default" });

roomType picks gameplay logic.
room (option) targets a specific room id suffix.

State lifecycle

room.onStateChange((state) => {
  render(state);
});

Important behavior:

  • first callback call is from initial state.snapshot
  • subsequent calls are from applied state.patch ops

Send custom room messages

room.send("player.move", { x: 10, y: 4, seq: 18 });
room.send("chat.send", { message: "hello" });

Use this for gameplay actions that your room/plugin handles in on_message.

Send bytes for custom binary payloads

room.sendBytes("voice.chunk", [1, 2, 3, 4]);

Receive room events/messages

room.onMessage("chat.message", (payload) => {
  console.log(payload);
});

Leave behavior

When a client leaves:

  • membership is removed from room
  • empty room may auto-dispose (depending on room lifecycle)
  • reconnect resume is possible within configured session TTL

Typed Room API

function (: ) {
  .('player.ready', { : true });
  .<{ : string[] }>('room.members', () => {
    .(..);
  });
}

On this page