PresenceEntry
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe 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.playerfor 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 thenamestring of the token’smeta, 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.nulluntil set. PresenceEntry.connected- A boolean.
falsewhile the player has no open connection, from just after its last one closes until its entry goesPRESENCE_GRACE(10 seconds) later;trueotherwise, 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 rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
PresenceEntry | 0.1 | 0.1 | 0.1 | 0.1 |