Docs Quickstart
GETTING STARTED

Universal Quickstart Guide

Integrate real-time voice, video, and screen sharing into any technology stack in minutes. Mint an isolated room session token on your backend server and connect clients via dedicated WebRTC SFU.

Kynitik REST API Gateway is live at https://kynitik.com/api/v1. WebRTC SFU signaling is active at wss://kynitik.com/rtc.

Step 1: Mint Session Token (Backend)

Send an authenticated POST request to https://kynitik.com/api/v1/rooms/token with your API Key and Secret headers. Select your backend language below:

// app/api/room/token/route.js (Next.js App Router)
import { NextResponse } from 'next/server';

export async function POST(req) {
  try {
    const { roomName, identity, name } = await req.json();

    const response = await fetch('https://kynitik.com/api/v1/rooms/token', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-KEY': process.env.KYNITIK_API_KEY,      // kt_live_...
        'X-API-SECRET': process.env.KYNITIK_API_SECRET // kt_sec_...
      },
      body: JSON.stringify({
        roomName: roomName || 'consultation-room-1',
        identity: identity || 'usr_' + Date.now(),
        name: name || 'Patient / Guest',
        canPublish: true,
        canSubscribe: true
      })
    });

    const data = await response.json();
    if (!response.ok) {
      return NextResponse.json({ error: data.error }, { status: response.status });
    }

    // Return token and SFU WebSocket URL to your client component
    return NextResponse.json(data);
  } catch (error) {
    return NextResponse.json({ error: 'Failed to mint token' }, { status: 500 });
  }
}

Step 2: Connect WebRTC Chamber (Frontend)

Connect the participant to the dedicated WebRTC SFU using the token and serverUrl returned by your backend. Select your client framework:

// components/LiveChamber.jsx ('use client' in Next.js App Router)
'use client';
import { useEffect, useRef, useState } from 'react';
import { Room, RoomEvent } from 'livekit-client';

export default function LiveChamber({ token, serverUrl }) {
  const containerRef = useRef(null);
  const [connected, setConnected] = useState(false);

  useEffect(() => {
    if (!token || !serverUrl) return;

    // 1. Initialize WebRTC SFU room with adaptive streaming
    const room = new Room({
      adaptiveStream: true,
      dynacast: true,
    });

    // 2. Handle remote participant video & audio tracks
    room.on(RoomEvent.TrackSubscribed, (track, publication, participant) => {
      const mediaEl = track.attach();
      mediaEl.id = 'track-' + track.sid;
      containerRef.current?.appendChild(mediaEl);
    });

    room.on(RoomEvent.TrackUnsubscribed, (track) => {
      track.detach();
      document.getElementById('track-' + track.sid)?.remove();
    });

    // 3. Connect to Kynitik WebRTC SFU and enable camera/mic
    async function connect() {
      await room.connect(serverUrl, token);
      await room.localParticipant.setCameraEnabled(true);
      await room.localParticipant.setMicrophoneEnabled(true);
      setConnected(true);
    }

    connect();
    return () => { room.disconnect(); };
  }, [token, serverUrl]);

  return (
    <div className="chamber-wrapper">
      <div className="status-badge">{connected ? '● LIVE' : 'Connecting...'}</div>
      <div ref={containerRef} className="media-grid" />
    </div>
  );
}
Launch Live Chamber Test
Need technical support or custom deployment?Contact Engineering ↗