Class: VoiceChat
Proximity voice for a world that has it (WorldConfig::voice_range on
the server).
Register it on the network, call enable from a click, and call update every frame with the ear and a way to find a speaker:
const voice = new VOXELIZE.VoiceChat();
network.register(voice);
button.onclick = () => voice.enable();
// every frame
voice.update(
{ position, forward, up },
(id) => peers.getPeerById(id)?.position.toArray(),
);
It captures the microphone, sends it while the gate is open
(push-to-talk or open mic), and plays every voice the server relays from
where its player stands, fading with distance to silence at the world's
range. It draws nothing: getState, getSpeakers and the
peers' voice metadata are what a game's UI reads.
Implements
Constructors
constructor
• new VoiceChat(options?): VoiceChat
Parameters
| Name | Type |
|---|---|
options | VoiceChatOptions |
Returns
Properties
packets
• packets: MessageProtocol[] = []
Outgoing packets, sent by network.flush().
Implementation of
Accessors
inputLevel
• get inputLevel(): number
The level of the player's own microphone, 0..1, for a meter.
Returns
number
isAvailable
• get isAvailable(): boolean
Whether the world this client joined has voice.
Returns
boolean
Methods
disable
▸ disable(): void
Turn voice off: the microphone closes and nothing is heard.
Returns
void
dispose
▸ dispose(): void
Close everything. The instance is not usable afterwards.
Returns
void
enable
▸ enable(«destructured»?): Promise<void>
Turn voice on. Call it from a click or a key press: it is what opens
the browser's microphone prompt and starts audio. With
withMicrophone: false, or when the microphone is refused, the player
listens without speaking (see micStatus).
Parameters
| Name | Type | Default value |
|---|---|---|
«destructured» | Object | {} |
› withMicrophone | boolean | true |
Returns
Promise<void>
getSpeakerVolume
▸ getSpeakerVolume(speakerId): number
The player's volume for speakerId; 1 unless they changed it.
Parameters
| Name | Type |
|---|---|
speakerId | string |
Returns
number
getSpeakers
▸ getSpeakers(): readonly VoiceSpeaker[]
The players heard right now, as of the last update, nearest
first: speaking, and near enough that their voice has any volume. The array is replaced, never mutated, when who is in it changes;
each entry's level and distance are refreshed in place every update.