rich-lion-2482
07/22/2025, 4:27 PMtall-airline-16756
07/22/2025, 4:27 PMtall-airline-16756
07/22/2025, 4:30 PMdeleteRoom API. This will end the session for everyone and remove the room from the server, preventing users from remaining in a silent room until they hang up.
Recommended approach:
1. Create a server-side API endpoint that calls deleteRoom using the LiveKit server SDK. For example, in a Next.js API route:
import { RoomServiceClient } from 'livekit-server-sdk';
import { NextRequest, NextResponse } from 'next/server';
export async function POST(req: NextRequest) {
const { roomName } = await req.json();
const { LIVEKIT_API_KEY, LIVEKIT_API_SECRET, LIVEKIT_URL } = process.env;
const roomService = new RoomServiceClient(
LIVEKIT_URL!,
LIVEKIT_API_KEY!,
LIVEKIT_API_SECRET!
);
await roomService.deleteRoom(roomName);
return new NextResponse(null, { status: 200 });
}
1. Call this endpoint from your TypeScript client when the LLM finishes:
const endRoomForEveryone = async (roomName: string) => {
await fetch('/api/end-room', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ roomName }),
});
};
// Usage when LLM finishes
await endRoomForEveryone(room.name);
This ensures all participants are disconnected and the room is fully closed when your LLM session ends.
If you only call room.disconnect() on the client, it will disconnect just that client, but the room will remain open for others. Using deleteRoom is the recommended way to end the session for everyone.rich-lion-2482
07/22/2025, 4:32 PMtall-airline-16756
07/22/2025, 4:33 PM