Daily.co Integration for Video Calls on Website
Daily.co provides WebRTC infrastructure with a simple JavaScript SDK. You create a room via REST API, send the URL to the user—they open a video call directly in the browser without installing an app. Suitable for video consultations, support chats, training.
Creating a Room via REST API
const DAILY_API_KEY = process.env.DAILY_API_KEY;
async function createRoom(options: {
name?: string;
expiresInMinutes?: number;
maxParticipants?: number;
}): Promise<{ url: string; name: string }> {
const response = await fetch('https://api.daily.co/v1/rooms', {
method: 'POST',
headers: {
'Authorization': `Bearer ${DAILY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: options.name ?? `room-${Date.now()}`,
properties: {
exp: Math.floor(Date.now() / 1000) + (options.expiresInMinutes ?? 60) * 60,
max_participants: options.maxParticipants ?? 10,
enable_screenshare: true,
enable_chat: true,
enable_recording: false,
start_video_off: false,
start_audio_off: false,
},
}),
});
const room = await response.json();
return { url: room.url, name: room.name };
}
// API for session creation
app.post('/api/video/room', authenticate, async (req, res) => {
const { consultationId } = req.body;
const room = await createRoom({
name: `consultation-${consultationId}`,
expiresInMinutes: 90,
maxParticipants: 2,
});
await db.consultations.update(consultationId, { roomUrl: room.url });
res.json({ url: room.url });
});
Participant Token
For private rooms, you need a meeting token—otherwise anyone with the URL can join:
async function createMeetingToken(roomName: string, participantName: string, isOwner = false) {
const response = await fetch('https://api.daily.co/v1/meeting-tokens', {
method: 'POST',
headers: {
'Authorization': `Bearer ${DAILY_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
properties: {
room_name: roomName,
user_name: participantName,
is_owner: isOwner, // owner can remove other participants
exp: Math.floor(Date.now() / 1000) + 90 * 60,
enable_recording: isOwner,
},
}),
});
const { token } = await response.json();
return token;
}
React Component with Daily JS SDK
npm install @daily-co/daily-js
import DailyIframe from '@daily-co/daily-js';
import { useEffect, useRef, useState } from 'react';
interface VideoCallProps {
roomUrl: string;
token: string;
userName: string;
onLeave?: () => void;
}
function VideoCall({ roomUrl, token, userName, onLeave }: VideoCallProps) {
const callRef = useRef<ReturnType<typeof DailyIframe.createFrame> | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
const [status, setStatus] = useState<'idle' | 'joining' | 'joined' | 'left'>('idle');
useEffect(() => {
if (!containerRef.current) return;
const call = DailyIframe.createFrame(containerRef.current, {
showLeaveButton: true,
showFullscreenButton: true,
iframeStyle: { width: '100%', height: '100%', border: 'none', borderRadius: '12px' },
});
callRef.current = call;
call.on('joining-meeting', () => setStatus('joining'));
call.on('joined-meeting', () => setStatus('joined'));
call.on('left-meeting', () => {
setStatus('left');
onLeave?.();
});
call.on('error', (err) => console.error('Daily error:', err));
call.join({ url: roomUrl, token, userName });
return () => {
call.destroy();
};
}, [roomUrl, token]);
return (
<div className="relative" style={{ height: 600 }}>
{status === 'joining' && (
<div className="absolute inset-0 flex items-center justify-center bg-gray-900 rounded-xl z-10">
<p className="text-white">Connecting...</p>
</div>
)}
{status === 'left' && (
<div className="absolute inset-0 flex items-center justify-center bg-gray-900 rounded-xl z-10">
<p className="text-white text-lg">Call ended</p>
</div>
)}
<div ref={containerRef} className="w-full h-full" />
</div>
);
}
Webhooks for Events
Daily.co sends events to your server:
app.post('/api/webhooks/daily', async (req, res) => {
const { event_type, payload } = req.body;
switch (event_type) {
case 'meeting.started':
await db.videoSessions.markStarted(payload.room.name);
break;
case 'meeting.ended':
await db.videoSessions.markEnded(payload.room.name, {
duration: payload.meeting_duration,
});
break;
case 'participant.joined':
await db.videoSessions.addParticipant(payload.room.name, payload.participant.user_name);
break;
}
res.status(200).end();
});
Timeline
Basic Daily.co integration with room creation and iframe—1–2 days. With tokens, webhooks, and recording—3–4 days.







