fierce-zoo-69908
08/19/2025, 11:12 AMtall-airline-16756
08/19/2025, 11:12 AMtall-airline-16756
08/19/2025, 11:13 AMdelete_room
API. This will end the call for everyone and tidy up the room, making sure the last participant disconnects smoothly.
Here’s a little example to show you how it works:
from livekit import api
async def hangup_call(ctx):
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
Another option is to keep an eye on when participants leave and automatically wrap up the call once only one is left. If you want, I’m happy to walk you through that too or help with any part of the setup!
Sources: Job lifecycle | LiveKit Docs | examples/voice_agents/error_callback.py | Agents telephony integration | LiveKit Docs | telephony/sip_lifecycle.pyfierce-zoo-69908
08/19/2025, 11:13 AMtall-airline-16756
08/19/2025, 11:14 AMroom_empty_future: asyncio.Future[None] = asyncio.get_running_loop().create_future()
def _on_participant_disconnected(_: rtc.Participant, fut=room_empty_future) -> None:
if len(ctx.room.remote_participants) == 0 and not fut.done():
fut.set_result(None)
ctx.room.on("participant_disconnected", _on_participant_disconnected)
Other SDKs: You’ll find similar event handlers in the Swift and Flutter SDKs that help you track when participants leave.
Another handy option is using webhooks to get "Participant Left" events on your server in real-time. If you want, I’d be happy to walk you through any specific setup or answer any questions you have!
Sources: livekit-agents/livekit/agents/voice/room_io/room_io.py | Sources/LiveKit/Protocols/RoomDelegate.swift | lib/src/events.dart | Webhooks | LiveKit Docs | Anatomy of an Agent | LiveKit Docsfierce-zoo-69908
08/19/2025, 11:33 AMroom_empty_future: asyncio.Future[None] = asyncio.get_running_loop().create_future()
def _on_participant_disconnected(_: rtc.Participant, fut=room_empty_future) -> None:
ctx.room.on("participant_disconnected", _on_participant_disconnected)
tall-airline-16756
08/19/2025, 11:34 AMfierce-zoo-69908
08/19/2025, 11:35 AM