RoomDefinition: voice property

Available since @irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room host

The voice property of a room definition turns on proximity voice: the room tells each connection who it hears and who hears it, and @irtio/client/voice plays what the room allows.

Value

An object with these optional properties. voice: {} turns voice on with the defaults.

maxSpeakers
The most speakers each listener hears, at most 256. Defaults to 8, or 256 with audible. The project’s voice.maxSpeakers setting is a ceiling: the room gets the smaller of the two.
owner(entity)
Returns the player ID an entity speaks for, or undefined. Defaults to the entity’s owner, else its owner string field.
audible(room, listener)
Returns the player IDs listener, a Connection, hears, replacing the default rule. The listener’s own ID is dropped.

Description

The project needs its voice setting turned on as well. By default a listener hears the players whose entities it can see under the room’s interest, ranked by the interest limit’s priority and capped at maxSpeakers. audible replaces that rule, for teams, radio channels or a whole room on one call.

With each state update the room works out every connection’s speakers and listeners, and sends them when they change, at most 4 times a second. Bots, and players the room muted with room.muteVoice(), are left out of every listener’s speakers. Voice doesn’t need a tickRate.

Examples

Team radio

Each player hears only its own team, wherever they are.

// radio.ts
import { defineRoom } from "@irtio/room";

export default defineRoom({
  onJoin(_room, connection) {
    connection.data.team = (connection.meta as { team?: string } | null)?.team ?? "red";
  },
  voice: {
    audible: (room, listener) =>
      [...room.connections.values()].filter((c) => c.data.team === listener.data.team).map((c) => c.player),
  },
});

See also

Runtime availability

Hosted roomsirt dev@irtio/testingSelf-hosted room host
voice0.10.10.10.1