RoomClient: presence property
@irtio/client 5.0BrowsersNodeThe presence read-only property of the RoomClient interface is the room’s PresenceList: every player in the room, with their name, status and whether they’re connected.
Value
A PresenceList. It’s empty until ready resolves, and the same list is kept across reconnects.
Description
The presence list has every player in the room, whatever the room’s interest sends the client, including players whose connection closed in the last 10 seconds. Its events fire after the entity callbacks of the same state update, before the update event. A reconnect doesn’t fire leave and join for players who stayed.
The player sets its own status with presence.setStatus(). The room sets each player’s name.
Examples
Showing who is typing
Each player sets a status while typing in the chat, and every client shows who is.
// typing.ts
import { connect } from "@irtio/client";
const room = await connect("main");
export function onInput(text: string) {
room.presence.setStatus({ typing: text.length > 0 });
}
room.presence.addEventListener("change", ({ entry, changed }) => {
if (!changed.includes("status") || entry.player === room.player) return;
const typing = (entry.status as { typing?: boolean } | null)?.typing === true;
console.log(typing ? `${entry.name} is typing` : `${entry.name} stopped typing`);
});
See also
PresenceListRoom.presence, the room’s side- Presence
Runtime availability
| Browsers | Node | |
|---|---|---|
presence | 5.0 | 5.0 |