Skip to content

WebRTC Setup

Add browser and mobile calling with the WebRTC SDK.

The WebRTC SDK turns a browser tab or mobile app into a fully featured endpoint on your account: it can register as an extension, receive queue calls and place outbound calls, with media encrypted end to end to the platform edge.

Install and connect

webrtc.ts

import { VoiceClient } from "@gtalk2voip/webrtc";

const client = new VoiceClient({
  // Short-lived token minted by YOUR server, never an API key
  token: await fetch("/api/voice-token").then((r) => r.text()),
});

await client.register();

client.on("incoming", (call) => {
  ringUI.show(call.from);
  answerButton.onclick = () => call.answer();
});

Minting client tokens

Browsers must never hold API keys. Your server exchanges its API key for a client token bound to one user and a set of capabilities, valid for up to 24 hours.

token-endpoint.ts

app.get("/api/voice-token", auth, async (req, res) => {
  const token = await gtalk.tokens.create({
    identity: req.user.id,
    capabilities: ["calls:receive", "calls:place"],
    ttl: 3600,
  });
  res.send(token.value);
});

Production checklist

  • Serve your app over HTTPS; browsers refuse microphone access on plain HTTP.
  • Handle the permission prompt: register only after a user gesture, and surface a retry path when access is denied.
  • Leave ICE servers at the SDK default; the platform provides TURN in every region for callers behind strict NATs.
  • Test on real mobile networks. The SDK reconnects automatically, but your UI should show the connection state it reports.