PresenceList: join event

Available since @irtio/client 5.0BrowsersNode

The join event of the PresenceList interface fires each time a player joins the room and their presence entry arrives.

Syntax

addEventListener("join", (event) => {})

Event type

A PresenceEvent. It extends Event and adds these properties:

entry Read only
The new player’s PresenceEntry.
changed Read only
An empty array.

Description

A player joins when their first connection opens. A player who reconnects within the 10-second grace keeps their entry, so they don’t join again: the change event fires for connected instead. A resync doesn’t fire join for players who stayed either.

The entries in the first state update arrive before connect() resolves, so a listener added after it doesn’t get join for them. Iterate room.presence for the players already in the room.

Examples

Announcing new players

The client greets each player who joins, and stops when the match starts.

// arrivals.ts
import { connect } from "@irtio/client";

const room = await connect("lobby");
const lobby = new AbortController();

room.presence.addEventListener("join", ({ entry }) => console.log(`${entry.name || entry.player} joined`), { signal: lobby.signal });

room.addEventListener("message", ({ data }) => {
  if ((data as { type?: unknown } | null)?.type === "start") lobby.abort();
});

See also

Runtime availability

BrowsersNode
join event5.05.0