PresenceEvent
Available since
@irtio/client 5.0BrowsersNodeThe PresenceEvent interface of the Client API is the event a PresenceList fires as its join, change or leave event. It extends Event, and carries the player’s entry.
Constructor
new PresenceEvent(type, entry)
new PresenceEvent(type, entry, changed)
type"join","change"or"leave".entry- The
PresenceEntrythe event is about. changedOptional- An array of the fields that changed. Defaults to an empty array.
The client creates the events it fires.
Instance properties
All are read only. It also has Event’s properties, such as type.
PresenceEvent.entry- The player’s
PresenceEntry. PresenceEvent.changed- The fields that changed, on
change.
Description
Two properties of PresenceEvent have no page of their own.
entry
entry is the player’s entry as the list holds it. On leave it has the values it last had, and the list no longer returns it from get().
changed
changed is an array of "name", "status" and "connected". It lists the fields that changed on change, and is empty on join and leave.
Examples
Logging who joined and who left
The client logs each arrival and departure from one listener.
// door-log.ts
import { connect } from "@irtio/client";
const room = await connect("main");
for (const type of ["join", "leave"] as const) {
room.presence.addEventListener(type, ({ entry }) => console.log(`${entry.name || entry.player}: ${type}`));
}
See also
PresenceListPresenceEntry- Client API on one page, the whole of
@irtio/clienton one page
Runtime availability
| Browsers | Node | |
|---|---|---|
PresenceEvent | 5.0 | 5.0 |