RoomOpenEvent
Available since
@irtio/client 5.0BrowsersNodeThe 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.reconnectedfalsefor the first open,trueafter 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
openeventRoomCloseEvent- Client API on one page, the whole of
@irtio/clienton one page
Runtime availability
| Browsers | Node | |
|---|---|---|
RoomOpenEvent | 5.0 | 5.0 |