RoomClient: joinTime property

Available since @irtio/client 5.0BrowsersNode

The joinTime read-only property of the RoomClient interface is how long the client took to join the room, and whether the room had to start first.

Value

An object with these properties, or undefined until ready resolves:

ms
A number: the milliseconds from constructing the client to applying the room’s first full state update. After a reconnect, it’s the milliseconds from the drop to the client holding the room’s state again.
started
A boolean: true if the router sent a waking event on the way, which it does for a room that wakes from hibernation, a room the connection creates and a room that restarts after a crash.

Description

ms leaves out any createRoom() or quickJoin() before the client was constructed. The UI kit’s join loader shows it.

Examples

Recording join times

The game sends each join’s time to its own analytics, split by whether the room had to start, since a wake takes longer.

// join-metrics.ts
import { connect } from "@irtio/client";

const room = await connect("main");
const { ms, started } = room.joinTime ?? { ms: 0, started: false };
console.log(`joined in ${Math.round(ms)} ms${started ? ", room started" : ""}`);
room.addEventListener("open", () => {
  if (room.joinTime) console.log(`back in ${Math.round(room.joinTime.ms)} ms`);
});

See also

Runtime availability

BrowsersNode
joinTime5.05.0