When the room exists and conversation is active, i...
# ask-ai
h
When the room exists and conversation is active, it happens to me that when user logs out for a while or closes a browser, the agent remains active for approximately 20 seconds. If user manages to get back within this interval, the conversation continues as usually. If it is longer, for example one minute, I receive the following log and then I must manually dispatch the agent again, because the room still exists. How to make the reconnection interval longer or how to delete the room on user's logout/disconnection. When I set explicitly "await deleteRoom" on user disconnection, very often the room is not deleted.
Copy code
[12:04:28.956] INFO (616): job completed.

jobID: "AJ_Rs7FQ4WCsNxb"

[12:04:28.956] INFO (616): Job process shutdown

jobID: "AJ_Rs7FQ4WCsNxb"
t
Thanks for reaching out, Pavel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To address your concerns about reconnection intervals and room deletion in LiveKit, here are the details: Reconnection Intervals LiveKit uses a
ReconnectPolicy
interface to control client reconnection behavior. This policy includes a method called
nextRetryDelayInMs
, which determines the time interval between reconnection attempts. You can customize this interval by implementing the
ReconnectPolicy
interface and adjusting the
nextRetryDelayInMs
method. Returning
null
from this method will stop reconnection attempts. Deleting a Room on User Logout/Disconnection When a user logs out or disconnects, you have two options: 1. Disconnect just the agent: This allows other participants to continue in the room. Use the following code:
Copy code
async def entrypoint(ctx: JobContext):
    # do some work
    ...
    # disconnect from the room
    ctx.shutdown(reason="Session ended")
2. Delete the entire room: This disconnects everyone and removes the room from the server. Use the following code:
Copy code
from livekit import api

async def entrypoint(ctx: JobContext):
    # do some work
    ...
    api_client = api.LiveKitAPI(
        os.getenv("LIVEKIT_URL"),
        os.getenv("LIVEKIT_API_KEY"),
        os.getenv("LIVEKIT_API_SECRET"),
    )
    await api_client.room.delete_room(api.DeleteRoomRequest(
        room=ctx.job.room.name,
    ))
When you delete a room, a
Disconnected
room event will be sent to all participants, and the room will be removed from the server. If you need further assistance or clarification, feel free to ask! Sources: GitHub::livekit::livekit_composite | livekit/client-sdk-swift/Sources/LiveK... | Inside a session | LiveKit Docs