Video conference with React
A complete call UI in a few lines with the React components.
@dtelecom/components-react gives you a ready call interface: participant grid, control bar, screen share and chat. You can ship it as is or build your own layout from the smaller components and hooks.
The component names keep their LiveKit names, such as LiveKitRoom, so existing LiveKit React code moves over with a package rename.
Install
Section titled “Install”npm install @dtelecom/components-react @dtelecom/components-styles @dtelecom/livekit-client@1.12.28The whole call in one component
Section titled “The whole call in one component”import '@dtelecom/components-styles';import { LiveKitRoom, VideoConference } from '@dtelecom/components-react';
export type RoomSession = { token: string; wsUrl: string; fallbackUrls?: string[] };
export function Call({ token, wsUrl, fallbackUrls, onLeave }: RoomSession & { onLeave: () => void }) { return ( <LiveKitRoom token={token} serverUrl={wsUrl} connectOptions={{ fallbackUrls }} connect={true} audio={true} video={true} onDisconnected={onLeave} data-lk-theme="default" style={{ height: '100vh' }} > <VideoConference /> </LiveKitRoom> );}Save the component above as Call.tsx. Return token, wsUrl and fallbackUrls from your backend’s createToken response and fetch them before rendering the component. connectOptions passes the ranked signaling URLs to the room SDK.
A token lasts 6 hours by default. For longer calls your backend extends it with extendToken before it expires; the name and metadata are kept. A participant whose token expired is removed about a minute later, and onDisconnected fires.
Fetch the token
Section titled “Fetch the token”import { useEffect, useState } from 'react';import type { RoomSession } from './Call';
export function useSession(room: string, user: string) { const [session, setSession] = useState<RoomSession | null>(null);
useEffect(() => { let cancelled = false; fetch(`/api/token?room=${encodeURIComponent(room)}&user=${encodeURIComponent(user)}`) .then((res) => res.json()) .then((data) => { if (!cancelled) setSession(data); }); return () => { cancelled = true; }; }, [room, user]);
return session;}Every token takes a concurrent participant slot from the moment it is issued, and an unused token holds the slot until it expires. In development React StrictMode runs useEffect twice, so this hook issues two tokens. Abort the extra request, or fetch the token on a user action such as a Join button.
Build your own layout
Section titled “Build your own layout”Use the smaller pieces when the default UI does not fit.
import '@dtelecom/components-styles';import { ControlBar, GridLayout, LiveKitRoom, ParticipantTile, RoomAudioRenderer, useTracks,} from '@dtelecom/components-react';import { Track } from '@dtelecom/livekit-client';import type { RoomSession } from './Call';
function Stage() { const tracks = useTracks( [ { source: Track.Source.Camera, withPlaceholder: true }, { source: Track.Source.ScreenShare, withPlaceholder: false }, ], { onlySubscribed: false }, ); return ( <GridLayout tracks={tracks} style={{ height: 'calc(100vh - 80px)' }}> <ParticipantTile /> </GridLayout> );}
export function CustomCall({ token, wsUrl, fallbackUrls }: RoomSession) { return ( <LiveKitRoom token={token} serverUrl={wsUrl} connectOptions={{ fallbackUrls }} connect={true} audio={true} video={true} data-lk-theme="default" > <Stage /> <RoomAudioRenderer /> <ControlBar /> </LiveKitRoom> );}RoomAudioRenderer plays everyone’s audio. Without it, or without VideoConference, the call is silent.
import { Chat, LiveKitRoom } from '@dtelecom/components-react';import type { RoomSession } from './Call';
export function CallWithChat({ token, wsUrl, fallbackUrls }: RoomSession) { return ( <LiveKitRoom token={token} serverUrl={wsUrl} connectOptions={{ fallbackUrls }} connect={true} data-lk-theme="default" > <Chat /> </LiveKitRoom> );}The participant’s token needs canPublishData, which is on by default. For a custom chat UI use the useChat hook; see Data messages and chat.
Handle device errors
Section titled “Handle device errors”import { LiveKitRoom, VideoConference } from '@dtelecom/components-react';import type { RoomSession } from './Call';
export function SafeCall({ token, wsUrl, fallbackUrls }: RoomSession) { return ( <LiveKitRoom token={token} serverUrl={wsUrl} connectOptions={{ fallbackUrls }} connect={true} audio={true} video={true} onError={(err) => console.error('room error', err)} onMediaDeviceFailure={(failure) => console.error('camera or microphone unavailable', failure)} > <VideoConference /> </LiveKitRoom> );}Next.js notes
Section titled “Next.js notes”- Components that use the room must be client components: put
'use client'at the top of the file. - Create tokens in a route handler or a server action, never in a client component. The API secret must stay on the server.
Example apps
Section titled “Example apps”- dtelecom-meet: a Google Meet style app with a pre-join screen, host controls and chat.
A participant on iOS or Android can scan or paste a hosted Meet invite in the React Native example to join the same meeting.
It runs on dTelecom Cloud as is: set DTELECOM_API_KEY, DTELECOM_API_SECRET and DTELECOM_CLOUD_URL, or use the Deploy to Vercel button in its README. See Examples.