DNZ Digita
← Back to Voice docs

DNZ Voice Docs

Node.js Backend Integration

Use fetch or axios from your Node 18+ server. Keep DNZ_VOICE_API_KEY in .env.

Environment

DNZ_VOICE_API_KEY=dnz_vk_…

DNZ_VOICE_API_URL=https://voice-api.dnzteam.online

Create channel on room start

Call this when a user starts or enters a voice session on your platform.

import express from "express";
const app = express();

app.post("/voice/session", async (req, res) => {
  const { channelName } = req.body;
  const r = await fetch(process.env.DNZ_VOICE_API_URL + "/v1/channels", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.DNZ_VOICE_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ channelName, maxPeers: 30, mode: "open" }),
  });
  if (r.status === 402) return res.status(402).json({ error: "quota_exceeded" });
  const data = await r.json();
  res.json(data);
});

Mint token for user

Issue a unique RTC Token per user before they join the channel.

app.post("/voice/token", async (req, res) => {
  const { channelName, uid, displayName, role } = req.body;
  const r = await fetch(
    `${process.env.DNZ_VOICE_API_URL}/v1/channels/${channelName}/token`,
    {
      method: "POST",
      headers: {
        Authorization: "Bearer " + process.env.DNZ_VOICE_API_KEY,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ uid, displayName, role: role ?? "speaker" }),
    }
  );
  res.json(await r.json());
});

Related content

Support