Guide · ~10 min

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:

Because tokens come from your permission model, you decide who's allowed to talk and listen — no separate identity system to maintain.

Add voice to your game — voice on Pro, from $49/mo

Get your API key →

Related