
    %i4                        d dl m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! ddl"m#Z# ddl$m%Z%m&Z& d	Z'	  G d
 de#      Z(y)    )annotationsN)Optional)
ListUpdate)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                      e Zd ZdZd fdZ	 	 	 	 ddZ	 	 	 	 	 	 ddZdddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 	 	 dd	Z	dddddddd
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
	 	 	 	 d dZ	 	 	 	 d!dZd"dZ	 	 	 	 d#dZ	 	 	 	 	 	 d$dZdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 d%dZ	 	 	 	 d&dZ	 	 	 	 d'dZdd	 	 	 	 	 d(dZ	 	 	 	 d)dZd*dZ x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
    ```
    c                *    t         |   ||||       y )N)super__init__)selfsessionurlapi_key
api_secret	__class__s        Q/var/www/html/engine/venv/lib/python3.12/site-packages/livekit/api/sip_service.pyr)   zSipService.__init__6   s    #w
;    c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zCreate a new SIP inbound trunk.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP inbound trunk
        CreateSIPInboundTrunkN)_clientrequestSVC_admin_headersr	   r*   creates     r0   create_sip_inbound_trunkz#SipService.create_sip_inbound_trunk9   A      \\))#!
 
 	
 
   9AA Ac                   K   | j                   j                  t        dt        ||      | j	                         t
               d{   S 7 w)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)r4   r5   r6   r   r7   r	   r*   trunk_idtrunks      r0   update_sip_inbound_trunkz#SipService.update_sip_inbound_trunkL   sN      \\))#(% !	
 	
 		
 	
   AAAAN)numbersallowed_addressesallowed_numbersauth_usernameauth_passwordnamemetadatac               .  K   t        ||||      }	|t        |      |	_        |t        |      |	_        |t        |      |	_        | j
                  j                  t        dt        ||	      | j                         t               d{   S 7 w)zqUpdates specific fields of an existing SIP inbound trunk.

        Only provided fields will be updated.
        )rJ   rK   rL   rM   Nsetr>   r@   update)r
   r   rG   rH   rI   r4   r5   r6   r   r7   r	   )
r*   rC   rG   rH   rI   rJ   rK   rL   rM   rR   s
             r0   update_sip_inbound_trunk_fieldsz*SipService.update_sip_inbound_trunk_fieldse   s       '''	
 'G4FN('16G'HF$&%/O%DF"\\))#(% !	
 	
 		
 	
s   BBBBc                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zCreate a new SIP outbound trunk.

        Args:
            create: Request containing trunk details

        Returns:
            Created SIP outbound trunk
        CreateSIPOutboundTrunkN)r4   r5   r6   r7   r   r8   s     r0   create_sip_outbound_trunkz$SipService.create_sip_outbound_trunk   sA      \\))$! 
 
 	
 
r<   c                   K   | j                   j                  t        dt        ||      | j	                         t
               d{   S 7 w)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
        UpdateSIPOutboundTrunkr?   N)r4   r5   r6   r   r7   r   rB   s      r0   update_sip_outbound_trunkz$SipService.update_sip_outbound_trunk   sN      \\))$)% ! 	
 	
 		
 	
rF   )address	transportrG   rJ   rK   rL   rM   c                  K   t        ||||||      }	|t        |      |	_        | j                  j	                  t
        dt        ||	      | j                         t               d{   S 7 w)zrUpdates specific fields of an existing SIP outbound trunk.

        Only provided fields will be updated.
        )rZ   r[   rJ   rK   rL   rM   NrO   rX   rQ   )	r   r   rG   r4   r5   r6   r   r7   r   )
r*   rC   rZ   r[   rG   rJ   rK   rL   rM   rR   s
             r0    update_sip_outbound_trunk_fieldsz+SipService.update_sip_outbound_trunk_fields   s~       (''
 'G4FN\\))$)% ! 	
 	
 		
 	
s   A(A1*A/+A1c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zList SIP inbound trunks with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP inbound trunks
        ListSIPInboundTrunkN)r4   r5   r6   r7   r   r*   lists     r0   list_sip_inbound_trunkz!SipService.list_sip_inbound_trunk   A      \\))!!'
 
 	
 
r<   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zList SIP outbound trunks with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP outbound trunks
        ListSIPOutboundTrunkN)r4   r5   r6   r7   r   r`   s     r0   list_sip_outbound_trunkz"SipService.list_sip_outbound_trunk   sA      \\))"!(
 
 	
 
r<   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zDelete a SIP trunk.

        Args:
            delete: Request containing trunk ID to delete

        Returns:
            Deleted trunk information
        DeleteSIPTrunkN)r4   r5   r6   r7   r   r*   deletes     r0   delete_sip_trunkzSipService.delete_sip_trunk  sA      \\))!
 
 	
 
r<   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zCreate a new SIP dispatch rule.

        Args:
            create: Request containing rule details

        Returns:
            Created SIP dispatch rule
        CreateSIPDispatchRuleNr4   r5   r6   r7   r   r8   s     r0   create_sip_dispatch_rulez#SipService.create_sip_dispatch_rule  r;   r<   c                   K   | j                   j                  t        dt        ||      | j	                         t
               d{   S 7 w)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_idrA   N)r4   r5   r6   r   r7   r   )r*   rule_idrules      r0   update_sip_dispatch_rulez#SipService.update_sip_dispatch_rule(  sH      \\))#(gtT!
 
 	
 
rF   )	trunk_idsrt   rL   rM   
attributesc          	        K   t        |||||rt        |      nd      }| j                  j                  t        dt        ||      | j                         t               d{   S 7 w)zqUpdates specific fields of an existing SIP dispatch rule.

        Only provided fields will be updated.
        rO   N)rL   rM   rt   rw   rv   rq   )rr   rR   )r   r   r4   r5   r6   r   r7   r   )r*   rs   rv   rt   rL   rM   rw   rR   s           r0   update_sip_dispatch_rule_fieldsz*SipService.update_sip_dispatch_rule_fields>  sl      '!3<jY/$
 \\))#(gfU!
 
 	
 
s   A"A+$A)%A+c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zList SIP dispatch rules with optional filtering.

        Args:
            list: Request with optional filtering parameters

        Returns:
            Response containing list of SIP dispatch rules
        ListSIPDispatchRuleN)r4   r5   r6   r7   r   r`   s     r0   list_sip_dispatch_rulez!SipService.list_sip_dispatch_rule[  rc   r<   c                   K   | j                   j                  t        d|| j                         t               d{   S 7 w)zDelete a SIP dispatch rule.

        Args:
            delete: Request containing rule ID to delete

        Returns:
            Deleted rule information
        DeleteSIPDispatchRuleNrn   ri   s     r0   delete_sip_dispatch_rulez#SipService.delete_sip_dispatch_rulen  r;   r<   timeoutc                 K   d}|rt        j                  |      }n|j                  r| j                  j                  j
                  rm| j                  j                  j
                  j                  rC| j                  j                  j
                  j                  dk  rt        j                  d      }| j                  j                  t        d|| j                  t               t        d            t        |       d{   S 7 w)	a!  Create a new SIP participant.

        Args:
            create: Request containing participant details
            timeout: Optional request timeout in seconds

        Returns:
            Created SIP participant

        Raises:
            SIPError: If the SIP operation fails
        N)total   CreateSIPParticipantTcallsipr   )aiohttpClientTimeoutwait_until_answeredr4   _sessionr   r   r5   r6   _auth_headerr"   r#   r   )r*   r9   r   client_timeouts       r0   create_sip_participantz!SipService.create_sip_participant  s     $ ;?$22AN'' %%--LL))1177LL))1177"<!(!6!6R!@\\))"km1EF" * 
 
 	
 
s   DDDDc                   K   | j                   j                  t        d|| j                  t	        d|j
                        t        d            t               d{   S 7 w)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)r4   r5   r6   r   r"   	room_namer#   r   )r*   transfers     r0   transfer_sip_participantz#SipService.transfer_sip_participant  sh      \\))$#!++ 4(   
 
 	
 
s   AA$A"A$c                L    | j                  t               t        d            S )NT)adminr   )r   r"   r#   )r*   s    r0   r7   zSipService._admin_headers  s      ID4I JJr1   )r+   zaiohttp.ClientSessionr,   strr-   r   r.   r   )r9   r   returnr	   )rC   r   rD   r	   r   r	   )rC   r   rG   Optional[list[str]]rH   r   rI   r   rJ   Optional[str]rK   r   rL   r   rM   r   r   r	   )r9   r   r   r   )rC   r   rD   r   r   r   )rC   r   rZ   
str | Noner[   zSIPTransport | NonerG   zlist[str] | NonerJ   r   rK   r   rL   r   rM   r   r   r   )ra   r   r   r   )ra   r   r   r   )rj   r   r   r   )r9   r   r   r   )rs   r   rt   r   r   r   )rs   r   rv   r   rt   zOptional[SIPDispatchRule]rL   r   rM   r   rw   zOptional[dict[str, str]]r   r   )ra   r   r   r   )rj   r   r   r   )r9   r   r   zOptional[float]r   r   )r   r   r   r   )r   zdict[str, str])__name__
__module____qualname____doc__r)   r:   rE   rS   rV   rY   r]   rb   rf   rk   ro   ru   ry   r|   r   r   r   r7   __classcell__)r/   s   @r0   r&   r&   *   s   	<
2
	
&

 #
 
	
: (,15/3'+'+""&&
&
 %	&

 /&
 -&
 %&
 %&
 &
  &
 
&
P
3
	
&

 $
 
	
: #)-$($($(##
#
 	#

 '#
 "#
 "#
 "#
 #
 #
 
#
J
.
	$
&
/
	%
&
"
2
	
&

 "
 
	
4 *.*.""&/3

 '	

 (
 
  
 -
 

:
.
	$
&
2
	
. $(	&
+&
 !	&

 
&
P
5
	
2Kr1   r&   ))
__future__r   r   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   _servicer!   access_tokenr"   r#   r6   r&    r1   r0   <module>r      sT    "   .      8  0 YK YKr1   