what is general instruction for ROOM. should it be...
# ask-ai
a
what is general instruction for ROOM. should it be persistent or ephemeral?
t
Thanks for reaching out, Jaihee. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks so much for reaching out! Could you share a bit more about how you plan to use the rooms? For instance, are you thinking about setting up rooms for one-time events, recurring meetings, or maybe something different? Understanding this will really help us figure out whether a persistent or ephemeral room would be the best fit for you.
a
in using web client, and i want to user keep connected after refresh and make agent persistent. But currently room is exploded as soon as user refreshes the page
t
I'm glad you're looking to keep your LiveKit room persistent and ensure users stay connected even after a page refresh. Here’s a friendly guide to help you through it: • Room Persistence: Rooms stay active as long as at least one participant is connected. To avoid the room closing when it’s empty, you can set the
emptyRoomTimeout
on the server side to delay closing, or consider using a bot to keep the room alive. • Reconnection After Refresh: A handy approach is to save the room and user details (like the room name and user identity) in
localStorage
or
sessionStorage
. Then, when the page reloads, you can retrieve these details and re-authenticate with a new or refreshed token. • Automatic Reconnection: LiveKit is designed to help by automatically reconnecting after network drops and refreshing tokens to keep sessions going smoothly. Just make sure your client asks your backend for a fresh token after a refresh. If you'd like, I’d be happy to walk you through an example of how to set up token generation or manage state persistence in your web client. Just let me know! Sources: agent-console/app/room/page.tsx | Connecting to LiveKit | LiveKit Docs | Authentication | LiveKit Docs
a
but agent is leaving the room
t
I’m here to help you keep the agent persistent in the room, even when other participants disconnect or refresh. Here’s how you can do that: • Disable Auto-Close Behavior: Simply set
closeOnDisconnect
to
false
in the room's input options. This way, the agent session won’t end when the last participant leaves. • Configure Server-Side Timeouts: You can adjust the
empty_timeout
and
departure_timeout
settings in your LiveKit server configuration (
livekit.yaml
). For instance, setting these to 300 seconds will keep the room open for 5 minutes after it becomes empty. • Manual Cleanup: It’s a good idea to add some logic to manually end the agent session when needed, like after some inactivity or based on your own custom conditions. If you’d like, I’d be happy to walk you through the detailed steps to configure these settings or help with implementing the logic. Just let me know! Sources: agents/src/job.ts | examples/voice_agents/realtime_joke_teller.py | pkg/rtc/room.go | packages/livekit-rtc/src/room.ts