How to add voice chat to a web game
Browser and web games don't fit native voice SDKs well — but WebRTC is built for exactly this. Here's how to add party or proximity voice to a web game with Guildyx: your server mints a media token, the player joins a room, and they're talking on a region-local server.
Why WebRTC for web games
Native game-voice SDKs (Vivox, etc.) are built for Unity and console titles. In the browser, WebRTC is the native path — no plugins, works everywhere, and it's what Guildyx runs on, with media servers in multiple regions so latency stays low for competitive play.
1. Mint a voice token (server-side)
When a player joins a lobby, party or proximity zone, ask Guildyx for a media token for that room. Access is gated by your permission model — only players who should hear each other get a token for the same room.
// your game server
const res = await fetch(
`https://eu.dc.guildyx.com/api/calls/${roomChannelId}/token`,
{ method: "POST",
headers: { "x-api-key": KEY, "Authorization": `Bearer ${playerJWT}` } }
);
const { url, token } = await res.json(); // url = wss://eu.lk.guildyx.com
2. Join the room (in the browser)
import { Room } from "livekit-client";
const room = new Room({ adaptiveStream: true });
await room.connect(url, token);
await room.localParticipant.setMicrophoneEnabled(true);
// hear everyone else
room.on("trackSubscribed", (track) => {
if (track.kind === "audio") track.attach(); // plays the audio
});
3. Proximity / team voice
Map your game's concept of "who can hear whom" to rooms:
- Party voice — one room per party.
- Team voice — one room per team.
- Proximity voice — move players between zone rooms as they move on the map (or adjust volume per peer client-side).
Because tokens come from your permission model, you decide who's allowed to talk and listen — no separate identity system to maintain.