RoomDefinition: voice property
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe 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’svoice.maxSpeakerssetting 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 itsownerstring field. audible(room, listener)- Returns the player IDs
listener, aConnection, 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 rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
voice | 0.1 | 0.1 | 0.1 | 0.1 |