PresenceEntry

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The PresenceEntry interface of the Room API is one player’s presence: its player ID, name and status, and whether it has an open connection. Every connection sees the same entry.

Presence.get() returns one, and iterating room.presence visits each. Its properties are read only, and show the entry’s current values; change the name and status with Presence.set().

Instance properties

PresenceEntry.player
The player ID, the same as Connection.player for the player’s connections. For a bot, its bot ID.
PresenceEntry.name
A string of at most MAX_PRESENCE_NAME (64) characters, which the room sets. It starts as the name string of the token’s meta, when there’s one of at most 64 characters, and "" otherwise.
PresenceEntry.status
A JSON value of at most MAX_PRESENCE_STATUS (1,024) bytes as JSON, which the player sets from its client and the room may replace. null until set.
PresenceEntry.connected
A boolean. false while the player has no open connection, from just after its last one closes until its entry goes PRESENCE_GRACE (10 seconds) later; true otherwise, and always for a bot.

Examples

Tidying statuses players leave behind

A player who drops keeps its entry for 10 seconds. This room clears a “typing” status as soon as the player is gone.

// typing.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  tickRate: 2,
  onTick(room) {
    for (const entry of room.presence) {
      const status = entry.status as { typing?: boolean } | null;
      if (!entry.connected && status?.typing) room.presence.set(entry.player, { status: null });
    }
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
PresenceEntry0.10.10.10.1