
    qiS                     |    d dl Z d dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ d d	lmZ  G d
 d      Zy)    N   )RoomService)EgressService)IngressService)
SipService)AgentDispatchService)ConnectorService)Optionalc                      e Zd ZdZ	 	 	 dddddee   dee   dee   deej                     deej                     f
d	Z	e
d
efd       Ze
d
efd       Ze
d
efd       Ze
d
efd       Ze
d
efd       Ze
d
efd       Zd Zd Zd Zy)
LiveKitAPIa  LiveKit Server API Client

    This class is the main entrypoint, which exposes all services.

    Usage:

    ```python
    from livekit import api
    lkapi = api.LiveKitAPI()
    rooms = await lkapi.room.list_rooms(api.proto_room.ListRoomsRequest(names=['test-room']))
    ```
    N)timeoutsessionurlapi_key
api_secretr   r   c                   |xs t        j                  d      }|xs t        j                  d      }|xs t        j                  d      }|st        d      |r|st        d      d| _        || _        | j                  s:d| _        |st        j                  d	      }t        j                  |
      | _        t        | j                  |||      | _	        t        | j                  |||      | _        t        | j                  |||      | _        t        | j                  |||      | _        t!        | j                  |||      | _        t%        | j                  |||      | _        y)a  Create a new LiveKitAPI instance.

        Args:
            url: LiveKit server URL (read from `LIVEKIT_URL` environment variable if not provided)
            api_key: API key (read from `LIVEKIT_API_KEY` environment variable if not provided)
            api_secret: API secret (read from `LIVEKIT_API_SECRET` environment variable if not provided)
            timeout: Request timeout (default: 60 seconds)
            session: aiohttp.ClientSession instance to use for requests, if not provided, a new one will be created
        LIVEKIT_URLLIVEKIT_API_KEYLIVEKIT_API_SECRETzurl must be setz"api_key and api_secret must be setTF<   )total)r   N)osgetenv
ValueError_custom_session_sessionaiohttpClientTimeoutClientSessionr   _roomr   _ingressr   _egressr   _sipr   _agent_dispatchr	   
_connector)selfr   r   r   r   r   s         I/opt/pipecat/venv/lib/python3.12/site-packages/livekit/api/livekit_api.py__init__zLiveKitAPI.__init__   s(   $ -RYY}-9RYY'89B299-A#B
.//jABB#}}#(D !//b9#11'BDM WjI
&t}}c7JO$T]]C*Mt}}c7JG	3DMM3Q[\*4==#w
S    returnc                     | j                   S )z$Instance of the AgentDispatchService)r$   r&   s    r'   agent_dispatchzLiveKitAPI.agent_dispatchE   s     ###r)   c                     | j                   S )zInstance of the RoomService)r    r,   s    r'   roomzLiveKitAPI.roomJ   s     zzr)   c                     | j                   S )zInstance of the IngressService)r!   r,   s    r'   ingresszLiveKitAPI.ingressO   s     }}r)   c                     | j                   S )zInstance of the EgressService)r"   r,   s    r'   egresszLiveKitAPI.egressT   s     ||r)   c                     | j                   S )zInstance of the SipService)r#   r,   s    r'   sipzLiveKitAPI.sipY   s     yyr)   c                     | j                   S )z Instance of the ConnectorService)r%   r,   s    r'   	connectorzLiveKitAPI.connector^   s     r)   c                 n   K   | j                   s#| j                  j                          d{    yy7 w)zqClose the API client

        Call this before your application exits or when the API client is no longer needed.N)r   r   closer,   s    r'   aclosezLiveKitAPI.aclosec   s/     
 ##--%%''' $'s   *535c                    K   | S w)*@private

        Support for `async with` r,   s    r'   
__aenter__zLiveKitAPI.__aenter__k   s      s   c                 @   K   | j                          d{    y7 w)r<   N)r:   )r&   exc_typeexc_valexc_tbs       r'   	__aexit__zLiveKitAPI.__aexit__q   s      kkms   )NNN)__name__
__module____qualname____doc__r
   strr   r   r   r(   propertyr   r-   r   r/   r   r1   r   r3   r   r5   r	   r7   r:   r>   rC   r=   r)   r'   r   r      s1    "!%$(	)T 4837)Tc])T #)T SM	)T '//0)T '//0)TV $ 4 $ $ k         Z   +  (r)   r   )r   r   room_servicer   egress_servicer   ingress_servicer   sip_servicer   agent_dispatch_servicer   connector_servicer	   typingr
   r   r=   r)   r'   <module>rQ      s,     	 % ) + # 8 / i ir)   