Voice chat
GDMP has voice chat built in. You turn it on for your experience; players set up their microphone once in the launcher (Settings → Voice chat) or in the game (ESC → Voice). Your scripts can put players in channels, mute them, and react when someone speaks.
Turn it on
Section titled “Turn it on”Add voice to the manifest’s capabilities. Optionally, say how it sounds:
{ "capabilities": ["players", "net", "voice"], "voice": { "mode": "proximity", "range": 900 }}voice field |
||
|---|---|---|
mode |
"global" (default) |
everyone in the same channel hears everyone, at full volume |
"proximity" |
closer is louder, with left / right from where the speaker stands; silent past range |
|
range |
30 .. 30000, default 900 | in level units (30 units = one block); proximity only |
Without the capability nothing is sent: the relay drops voice for experiences that do not declare it.
What players get
Section titled “What players get”- Voice activity (the microphone opens when they speak, with a sensitivity they set) or push to talk (V by default, any key or a side mouse button), or the microphone off.
- In ESC → Players: a ring around whoever is speaking, a mute button and a volume slider for every player (only for them). Block also mutes.
- In ESC → Voice: their microphone and its level, mute, deafen, volumes, voice sounds, the channel they are in.
- Short voice sounds when someone joins or leaves their channel, and when they mute.
Voice is Opus at 24 kbps in 20 ms frames, over UDP (TCP when UDP is blocked), with error correction for lost packets.
gdmp.voice on the server
Section titled “gdmp.voice on the server”Channels and mutes are the server’s: a client cannot change them.
setChannel(playerId, name) |
puts the player in a channel; "" = the default channel (everyone). A name is 1..23 of A-Z a-z 0-9 _ - and spaces |
getChannel(playerId) → string |
|
setMuted(playerId, muted) |
the server’s mute: nobody hears that player until you unmute them |
isMuted(playerId) → boolean |
the server’s mute only |
isSpeaking(playerId) → boolean |
a voice frame from them in the last 300 ms |
// teams hear only their own team; the dead are muted until the next roundgdmp.players.onJoin(p => gdmp.voice.setChannel(p.id, teamOf(p.id)));gdmp.players.onDeath(p => gdmp.voice.setMuted(p.id, true));function newRound() { for (const p of gdmp.players.list()) gdmp.voice.setMuted(p.id, false); }gdmp.voice on a client
Section titled “gdmp.voice on a client”isEnabled() → boolean |
voice chat runs on this PC (the experience has it and the engine started) |
isSpeaking(playerId) → boolean |
that player is speaking (this player too, while their microphone is open) |
onSpeaking(callback) |
callback(playerId, speaking) when someone starts or stops speaking |
setVolume(playerId, volume) |
your game’s own volume for that player, 0 .. 2 (multiplied with the player’s choice) |
getVolume(playerId) → number |
|
channel() → string |
the channel this player is in ("" = the default one) |
playSound(name) |
one of the voice sounds: "join", "leave", "mute", "unmute" (if the player has voice sounds on) |
// a speaking bubble over the player's name taggdmp.voice.onSpeaking((id, speaking) => setBubble(id, speaking));A player can always mute anyone for themselves, whatever your script sets.
TypeScript
Section titled “TypeScript”The declarations from the GDMP types (namespace GDMP):
interface VoiceServer { /** `""` = the default channel. */ setChannel(playerId: PlayerId, name: string): void; getChannel(playerId: PlayerId): string; setMuted(playerId: PlayerId, muted: boolean): void; isMuted(playerId: PlayerId): boolean; isSpeaking(playerId: PlayerId): boolean;}
interface VoiceClient { isEnabled(): boolean; isSpeaking(playerId: PlayerId): boolean; onSpeaking(cb: Callback<[playerId: PlayerId, speaking: boolean]>): void; /** 0..2. */ setVolume(playerId: PlayerId, volume: number): void; getVolume(playerId: PlayerId): number; channel(): string; playSound(sound: 'join' | 'leave' | 'mute' | 'unmute'): void;}