early-afternoon-97327
05/13/2025, 1:06 PMhow can i delete room on pariticpant disconnet
tall-airline-16756
05/13/2025, 1:06 PMtall-airline-16756
05/13/2025, 1:06 PMctx.shutdown()
method to disconnect just the agent from the room, allowing other participants to continue in the session: async def entrypoint(ctx: JobContext):
# do some work
...
# disconnect from the room
ctx.shutdown(reason="Session ended")
2. Disconnecting everyone and deleting the room: Use the server API's deleteRoom
method to end the session for everyone and remove the room from the server: 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,
))
This will send a Disconnected
room event to all participants and remove the room from the server.
You can detect when a participant disconnects using the appropriate event handler for your platform, such as the room(_:participantDidDisconnect:)
delegate method in the Swift SDK.
Sources: Inside a session | LiveKit Docs | room(_:participantDidDisconnect:) | Documentationearly-afternoon-97327
05/13/2025, 1:08 PMtall-airline-16756
05/13/2025, 1:08 PMdelete_room
API to end the session for all participants. Here is an example implementation:
# Add these imports at the top of your file
from livekit import api, rtc
from livekit.agents import get_job_context
# Add this function definition anywhere
async def hangup_call():
ctx = get_job_context()
if ctx is None:
# Not running in a job context
return
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
class MyAgent(Agent):
# Your agent implementation
@function_tool
async def end_call(self, ctx: RunContext):
"""Called when the user wants to end the call"""
# let the agent finish speaking
current_speech = ctx.session.current_speech
if current_speech:
await current_speech.wait_for_playout()
await hangup_call()
When the delete_room
API is called, the Disconnected
room event will be sent with a reason of ROOM_DELETED
, and the room will be removed from the server, effectively ending the call for all participants.
Sources: Agents telephony integration | LiveKit Docs | Inside a session | LiveKit Docsearly-afternoon-97327
05/13/2025, 1:09 PMhow can i get discount event if participant event
tall-airline-16756
05/13/2025, 1:09 PMpublic delegate void ParticipantDisconnectedDelegate(RemoteParticipant participant);
• Swift SDK: optional func room(_ room: Room, participantDidDisconnect participant: RemoteParticipant)
• Android SDK: class ParticipantDisconnected(val room: Room, val participant: RemoteParticipant) : RoomEvent
• Flutter SDK: ParticipantDisconnectedEvent({required RemoteParticipant participant})
This event is triggered when a RemoteParticipant
leaves the room, allowing your application to respond appropriately to participant disconnections.
Sources: Delegate Room.ParticipantDisconnectedDelegate | LiveKit Unity SDK | room(_:participantDidDisconnect:) | Documentation | ParticipantDisconnected | ParticipantDisconnectedEvent class - livekit_client library - Dart APIearly-afternoon-97327
05/13/2025, 1:10 PMcan you provide python code
tall-airline-16756
05/13/2025, 1:10 PMgreen-rocket-44814
05/21/2025, 9:09 PMgreen-rocket-44814
05/21/2025, 9:09 PM