o
    id                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z( d	Z)	 G d
d de%Z*dS )    )annotationsN)Optional)
ListUpdate)SIPOutboundConfigSIPTrunkInfoCreateSIPInboundTrunkRequestUpdateSIPInboundTrunkRequestSIPInboundTrunkInfoSIPInboundTrunkUpdateCreateSIPOutboundTrunkRequestUpdateSIPOutboundTrunkRequestSIPOutboundTrunkInfoSIPOutboundTrunkUpdateListSIPInboundTrunkRequestListSIPInboundTrunkResponseListSIPOutboundTrunkRequestListSIPOutboundTrunkResponseDeleteSIPTrunkRequestSIPDispatchRuleSIPDispatchRuleInfoSIPDispatchRuleUpdateCreateSIPDispatchRuleRequestUpdateSIPDispatchRuleRequestListSIPDispatchRuleRequestListSIPDispatchRuleResponseDeleteSIPDispatchRuleRequestCreateSIPParticipantRequestTransferSIPParticipantRequestSIPParticipantInfoSIPTransport   )Service)VideoGrants	SIPGrantsSIPc                      s  e Zd ZdZd fdd	ZdddZdddZdddZdddZdddddddddd#d$Z	dddddddddd&d'Z
dd*d+Zdd,d-Zdd.d/Zdd0d1Zdddddddd2dd7d8Zdddddddd2dd:d;Zdd?d@ZddAdBZddEdFZddGdHZddLdMZddNdOZddRdSZddTdUZddXdYZddZd[Zdddddd\ddadbZdddddd\ddcddZddgdhZddidjZddldmZddndoZ ddddpddwdxZ!dd{d|Z"dd~dZ#  Z$S )
SipServicezClient for LiveKit SIP Service API

    Recommended way to use this service is via `livekit.api.LiveKitAPI`:

    ```python
    from livekit import api
    lkapi = api.LiveKitAPI()
    sip_service = lkapi.sip
    ```
    sessionaiohttp.ClientSessionurlstrapi_key
api_secretc                   s   t  |||| d S )N)super__init__)selfr&   r(   r*   r+   	__class__ Y/var/www/html/livekit_bhavya/venv/lib/python3.10/site-packages/livekit/api/sip_service.pyr-   8      zSipService.__init__creater   returnr	   c                       | j td||  tI dH S )zCreate a new SIP inbound trunk.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP inbound trunk
        CreateSIPInboundTrunkN)_clientrequestSVC_admin_headersr	   r.   r4   r1   r1   r2   create_inbound_trunk;      
zSipService.create_inbound_trunkc                   "   t jdtdd | |I dH S )zCreate a new SIP inbound trunk.

        .. deprecated::
           Use :meth:`create_inbound_trunk` instead.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP inbound trunk
        zHcreate_sip_inbound_trunk is deprecated, use create_inbound_trunk instead   
stacklevelN)warningswarnDeprecationWarningr=   r<   r1   r1   r2   create_sip_inbound_trunkN      z#SipService.create_sip_inbound_trunktrunk_idtrunkc                   (   | j tdt||d|  tI dH S )zUpdates an existing SIP inbound trunk by replacing it entirely.

        Args:
            trunk_id: ID of the SIP inbound trunk to update
            trunk: SIP inbound trunk to update with

        Returns:
            Updated SIP inbound trunk
        UpdateSIPInboundTrunksip_trunk_idreplaceN)r8   r9   r:   r   r;   r	   r.   rH   rI   r1   r1   r2   update_inbound_trunkc      
zSipService.update_inbound_trunkc                   $   t jdtdd | ||I dH S )aM  Updates an existing SIP inbound trunk by replacing it entirely.

        .. deprecated::
           Use :meth:`update_inbound_trunk` instead.

        Args:
            trunk_id: ID of the SIP inbound trunk to update
            trunk: SIP inbound trunk to update with

        Returns:
            Updated SIP inbound trunk
        zHupdate_sip_inbound_trunk is deprecated, use update_inbound_trunk insteadr@   rA   N)rC   rD   rE   rP   rO   r1   r1   r2   update_sip_inbound_trunk|      z#SipService.update_sip_inbound_trunkNnumbersallowed_addressesallowed_numbersauth_usernameauth_passwordnamemetadatarV    Optional[ListUpdate | list[str]]rW   rX   rY   Optional[str]rZ   r[   r\   c          
        s.  t ||||d}	|dur2t|tr+|	jj|j |	jj|j |	jj|j n|	jj| |dur[t|trT|	jj|j |	jj|j |	jj|j n|	jj| |durt|tr}|	j	j|j |	j	j|j |	j	j|j n|	j	j| | j
tdt||	d|  tI dH S )zqUpdates specific fields of an existing SIP inbound trunk.

        Only provided fields will be updated.
        )rY   rZ   r[   r\   NrK   rM   update)r
   
isinstancer   rV   setextendaddremoverW   rX   r8   r9   r:   r   r;   r	   )
r.   rH   rV   rW   rX   rY   rZ   r[   r\   r`   r1   r1   r2   update_inbound_trunk_fields   sF   



z&SipService.update_inbound_trunk_fieldsOptional[list[str]]c          	   
     2   t jdtdd | j||||||||dI dH S )zUpdates specific fields of an existing SIP inbound trunk.

        .. deprecated::
           Use :meth:`update_inbound_trunk_fields` instead.

        Only provided fields will be updated.
        zVupdate_sip_inbound_trunk_fields is deprecated, use update_inbound_trunk_fields insteadr@   rA   rU   N)rC   rD   rE   rf   )	r.   rH   rV   rW   rX   rY   rZ   r[   r\   r1   r1   r2   update_sip_inbound_trunk_fields       z*SipService.update_sip_inbound_trunk_fieldsr   r   c                   r6   )zCreate a new SIP outbound trunk.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP outbound trunk
        CreateSIPOutboundTrunkN)r8   r9   r:   r;   r   r<   r1   r1   r2   create_outbound_trunk   r>   z SipService.create_outbound_trunkc                   r?   )zCreate a new SIP outbound trunk.

        .. deprecated::
           Use :meth:`create_outbound_trunk` instead.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP outbound trunk
        zJcreate_sip_outbound_trunk is deprecated, use create_outbound_trunk insteadr@   rA   N)rC   rD   rE   rl   r<   r1   r1   r2   create_sip_outbound_trunk  rG   z$SipService.create_sip_outbound_trunkc                   rJ   )a  Updates an existing SIP outbound trunk by replacing it entirely.

        Args:
            trunk_id: ID of the SIP outbound trunk to update
            trunk: SIP outbound trunk to update with

        Returns:
            Updated SIP outbound trunk
        UpdateSIPOutboundTrunkrL   N)r8   r9   r:   r   r;   r   rO   r1   r1   r2   update_outbound_trunk  rQ   z SipService.update_outbound_trunkc                   rR   )aR  Updates an existing SIP outbound trunk by replacing it entirely.

        .. deprecated::
           Use :meth:`update_outbound_trunk` instead.

        Args:
            trunk_id: ID of the SIP outbound trunk to update
            trunk: SIP outbound trunk to update with

        Returns:
            Updated SIP outbound trunk
        zJupdate_sip_outbound_trunk is deprecated, use update_outbound_trunk insteadr@   rA   N)rC   rD   rE   ro   rO   r1   r1   r2   update_sip_outbound_trunk/  rT   z$SipService.update_sip_outbound_trunkaddress	transportrV   rY   rZ   r[   r\   rr   
str | Noners   SIPTransport | Nonec          
        s   t ||||||d}	|dur4t|tr-|	jj|j |	jj|j |	jj|j n|	jj| | j	t
dt||	d|  tI dH S )zrUpdates specific fields of an existing SIP outbound trunk.

        Only provided fields will be updated.
        )rr   rs   rY   rZ   r[   r\   Nrn   r_   )r   ra   r   rV   rb   rc   rd   re   r8   r9   r:   r   r;   r   )
r.   rH   rr   rs   rV   rY   rZ   r[   r\   r`   r1   r1   r2   update_outbound_trunk_fieldsG  s2   

z'SipService.update_outbound_trunk_fieldslist[str] | Nonec          	   
     rh   )zUpdates specific fields of an existing SIP outbound trunk.

        .. deprecated::
           Use :meth:`update_outbound_trunk_fields` instead.

        Only provided fields will be updated.
        zXupdate_sip_outbound_trunk_fields is deprecated, use update_outbound_trunk_fields insteadr@   rA   rq   N)rC   rD   rE   rv   )	r.   rH   rr   rs   rV   rY   rZ   r[   r\   r1   r1   r2    update_sip_outbound_trunk_fieldsr  rj   z+SipService.update_sip_outbound_trunk_fieldslistr   r   c                   r6   )zList SIP inbound trunks with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP inbound trunks
        ListSIPInboundTrunkN)r8   r9   r:   r;   r   r.   ry   r1   r1   r2   list_inbound_trunk  r>   zSipService.list_inbound_trunkc                   r?   )a  List SIP inbound trunks with optional filtering.

        .. deprecated::
           Use :meth:`list_inbound_trunk` instead.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP inbound trunks
        zDlist_sip_inbound_trunk is deprecated, use list_inbound_trunk insteadr@   rA   N)rC   rD   rE   r|   r{   r1   r1   r2   list_sip_inbound_trunk  rG   z!SipService.list_sip_inbound_trunkr   r   c                   r6   )zList SIP outbound trunks with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP outbound trunks
        ListSIPOutboundTrunkN)r8   r9   r:   r;   r   r{   r1   r1   r2   list_outbound_trunk  r>   zSipService.list_outbound_trunkc                   r?   )a!  List SIP outbound trunks with optional filtering.

        .. deprecated::
           Use :meth:`list_outbound_trunk` instead.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP outbound trunks
        zFlist_sip_outbound_trunk is deprecated, use list_outbound_trunk insteadr@   rA   N)rC   rD   rE   r   r{   r1   r1   r2   list_sip_outbound_trunk  rG   z"SipService.list_sip_outbound_trunkdeleter   r   c                   r6   )zDelete a SIP trunk.

        Args:
            delete: Request containing trunk ID to delete

        Returns:
            Deleted trunk information
        DeleteSIPTrunkN)r8   r9   r:   r;   r   r.   r   r1   r1   r2   delete_trunk  s   	
zSipService.delete_trunkc                   r?   )zDelete a SIP trunk.

        .. deprecated::
           Use :meth:`delete_trunk` instead.

        Args:
            delete: Request containing trunk ID to delete

        Returns:
            Deleted trunk information
        z8delete_sip_trunk is deprecated, use delete_trunk insteadr@   rA   N)rC   rD   rE   r   r   r1   r1   r2   delete_sip_trunk  s   zSipService.delete_sip_trunkr   r   c                   r6   )zCreate a new SIP dispatch rule.

        Args:
            create: Request containing rule details

        Returns:
            Created SIP dispatch rule
        CreateSIPDispatchRuleNr8   r9   r:   r;   r   r<   r1   r1   r2   create_dispatch_rule	  r>   zSipService.create_dispatch_rulec                   r?   )zCreate a new SIP dispatch rule.

        .. deprecated::
           Use :meth:`create_dispatch_rule` instead.

        Args:
            create: Request containing rule details

        Returns:
            Created SIP dispatch rule
        zHcreate_sip_dispatch_rule is deprecated, use create_dispatch_rule insteadr@   rA   N)rC   rD   rE   r   r<   r1   r1   r2   create_sip_dispatch_rule  rG   z#SipService.create_sip_dispatch_rulerule_idrulec                   rJ   )zUpdates an existing SIP dispatch rule by replacing it entirely.

        Args:
            rule_id: ID of the SIP dispatch rule to update
            rule: SIP dispatch rule to update with

        Returns:
            Updated SIP dispatch rule
        UpdateSIPDispatchRule)sip_dispatch_rule_idrN   N)r8   r9   r:   r   r;   r   r.   r   r   r1   r1   r2   update_dispatch_rule1  s   

zSipService.update_dispatch_rulec                   rR   )aK  Updates an existing SIP dispatch rule by replacing it entirely.

        .. deprecated::
           Use :meth:`update_dispatch_rule` instead.

        Args:
            rule_id: ID of the SIP dispatch rule to update
            rule: SIP dispatch rule to update with

        Returns:
            Updated SIP dispatch rule
        zHupdate_sip_dispatch_rule is deprecated, use update_dispatch_rule insteadr@   rA   N)rC   rD   rE   r   r   r1   r1   r2   update_sip_dispatch_ruleG  rT   z#SipService.update_sip_dispatch_rule	trunk_idsr   r[   r\   
attributesr   Optional[SIPDispatchRule]r   Optional[dict[str, str]]c                  s   t ||||d}|dur2t|tr+|jj|j |jj|j |jj|j n|jj| | j	t
dt||d|  tI dH S )zqUpdates specific fields of an existing SIP dispatch rule.

        Only provided fields will be updated.
        )r[   r\   r   r   Nr   )r   r`   )r   ra   r   r   rb   rc   rd   re   r8   r9   r:   r   r;   r   )r.   r   r   r   r[   r\   r   r`   r1   r1   r2   update_dispatch_rule_fields_  s(   


z&SipService.update_dispatch_rule_fieldsc                  s.   t jdtdd | j||||||dI dH S )zUpdates specific fields of an existing SIP dispatch rule.

        .. deprecated::
           Use :meth:`update_dispatch_rule_fields` instead.

        Only provided fields will be updated.
        zVupdate_sip_dispatch_rule_fields is deprecated, use update_dispatch_rule_fields insteadr@   rA   r   N)rC   rD   rE   r   )r.   r   r   r   r[   r\   r   r1   r1   r2   update_sip_dispatch_rule_fields  s   z*SipService.update_sip_dispatch_rule_fieldsr   r   c                   r6   )zList SIP dispatch rules with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP dispatch rules
        ListSIPDispatchRuleN)r8   r9   r:   r;   r   r{   r1   r1   r2   list_dispatch_rule  r>   zSipService.list_dispatch_rulec                   r?   )a  List SIP dispatch rules with optional filtering.

        .. deprecated::
           Use :meth:`list_dispatch_rule` instead.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP dispatch rules
        zDlist_sip_dispatch_rule is deprecated, use list_dispatch_rule insteadr@   rA   N)rC   rD   rE   r   r{   r1   r1   r2   list_sip_dispatch_rule  rG   z!SipService.list_sip_dispatch_ruler   c                   r6   )zDelete a SIP dispatch rule.

        Args:
            delete: Request containing rule ID to delete

        Returns:
            Deleted rule information
        DeleteSIPDispatchRuleNr   r   r1   r1   r2   delete_dispatch_rule  r>   zSipService.delete_dispatch_rulec                   r?   )zDelete a SIP dispatch rule.

        .. deprecated::
           Use :meth:`delete_dispatch_rule` instead.

        Args:
            delete: Request containing rule ID to delete

        Returns:
            Deleted rule information
        zHdelete_sip_dispatch_rule is deprecated, use delete_dispatch_rule insteadr@   rA   N)rC   rD   rE   r   r   r1   r1   r2   delete_sip_dispatch_rule  rG   z#SipService.delete_sip_dispatch_rule)timeoutrH   outbound_trunk_configr   r   Optional[float]r   Optional[SIPOutboundConfig]r   c             	     s   d}|rt j|d}n|jr(| jjjr(| jjjjr(| jjjjdk r(t jdd}|r-||_|r2||_| jj	t
d|| jt tdddt|dI dH S )	a  Create a new SIP participant.

        Args:
            create: Request containing participant details
            timeout: Optional request timeout in seconds
            trunk_id: Optional SIP trunk ID to use for the participant
            outbound_trunk_config: Optional outbound trunk configuration for the participant

        Returns:
            Created SIP participant

        Raises:
            SIPError: If the SIP operation fails
        N)total   CreateSIPParticipantTcallsip)r   )aiohttpClientTimeoutwait_until_answeredr8   _sessionr   r   rM   rI   r9   r:   _auth_headerr"   r#   r   )r.   r4   r   rH   r   client_timeoutr1   r1   r2   create_sip_participant  s.   
z!SipService.create_sip_participanttransferr   c              
     s6   | j td|| jtd|jdtdddtI dH S )zTransfer a SIP participant to a different room.

        Args:
            transfer: Request containing transfer details

        Returns:
            Updated SIP participant information
        TransferSIPParticipantT)
room_adminroomr   r   N)r8   r9   r:   r   r"   	room_namer#   r   )r.   r   r1   r1   r2   transfer_sip_participant$  s   
z#SipService.transfer_sip_participantdict[str, str]c                 C  s   | j t tdddS )NT)adminr   )r   r"   r#   )r.   r1   r1   r2   r;   =  r3   zSipService._admin_headers)r&   r'   r(   r)   r*   r)   r+   r)   )r4   r   r5   r	   )rH   r)   rI   r	   r5   r	   )rH   r)   rV   r]   rW   r]   rX   r]   rY   r^   rZ   r^   r[   r^   r\   r^   r5   r	   )rH   r)   rV   rg   rW   rg   rX   rg   rY   r^   rZ   r^   r[   r^   r\   r^   r5   r	   )r4   r   r5   r   )rH   r)   rI   r   r5   r   )rH   r)   rr   rt   rs   ru   rV   r]   rY   rt   rZ   rt   r[   rt   r\   rt   r5   r   )rH   r)   rr   rt   rs   ru   rV   rw   rY   rt   rZ   rt   r[   rt   r\   rt   r5   r   )ry   r   r5   r   )ry   r   r5   r   )r   r   r5   r   )r4   r   r5   r   )r   r)   r   r   r5   r   )r   r)   r   r]   r   r   r[   r^   r\   r^   r   r   r5   r   )r   r)   r   rg   r   r   r[   r^   r\   r^   r   r   r5   r   )ry   r   r5   r   )r   r   r5   r   )
r4   r   r   r   rH   r^   r   r   r5   r   )r   r   r5   r   )r5   r   )%__name__
__module____qualname____doc__r-   r=   rF   rP   rS   rf   ri   rl   rm   ro   rp   rv   rx   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   __classcell__r1   r1   r/   r2   r%   ,   s    



;
#


/
#








(




2r%   )+
__future__r   r   rC   typingr   livekit.protocol.modelsr   livekit.protocol.sipr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _servicer!   access_tokenr"   r#   r:   r%   r1   r1   r1   r2   <module>   s    t