RoomClient: player property
Available since
@irtio/client 5.0BrowsersNodeThe player read-only property of the RoomClient interface is the ID of the player the client connected as.
Value
A string: the sub of the player token passed as token, or guest: followed by a random ID for a guest. It’s "" until the router accepts the first connection, and set by the time ready resolves.
Description
The player ID stays the same across reconnects. A guest keeps its ID across reloads and browser restarts too, since the client keeps the guest’s token in localStorage; with guest: "tab" it’s kept per tab instead. See the Guests section of Games without a backend.
The room sees the same ID as connection.player. Presence entries, entities.ownerOf() and the room’s messages name players by it too.
Examples
Marking the local player in the player list
A player list marks the local player’s own entry.
// players.ts
import { connect } from "@irtio/client";
const room = await connect("main");
for (const entry of room.presence) {
console.log(entry.player === room.player ? `${entry.name} (you)` : entry.name);
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
player | 5.0 | 5.0 |