Connection: player property
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe player read-only property of the Connection interface is the player ID of the player who opened the connection.
Value
A string: the sub claim of the connection’s token, or for a guest a guest ID that starts with guest:.
Description
The player ID is the same for every connection the player opens, so it’s what the room keys a player’s things by: private state, entity ownership, presence entries and bans. A room holds at most one open connection per player; see One connection per player.
Examples
Giving the player a flag of its own
// flags.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";
const Flag = entity("flag", { x: "f32", y: "f32" }, { writable: ["x", "y"], onOwnerLeave: "delete" });
export default defineRoom({
schema: defineSchema({ entities: [Flag] }),
onJoin(room, connection) {
if (room.entities.ownedBy(connection.player, Flag).next().done) {
room.entities.create(Flag, {}, { owner: connection.player });
}
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
player | 0.1 | 0.1 | 0.1 | 0.1 |