RoomClient: asleep property
@irtio/client 5.0BrowsersNodeThe asleep read-only property of the RoomClient interface says whether the room is asleep: hibernated while the router holds the client’s connection open.
Value
A boolean. It’s true from the sleep event until the room wakes or the connection drops, and false otherwise.
Description
A room sleeps when its code calls room.hibernate({ keepConnections: true }). While it sleeps, the connection stays open and readyState stays "open". Messages, calls and owner writes the client sends meanwhile wake the room and reach it after; unreliable messages and inputs are dropped. The client pings every 15 seconds instead of every 2.
When the room wakes, asleep is false again and the wake event fires, once the client holds the room’s full state.
Examples
Showing a sleeping board
A turn-based board game’s room sleeps between moves. The client shows that the room is waiting, and the next move wakes it.
// board.ts
import { connect } from "@irtio/client";
const room = await connect("main");
const show = () => console.log(room.asleep ? "Waiting for the next move" : "Your move");
room.addEventListener("sleep", show);
room.addEventListener("wake", show);
show();
See also
sleepeventRoom.hibernate(), the room’s side- Sleeping rooms
Runtime availability
| Browsers | Node | |
|---|---|---|
asleep | 5.0 | 5.0 |