Hi when I stop the frontend and agent server, the ...
# ask-ai
a
Hi when I stop the frontend and agent server, the room is still running in livekit cloud. How to cleanup room when the client or agent are disconnected.
t
Thanks for reaching out, Satvik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
When it comes to cleaning up a room in LiveKit Cloud after a client or agent disconnects, you have a few helpful options to consider: • Disconnecting Only the Agent: You can use the
ctx.shutdown()
method to gracefully disconnect the agent, while still allowing other participants to stay connected. This will take care of the necessary cleanup for the agent. • Ending the Entire Room Session: If you want to close the whole room, the Server API’s
deleteRoom
method is the way to go. This will disconnect everyone and fully terminate the room. • Automatic Room Cleanup: LiveKit is designed to automatically close a room once the last non-agent participant leaves, as long as the room has been empty for longer than the set timeout. If you’d like more precise control, using the Server API to delete the room whenever you need is a great option. Please feel free to reach out if you’d like any help implementing these methods—I’m here to support you! Sources: Inside a session | LiveKit Docs | Job lifecycle | LiveKit Docs | examples/voice_agents/session_close_callback.py | Anatomy of an Agent | LiveKit Docs
a
when I reload the page in frontend i am disconnected from the room and not able to reconnect to the room
t
I understand that reloading the frontend page disconnects you from the room because the
Room.disconnect()
method is automatically called when the application exits or reloads. This is actually expected behavior in LiveKit, so you’re not alone in encountering this. To get back in, you’ll want to reinitialize the room connection after the page reload. Make sure your frontend code is set up to handle reconnection by rejoining the room with the right credentials and settings. If you’d like, I’m here to help you with the reconnection logic—just let me know, and we can work through it together! Sources: Connecting to LiveKit | LiveKit Docs