o
    ic
                     @   s   d Z ddlZG dd dZdS )zNLiveKit REST Helpers.

Methods that wrap the LiveKit API for room management.
    Nc                	   @   sX   e Zd ZdZdddedededejfdd	ZddedefddZ	dedefddZ
dS )LiveKitRESTHelperzlHelper class for interacting with LiveKit's REST API.

    Provides methods for managing LiveKit rooms.
    zhttps://your-livekit-host.com)api_urlapi_key
api_secretr   aiohttp_sessionc                C   s"   || _ || _|d| _|| _dS )a,  Initialize the LiveKit REST helper.

        Args:
            api_key: Your LiveKit API key.
            api_secret: Your LiveKit API secret.
            api_url: LiveKit server URL (e.g. "https://your-livekit-host.com").
            aiohttp_session: Async HTTP session for making requests.
        /N)r   r   rstripr   r   )selfr   r   r   r    r
   T/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/transports/livekit/utils.py__init__   s   
zLiveKitRESTHelper.__init__Troom_createreturnc                 C   sN   ddl }ddl}| j| jt|  t|  d d|id}|j|| jddS )zCreate a signed access token for LiveKit API authentication.

        Args:
            room_create: Whether to grant roomCreate permission.

        Returns:
            Signed JWT access token.
        r   N<   
roomCreate)isssubnbfexpvideoHS256)	algorithm)timejwtr   intencoder   )r	   r   r   r   claimsr
   r
   r   _create_access_token*   s   	

z&LiveKitRESTHelper._create_access_token	room_namec              	      s   | j dd}d| dd}| jj| j d|d|id4 I d	H &}|jd
kr=| I d	H }td| d|j d| W d	  I d	H  dS 1 I d	H sNw   Y  dS )a2  Delete a LiveKit room by name.

        This will forcibly disconnect all participants currently in the room.

        Args:
            room_name: Name of the room to delete.

        Returns:
            True if deletion was successful.

        Raises:
            Exception: If deletion fails.
        T)r   zBearer zapplication/json)AuthorizationzContent-Typez%/twirp/livekit.RoomService/DeleteRoomroom)headersjsonN   zFailed to delete room [z] (status: z): )r   r   postr   statustext	Exception)r	   r   tokenr!   rr&   r
   r
   r   delete_room_by_nameC   s$   

		z%LiveKitRESTHelper.delete_room_by_nameN)T)__name__
__module____qualname____doc__straiohttpClientSessionr   boolr   r*   r
   r
   r
   r   r      s    

r   )r.   r0   r   r
   r
   r
   r   <module>   s   