PresenceList: leave event
Available since
@irtio/client 5.0BrowsersNodeThe leave event of the PresenceList interface fires each time a player leaves the room and their presence entry goes.
Syntax
addEventListener("leave", (event) => {})
Event type
A PresenceEvent. It extends Event and adds these properties:
entryRead only- The
PresenceEntryof the player who left, with the values it last had. changedRead only- An empty array.
Description
A player leaves 10 seconds after their last connection drops, unless they reconnect first, or at once when their client closes with close(). Before then their entry stays, with connected false. A resync doesn’t fire leave for players who stayed.
By the time the event fires, get() no longer returns the entry.
Examples
Freeing a seat when a player leaves
The client shows a player’s seat as empty once they have left the room, not when their connection first drops.
// seats.ts
import { connect } from "@irtio/client";
const room = await connect("table-8");
room.presence.addEventListener("change", ({ entry, changed }) => {
if (changed.includes("connected") && !entry.connected) console.log(`holding ${entry.name || entry.player}'s seat`);
});
room.presence.addEventListener("leave", ({ entry }) => console.log(`${entry.name || entry.player}'s seat is free`));
See also
joineventRoomDefinition.onPlayerLeave(), the room’s side- Presence
Runtime availability
| Browsers | Node | |
|---|---|---|
leave event | 5.0 | 5.0 |