PresenceList: get() method
Available since
@irtio/client 5.0BrowsersNodeThe get() method of the PresenceList interface returns a player’s presence entry.
Syntax
get(player)
Parameters
player- A string, the player ID.
Return value
The player’s PresenceEntry, or undefined when they have none in the room.
Exceptions
None.
Description
get() is a map lookup. A player has one entry however many connections they have, and keeps it through a dropped connection for 10 seconds, with connected false.
Examples
Naming who sent a chat message
The room relays chat with the sender’s player ID. The client shows the sender’s name from their presence entry.
// chat.ts
import { connect } from "@irtio/client";
const room = await connect("main");
room.addEventListener("message", ({ data }) => {
const chat = data as { from?: string; message?: string } | null;
if (typeof chat?.from !== "string" || typeof chat.message !== "string") return;
const name = room.presence.get(chat.from)?.name || chat.from;
console.log(`${name}: ${chat.message}`);
});
See also
PresenceList.mePresence.get(), the room’s side
Runtime availability
| Browsers | Node | |
|---|---|---|
get() | 5.0 | 5.0 |