RoomClient: generation property
@irtio/client 5.0BrowsersNodeThe generation read-only property of the RoomClient interface is the room’s generation: a number that changes each time the room starts again, when it restarts or wakes.
Value
A number, from the router’s answer to each connection. It’s 0 until the router accepts the first connection.
Description
Compare generations for equality only: a different number means a room started again from its room state, and the order of the numbers means nothing.
When a reconnect finds the room in the same generation, the client resumes: the room sends only what changed while the client was away, and the client keeps its estimate of serverTick(). When the generation changed, every entity leaves the entity store and the room’s full state enters again, and predictions and interpolators start over.
Examples
Noticing that the room started again
After a reconnect, a game that keeps something outside room state checks whether the room it reconnected to is the same one.
// restarts.ts
import { connect } from "@irtio/client";
const room = await connect("main");
let generation = room.generation;
room.addEventListener("open", () => {
if (room.generation !== generation) console.warn("the room started again; rebuilding the scene");
generation = room.generation;
});
See also
openevent- Generations, in How rooms hibernate and wake
Runtime availability
| Browsers | Node | |
|---|---|---|
generation | 5.0 | 5.0 |