RoomOpenEvent

Available since @irtio/client 5.0BrowsersNode

The RoomOpenEvent interface of the Client API is the event a RoomClient fires as its open event, when it holds the room’s full state after having no connection. It extends Event.

Constructor

new RoomOpenEvent(reconnected)
reconnected
A boolean, the event’s reconnected. The event’s type is "open".

The client creates the events it fires.

Instance properties

All are read only. It also has Event’s properties, such as type.

RoomOpenEvent.reconnected
false for the first open, true after each reconnect.

Examples

Counting reconnects

A game’s debug overlay counts how often the client has reconnected.

// reconnects.ts
import { connect, type RoomOpenEvent } from "@irtio/client";

const room = await connect("https://rooms.irt.io/my-game/arena");
let reconnects = 0;

function opened(event: RoomOpenEvent): void {
  if (event.reconnected) reconnects += 1;
  console.log(`reconnects: ${reconnects}`);
}
room.addEventListener("open", opened);

See also

Runtime availability

BrowsersNode
RoomOpenEvent5.05.0