How to detect if the user is idle and disconnect the room

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

How can I detect if the agent is idle and disconnect the room if the user doesn’t speak for 5 minutes?

We have an example specifically for this use case:

This example shows how to track user inactivity and take action (like disconnecting) after a timeout period.

Note: Calling session.shutdown() disconnects the audio stream but doesn’t delete the room. If you need to fully close the room, use the Room API to delete it.