Voice: speaking property

Available since @irtio/client 5.0Browsers

The speaking read-only property of the Voice interface is the set of players the voice server hears talking now, this player included.

Value

A ReadonlySet<string> of player IDs. It’s empty while voice is down.

Description

The voice server detects speech, so speaking covers speakers this client doesn’t hear too. A player who isn’t on the voice server is never in it. The speaking event, a CustomEvent, fires with the new set in its detail each time it changes.

Examples

Lighting up a speaking ring

Each player’s portrait gets a ring while they speak, updated whenever the set changes.

// speaking-ring.ts
import type { Voice } from "@irtio/client/voice";

export function ringSpeakers(voice: Voice, portraits: Map<string, HTMLElement>): void {
  const update = (speaking: ReadonlySet<string>) => {
    for (const [player, portrait] of portraits) portrait.classList.toggle("speaking", speaking.has(player));
  };
  update(voice.speaking);
  voice.addEventListener("speaking", ({ detail }) => update(detail));
}

See also

Runtime availability

Browsers
speaking5.0