steep-shampoo-86436
12/29/2025, 6:39 PMtall-airline-16756
12/29/2025, 6:39 PMtall-airline-16756
12/29/2025, 6:39 PMawait room.disconnect() in the browser. This unpublishes local tracks, unsubscribes from remote tracks, and releases media devices and WebAudio contexts.
• After disconnect completes, clear any room/participant state and unmount components tied to the room to drop React references and avoid leaks.
2) Backend — end the room and stop egress/agents
• From your server, call the Room deletion API to force the room to end (for example, RoomServiceClient.deleteRoom(roomName) using the server SDK). This causes remaining participants (AI agent) and egress/recording to be terminated server-side and ensures recordings stop cleanly.
• If your AI agent runs as a separate job/process, ensure it listens for the room-deleted event or you invoke its shutdown hook so it can save state and exit.
3) Optional but recommended
• If you start recordings/egress separately, explicitly stop egress before or when deleting the room to ensure finalization of recording files.
• Ensure any agent-side shutdown callbacks run (e.g., save logs, close DB connections).
• Return a short “meeting ended” acknowledgement to the UI once both client disconnect and room deletion succeed.
Minimal sequence to implement
1. Frontend: await room.disconnect() → cleanup UI/state.
2. Backend: call deleteRoom(roomName) → stops AI agent and recording.
If you want, tell me:
• which LiveKit SDK you’re using on the server (Node/TS, other), and
• whether your AI agent is a separate process or a LiveKit server-side job—
and I’ll give exact code snippets for both the frontend and server steps.
Sources: Job lifecycle | LiveKit docs | Stream music over WebRTC using React and WebAudiosteep-shampoo-86436
12/29/2025, 6:46 PMtall-airline-16756
12/29/2025, 6:46 PMawait room.disconnect() — frees the human’s media tracks, unsubscribes from remote tracks, and clears browser audio/WebRTC resources immediately.
• Backend: 1) stop recording/egress — ensures the recording is finalized and files are properly closed. 2) deleteRoom(roomName) — forces remaining participants (AI agent) out and tears down the room/server-side resources.
Notes and small precautions:
• Stopping egress before deleting the room ensures the recording finalizes cleanly; deleting the room first can still stop egress, but explicit stop avoids partial or delayed finalization.
• Return success from each step to the client so the UI can show a definitive “ended” state (disconnect confirmed → egress stopped → room deleted).
• If your AI agent needs time to save state, have it listen for room-deleted events or run a shutdown hook so it can finish work before exit.
If you want, I can provide example Node/TS snippets for stopping egress and calling deleteRoom. Which server SDK are you using?steep-shampoo-86436
12/29/2025, 6:48 PMtall-airline-16756
12/29/2025, 6:48 PMawait room.disconnect() — free browser media and UI state.
2. Backend: call StopEgress (explicit stop) — ensure the recording is muxed and uploaded cleanly.
3. Backend: call DeleteRoom(roomName) — tear down the room and force remaining participants out.
Notes
• Stopping egress first gives you a clear success/failure response to act on (e.g., retry on failure).
• If your workflow cannot call StopEgress (rare), DeleteRoom will still stop recording but accept the increased risk above.
• If you want, I can provide Node/TS snippets for calling StopEgress and DeleteRoom for your server SDK. Which SDK are you using? Sources: Job lifecycle | LiveKit docs | Universal Egress | server-sdk-js | livekit/livekit_composite | DeepWiki | Server-side | livekit/livekit_composite | DeepWiki