RoomClient: peers property
Available since
@irtio/client 5.0BrowsersNodeThe peers read-only property of the RoomClient interface lists the players this player hears and is heard by in voice chat, as the room last decided.
Value
An object with these properties:
speakers- A read-only array of the player IDs this player hears.
listeners- A read-only array of the player IDs that hear this player.
Both are empty in a project that doesn’t use voice, and after each reconnect until the room sends them again.
Description
The room decides who hears whom, by distance and line of sight or by its own rule, and the peers event fires when the lists change. joinVoice() subscribes to the speakers and lets the listeners hear the player; read peers to show who is in earshot.
Examples
Showing who can hear you
A proximity chat game lists the players who hear the local player each time the room changes who’s in earshot.
// earshot.ts
import type { RoomClient } from "@irtio/client";
export function showEarshot(room: RoomClient): void {
room.addEventListener("peers", () => {
const names = room.peers.listeners.map((player) => room.presence.get(player)?.name ?? player);
console.log(names.length > 0 ? `Heard by ${names.join(", ")}` : "Nobody can hear you");
});
}
See also
Runtime availability
| Browsers | Node | |
|---|---|---|
peers | 5.0 | 5.0 |