quaint-daybreak-28499
12/19/2025, 7:29 PMtall-airline-16756
12/19/2025, 7:29 PMtall-airline-16756
12/19/2025, 7:29 PMctx.shutdown('reason') to disconnect and allow pending work to finish. This cleanly ends the session from the agent side.
2) Run cleanup logic
• Register shutdown callbacks with ctx.addShutdownCallback(() => { ... }) to persist state, stop timers, close DB connections, free file handles, or remove temp files.
3) (Optional) End the room for everyone
• If you want to end the meeting for all participants, call the Room service API to delete the room:
const roomServiceClient = new RoomServiceClient(
process.env.LIVEKIT_URL,
process.env.LIVEKIT_API_KEY,
process.env.LIVEKIT_API_SECRET,
);
await roomServiceClient.deleteRoom(roomName);
Quick checklist before shutdown:
• Stop or release media tracks and streams if you created them.
• Flush or save any queued data or logs.
• Close network/db connections and cancel timers.
If you want, tell me which parts you’re using (agent SDK, participant client, or room service) and I’ll provide a short code example tailored to your setup.
Sources: Job lifecycle | LiveKit docsquaint-daybreak-28499
12/19/2025, 7:30 PMtall-airline-16756
12/19/2025, 7:31 PMawait roomServiceClient.deleteRoom(roomName); will run once the delete completes.
Example:
await roomServiceClient.deleteRoom(roomName);
console.log('Room deleted — now running post-delete tasks');
// run cleanup, notify users, close connections, etc.
Notes:
• If deleteRoom throws, wrap in try/catch to handle errors before running post-delete logic.
• If you need to run something regardless of success/failure, use finally.
• For ordered async work, await each step so each completes before the next runs.
Want a small example showing try/catch/finally for your exact use case?
Sources: Managing rooms | LiveKit docs | Job lifecycle | LiveKit docs