RoomClient: wake event
Available since
@irtio/client 5.0BrowsersNodeThe 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
sleepeventRoomClient.asleepRoomDefinition.onWake(), the room side- Sleeping rooms
Runtime availability
| Browsers | Node | |
|---|---|---|
wake event | 5.0 | 5.0 |