PresenceList: size property
Available since
@irtio/client 5.0BrowsersNodeThe size read-only property of the PresenceList interface is the number of presence entries the client holds.
Value
A whole number, 0 before the client is first ready. It counts every entry: players whose connection dropped and whose 10-second grace hasn’t ended, with connected false, and bots.
Description
size counts players, not connections. To count the players still connected, filter the list:
[...room.presence].filter((entry) => entry.connected).length
Examples
Waiting for a full table
A card table seats four. The client shows how many seats are left until four players are in.
// seats.ts
import { connect } from "@irtio/client";
const room = await connect("table-3");
function seats(): void {
const left = 4 - room.presence.size;
console.log(left > 0 ? `waiting for ${left} more` : "table full");
}
seats();
room.presence.addEventListener("join", seats);
room.presence.addEventListener("leave", seats);
See also
PresenceListPresence.size, the room’s side
Runtime availability
| Browsers | Node | |
|---|---|---|
size | 5.0 | 5.0 |