DNZ Digita
← Back to Voice docs

DNZ Voice Docs

Web & JavaScript Integration

Your website backend issues the RTC Token. The browser never holds the API key. Load the SDK from your voice-api /demo/sdk/ bundle or copy it into your build.

Architecture

1) User clicks Join in your UI.

2) Your backend creates or reuses a channelName and returns { channelName, token }.

3) Browser calls DNZVoiceClient.join({ roomId: channelName, token, displayName }).

Example (browser)

SDK path on production: https://voice-api.dnzteam.online/demo/sdk/

import { DNZVoiceClient } from "./dnz-voice-sdk/index.js";

// token + iceServers from YOUR backend endpoint
const { channelName, token, iceServers } = await fetch("/api/voice/join").then(r => r.json());

const client = new DNZVoiceClient({
  serverUrl: "https://voice-api.dnzteam.online",
});

const room = await client.join({
  roomId: channelName,
  token,
  displayName: "Guest",
  iceServers, // real STUN/TURN, forwarded from the token response
});

room.on("peerJoined", (peer) => console.log(peer.displayName));

Backend route (Node.js / Next.js)

Protect this route with your user session. Use the API key only here.

// app/api/voice/join/route.ts
export async function POST(req) {
  const user = await getSessionUser(req);
  const channelName = "room_" + user.classId;

  const tokenRes = await fetch(
    `https://voice-api.dnzteam.online/v1/channels/${channelName}/token`,
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.DNZ_VOICE_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        uid: user.id,
        displayName: user.name,
        role: "speaker",
      }),
    }
  );
  const data = await tokenRes.json();
  return Response.json({ channelName, token: data.token, iceServers: data.iceServers });
}

Related content

Support