PresenceList: leader property

Available since @irtio/client 5.0BrowsersNode

The leader read-only property of the PresenceList interface is the player ID of the player who leads a native room.

Value

A string, or undefined when no player leads or the client isn’t connected. A room with room code has no leader, so it’s always undefined there.

Description

The room names its leader, and the leader event fires when it changes. The leader can start and cancel a lobby’s countdown, and passes the role on with room.lead(player).

Examples

Marking the leader in a player list

The client adds a note to the leader’s name when it draws the list.

// roster-leader.ts
import { connect } from "@irtio/client";

const room = await connect("lobby", { type: "lobby" });

function names(): string[] {
  return [...room.presence].map((entry) => (entry.player === room.presence.leader ? `${entry.name} (leads)` : entry.name));
}

console.log(names().join(", "));

See also

Runtime availability

BrowsersNode
leader5.05.0