Presence: get() method

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

The get() method of the Presence interface returns a player’s presence entry.

Syntax

get(player)

Parameters

player
The player ID.

Return value

The player’s PresenceEntry, or undefined when the player has none.

Description

A player’s entry exists from before onJoin runs for its first connection until its presence ends, so it’s there in onLeave, and in onPlayerLeave until the hook first awaits. While the player has no open connection, connected is false.

Examples

Saying goodbye by name

onPlayerLeave runs once a player’s presence ends, with the entry still there until the hook first awaits, so it can read the player’s name.

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

export default defineRoom({
  onPlayerLeave(room, player) {
    const name = room.presence.get(player)?.name || "A player";
    room.broadcast({ type: "left", text: `${name} left the table` });
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
get()0.10.10.10.1