kind-iron-94532
08/06/2025, 4:44 AMtall-airline-16756
08/06/2025, 4:44 AMtall-airline-16756
08/06/2025, 4:45 AMClose()
and closeWithHangup()
for call termination.
If you need further assistance with implementing these methods, let me know!
Sources: SIP overview | LiveKit Docs | Create and configure Telnyx SIP trunk | LiveKit Docs | Accepting incoming calls | LiveKit Docs | pkg/sip/inbound.go | Agents telephony integration | LiveKit Docskind-iron-94532
08/06/2025, 4:46 AMtall-airline-16756
08/06/2025, 4:47 AMcloseWithHangup
method in LiveKit is all about ending inbound SIP calls when you decide to hang up. Here’s a quick rundown of what it does:
• State Update: It updates the call state by setting the DisconnectReason
to CLIENT_INITIATED
, so everyone knows the client ended the call.
• Call Termination: It calls the internal close
method to wrap things up nicely—this includes sending SIP BYE messages, freeing up media resources, and removing the participant from the room.
• Resource Cleanup: It makes sure all resources like media ports and room data are tidied up properly.
• Usage: You’d typically use this method when hanging up during an active call or closing the LiveKit room yourself.
If you want me to walk you through it or help with implementing this method, just let me know—I’m here to help!
Sources: pkg/sip/inbound.gokind-iron-94532
08/06/2025, 5:02 AMtall-airline-16756
08/06/2025, 5:03 AMcloseWithHangup
method isn’t available. No worries though! You can handle SIP call hangups using these approaches:
• Using the end_call
Method: This one removes the participant from the room and ends the call. Here’s a little example:
from livekit import api
class CallActions:
async def hangup(self):
try:
await self.api.room.remove_participant(api.RoomParticipantIdentity(
room=self.room.name,
identity=self.participant.identity,
))
except Exception as e:
<http://logger.info|logger.info>(f"Error while ending call: {e}")
async def end_call(self):
<http://logger.info|logger.info>(f"Ending the call for {self.participant.identity}")
await self.hangup()
• Deleting the Room: If you want to end the call for everyone in the room, you can delete the room like this:
from livekit import api
class CallActions:
async def end_call(self):
<http://logger.info|logger.info>(f"Ending the call for {self.participant.identity}")
await context.session.generate_reply(
instructions="Thank you for your time. I'll be ending this call now. Goodbye!"
)
job_ctx = get_job_context()
await job_ctx.api.room.delete_room(
api.DeleteRoomRequest(room=job_ctx.room.name)
)
If you’d like a hand implementing these or have any other questions, just let me know—I’m here to help!
Sources: Making calls using SIP | LiveKit Docs | Agents telephony integration | LiveKit Docs | telephony/sip_lifecycle.pyminiature-yacht-61157
08/06/2025, 8:33 AMtall-airline-16756
08/06/2025, 8:33 AMkind-iron-94532
08/06/2025, 9:27 AMasync def _end_call(self, reason: str = "", msg: str = ""):
"""
End the current call.
"""
if msg:
await self.session.say(text=msg, allow_interruptions=False)
time_to_wait = get_time_to_wait_for_playout(msg)
await asyncio.sleep(time_to_wait)
if reason:
<http://logger.info|logger.info>(f"Ending call for reason: {reason}")
job_ctx = agents.get_job_context()
await job_ctx.api.room.delete_room(api.DeleteRoomRequest(room=job_ctx.room.name))
return "Call has been ended."