RoomOpenEvent: reconnected property

Available since @irtio/client 5.0BrowsersNode

The reconnected read-only property of the RoomOpenEvent interface says whether the client had a connection to the room before this open event.

Value

A boolean.

  • false for the first open, which fires before connect() resolves.
  • true after each reconnect, whether the client resumed or the room sent its state whole.

Description

A listener added after await connect(...) sees only opens with reconnected true, since the first one has fired by then.

Examples

Telling a first join from a return

A listener added before the client is ready sees both kinds of open. The client is constructed with new RoomClient() rather than connect() so the listener is in place before the first one.

// join-log.ts
import { RoomClient } from "@irtio/client";

const client = new RoomClient("https://rooms.irt.io/my-game/arena");
client.addEventListener("open", (event) => {
  console.log(event.reconnected ? "back in the arena" : "joined the arena");
});
await client.ready;

See also

Runtime availability

BrowsersNode
reconnected5.05.0