PresenceEntry

Available since @irtio/client 5.0BrowsersNode

The PresenceEntry interface of the Client API is one player’s entry in room.presence: their player ID, name and status, and whether they have an open connection. Every client sees the same entry.

PresenceList.get() and me return one, iterating room.presence visits each, and the PresenceList events carry them in a PresenceEvent. Its properties are read only and show the entry’s values as of the last state update; the local player changes their own status with setStatus().

Instance properties

PresenceEntry.player
A string, the player ID. For a bot, its bot ID, which starts with bot:; isBot() tells them apart.
PresenceEntry.name
A string of at most 64 characters, which the room sets with Presence.set(). It starts as the name string of the player token’s meta, when there’s one of at most 64 characters, and "" otherwise.
PresenceEntry.status
A JSON value of at most 1 KB as JSON, which the player sets from their client and the room may replace. null until set.
PresenceEntry.connected
A boolean. false while the player has no open connection, from just after their last one closes until their entry goes 10 seconds later; true otherwise, and always for a bot.

Description

An entry’s properties change with each state update. A player who reconnects within the 10-second grace keeps their entry and status. After a resync, such as on a change of the room’s generation, each entry is a new object, so look entries up with get() rather than keeping them.

Examples

Listing who’s ready

Each player sets a ready flag in their status. The client lists the connected players and whether each is ready.

// ready-check.ts
import { connect, type PresenceEntry } from "@irtio/client";

const room = await connect("lobby");

function isReady(entry: PresenceEntry): boolean {
  const status = entry.status as { ready?: unknown } | null;
  return status?.ready === true;
}

room.addEventListener("update", () => {
  for (const entry of room.presence) {
    if (entry.connected) console.log(`${entry.name || entry.player}: ${isReady(entry) ? "ready" : "not ready"}`);
  }
});

status is whatever the player set, so the client checks its shape before using it.

See also

Runtime availability

BrowsersNode
PresenceEntry5.05.0