RoomClient: wake event

Available since @irtio/client 5.0BrowsersNode

The wake event of the RoomClient interface fires when the room wakes from sleep and the client holds its full state again.

Syntax

addEventListener("wake", (event) => {})

Event type

A plain Event, with no properties of its own.

Description

wake follows a sleep event. When it fires, asleep is false, and calls the client made while the room slept are answered, not failed. Prediction starts over.

It isn’t an open event, since the connection never dropped. A room that wakes after the connection dropped, as from hibernation, fires open instead.

Examples

Catching up after a wake

A board game shows whose turn it is once the room is back, since another player’s move is often what woke it.

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

const Board = entity("board", { turn: "string" });
const schema = defineSchema({ state: Board });

const room = await connect("https://rooms.irt.io/my-game/chess-12", { schema });
const banner = document.querySelector("#turn")!;

room.addEventListener("wake", () => {
  banner.textContent = room.state.turn === room.player ? "Your move" : "Waiting for your opponent";
});

See also

Runtime availability

BrowsersNode
wake event5.05.0