if participant.kind == rtc.ParticipantKind.PARTICI...
# ask-ai
e
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP: how can i check if sip participant is inbound call or outbound call.
t
Thanks for reaching out, Shehryar. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you figure out whether a SIP participant is on an inbound or outbound call, you can use the
SIPCallDirection
enum. This enum clearly defines the call direction with these values: •
SCD_INBOUND
for inbound calls •
SCD_OUTBOUND
for outbound calls This approach is the most straightforward and reliable way to identify the call direction. If you have any questions or need more help, please don’t hesitate to ask—I’m here for you! Sources: livekit/livekit_sip.pb.go | SIP participant | LiveKit Docs | livekit-protocol/livekit/protocol/sip.pyi
e
can you provide the python code.
t
I'd love to share a helpful Python code example that shows you how to check if a SIP participant is an inbound or outbound call:
Copy code
from livekit import rtc

def check_sip_call_direction(participant):
    """
    Check if a SIP participant represents an inbound or outbound call
    by examining the participant attributes.
    
    Args:
        participant: LiveKit participant object
    Returns:
        str: "inbound" or "outbound"
    """
    if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
        # Inbound calls have a ruleID attribute, outbound calls do not
        if 'sip.ruleID' in participant.attributes:
            return "inbound"
        else:
            return "outbound"
    return None

# Example usage in a participant connected handler:
async def on_participant_connected(participant: rtc.RemoteParticipant):
    if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
        direction = check_sip_call_direction(participant)
        print(f"SIP participant connected: {participant.identity}")
        print(f"Call direction: {direction}")
This snippet works by checking the
sip.ruleID
attribute to figure out the call direction. Typically, inbound calls have this attribute, while outbound calls don’t. If anything feels unclear or if you want me to walk you through it step-by-step, just let me know—I’m here to help! Sources: SIP participant | LiveKit Docs | telephony/sip_lifecycle.py