Voice: participants event
Available since
@irtio/client 5.0BrowsersThe participants event of the Voice interface fires when another player joins or leaves the voice server, with the new set of players on it.
Syntax
addEventListener("participants", (event) => {})
Event type
A CustomEvent. Its detail is a ReadonlySet<string>: the new participants, the player IDs of the other players on the voice server.
Description
The event fires only when the set changes. It also fires with an empty set when voice drops, and with the players on it again after voice rejoins, so a listener added once keeps working across reconnects. disconnect() empties the set too.
Examples
Announcing who joins voice
A chat panel posts a line when a player joins or leaves voice.
// voice-feed.ts
import type { Voice } from "@irtio/client/voice";
export function announceVoice(voice: Voice, post: (line: string) => void): void {
let before = new Set(voice.participants);
voice.addEventListener("participants", ({ detail: now }) => {
for (const player of now) if (!before.has(player)) post(`${player} joined voice`);
for (const player of before) if (!now.has(player)) post(`${player} left voice`);
before = new Set(now);
});
}
When voice drops, every player reads as leaving, and joining again when it rejoins.
See also
Runtime availability
| Browsers | |
|---|---|
participants event | 5.0 |