o
    i.                     @   s   d dl 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 d dlmZmZ ddlmZ ddlmZ dZ 	 G d	d deZ!dS )
    N)uuid4)CreateRoomRequestListRoomsRequestDeleteRoomRequestListRoomsResponseDeleteRoomResponseListParticipantsRequestListParticipantsResponseRoomParticipantIdentityMuteRoomTrackRequestMuteRoomTrackResponseUpdateParticipantRequestUpdateSubscriptionsRequestSendDataRequestSendDataResponseUpdateRoomMetadataRequestRemoveParticipantResponseUpdateSubscriptionsResponseForwardParticipantRequestForwardParticipantResponseMoveParticipantRequestMoveParticipantResponse)RoomParticipantInfo   )Service)VideoGrantsRoomServicec                       s  e Zd ZdZdejdededef fddZded	e	fd
dZ
ded	efddZded	efddZded	e	fddZded	efddZded	efddZded	efddZded	dfdd Zd!ed	dfd"d#Zded	e fd$d%Z!de"d	efd&d'Z#de$d	e%fd(d)Z&d*e'd	e(fd+d,Z)  Z*S )-r   a`  Client for LiveKit RoomService API

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

    ```python
    from livekit import api
    lkapi = api.LiveKitAPI()
    room_service = lkapi.room
    ```

    Also see https://docs.livekit.io/home/server/managing-rooms/ and https://docs.livekit.io/home/server/managing-participants/
    sessionurlapi_key
api_secretc                    s   t  |||| d S )N)super__init__)selfr   r   r    r!   	__class__ Z/var/www/html/livekit_bhavya/venv/lib/python3.10/site-packages/livekit/api/room_service.pyr#   0   s   zRoomService.__init__createreturnc              
      (   | j td|| tddtI dH S )a  Creates a new room with specified configuration.

        Args:
            create (CreateRoomRequest): arg containing:
                - name: str - Unique room name
                - empty_timeout: int - Seconds to keep room open if empty
                - max_participants: int - Max allowed participants
                - metadata: str - Custom room metadata
                - egress: RoomEgress - Egress configuration
                - min_playout_delay: int - Minimum playout delay in ms
                - max_playout_delay: int - Maximum playout delay in ms
                - sync_streams: bool - Enable A/V sync for playout delays >200ms

        Returns:
            Room: The created room object
        
CreateRoomTroom_createN)_clientrequestSVC_auth_headerr   r   )r$   r)   r'   r'   r(   create_room3   s   
zRoomService.create_roomlistc              
      r+   )a!  Lists active rooms.

        Args:
            list (ListRoomsRequest): arg containing:
                - names: list[str] - Optional list of room names to filter by

        Returns:
            ListRoomsResponse:
                - rooms: list[Room] - List of active Room objects
        	ListRoomsT)	room_listN)r/   r0   r1   r2   r   r   r$   r4   r'   r'   r(   
list_roomsO   s   
zRoomService.list_roomsdeletec              
      r+   )zDeletes a room and disconnects all participants.

        Args:
            delete (DeleteRoomRequest): arg containing:
                - room: str - Name of room to delete

        Returns:
            DeleteRoomResponse: Empty response object
        
DeleteRoomTr-   N)r/   r0   r1   r2   r   r   )r$   r9   r'   r'   r(   delete_roomb   s   

zRoomService.delete_roomupdatec                    ,   | j td|| td|jdtI dH S )aP  Updates a room's [metadata](https://docs.livekit.io/home/client/data/room-metadata/).

        Args:
            update (UpdateRoomMetadataRequest): arg containing:
                - room: str - Name of room to update
                - metadata: str - New metadata to set

        Returns:
            Room: Updated Room object
        UpdateRoomMetadataT
room_adminroomN)r/   r0   r1   r2   r   rA   r   r$   r<   r'   r'   r(   update_room_metadatat      
z RoomService.update_room_metadatac                    r=   )aF  Lists all participants in a room.

        Args:
            list (ListParticipantsRequest): arg containing:
                - room: str - Name of room to list participants from

        Returns:
            ListParticipantsResponse:
                - participants: list[ParticipantInfo] - List of participant details
        ListParticipantsTr?   N)r/   r0   r1   r2   r   rA   r	   r7   r'   r'   r(   list_participants   rD   zRoomService.list_participantsgetc                    r=   )a/  Gets details about a specific participant.

        Args:
            get (RoomParticipantIdentity): arg containing:
                - room: str - Room name
                - identity: str - Participant identity to look up

        Returns:
            ParticipantInfo:
                - sid: str - Participant session ID
                - identity: str - Participant identity
                - state: int - Connection state
                - tracks: list[TrackInfo] - Published tracks
                - metadata: str - Participant metadata
                - joined_at: int - Join timestamp
                - name: str - Display name
                - version: int - Protocol version
                - permission: ParticipantPermission - Granted permissions
                - region: str - Connected region
        GetParticipantTr?   Nr/   r0   r1   r2   r   rA   r   )r$   rG   r'   r'   r(   get_participant   s   
zRoomService.get_participantremovec                    r=   )a3  Removes a participant from a room.

        Args:
            remove (RoomParticipantIdentity): arg containing:
                - room: str - Room name
                - identity: str - Identity of participant to remove

        Returns:
            RemoveParticipantResponse: Empty response object
        RemoveParticipantTr?   N)r/   r0   r1   r2   r   rA   r   )r$   rK   r'   r'   r(   remove_participant   s   
zRoomService.remove_participantforwardNc                    4   | j td|| td|j|jdtI dH  dS )a  Forwards a participant and their published tracks from one room to another.

        This feature is only available for LiveKit Cloud/Private Cloud.

        Args:
            forward (ForwardParticipantRequest): arg containing:
                - room: str - Room name
                - identity: str - identity of Participant to forward
                - destination_room: str - Destination room name
        ForwardParticipantTr@   rA   destination_roomN)r/   r0   r1   r2   r   rA   rR   r   )r$   rN   r'   r'   r(   forward_participant   s   
zRoomService.forward_participantmovec                    rO   )ah  Moves a participant from one room to another.

        This feature is only available for LiveKit Cloud/Private Cloud.

        Args:
            move (MoveParticipantRequest): arg containing:
                - room: str - Room name
                - identity: str - Participant identity
                - destination_room: str - Destination room name
        MoveParticipantTrQ   N)r/   r0   r1   r2   r   rA   rR   r   )r$   rT   r'   r'   r(   move_participant   s   zRoomService.move_participantc                    r=   )a  Mutes or unmutes a participant's published track.

        Args:
            update (MuteRoomTrackRequest): arg containing:
                - room: str - Room name
                - identity: str - Participant identity
                - track_sid: str - Track session ID to mute
                - muted: bool - True to mute, False to unmute

        Returns:
            MuteRoomTrackResponse containing:
                - track: TrackInfo - Updated track information
        MutePublishedTrackTr?   N)r/   r0   r1   r2   r   rA   r   rB   r'   r'   r(   mute_published_track   s   
z RoomService.mute_published_trackc                    r=   )a  Updates a participant's metadata or permissions.

        Args:
            update (UpdateParticipantRequest): arg containing:
                - room: str - Room name
                - identity: str - Participant identity
                - metadata: str - New metadata
                - permission: ParticipantPermission - New permissions
                - name: str - New display name
                - attributes: dict[str, str] - Key-value attributes

        Returns:
            ParticipantInfo: Updated participant information
        UpdateParticipantTr?   NrI   rB   r'   r'   r(   update_participant  s   
zRoomService.update_participantc                    r=   )a  Updates a participant's track subscriptions.

        Args:
            update (UpdateSubscriptionsRequest): arg containing:
                - room: str - Room name
                - identity: str - Participant identity
                - track_sids: list[str] - Track session IDs
                - subscribe: bool - True to subscribe, False to unsubscribe
                - participant_tracks: list[ParticipantTracks] - Participant track mappings

        Returns:
            UpdateSubscriptionsResponse: Empty response object
        UpdateSubscriptionsTr?   N)r/   r0   r1   r2   r   rA   r   rB   r'   r'   r(   update_subscriptions.  s   
z RoomService.update_subscriptionssendc                    s6   t  j|_| jtd|| td|jdt	I dH S )a  Sends data to participants in a room.

        Args:
            send (SendDataRequest): arg containing:
                - room: str - Room name
                - data: bytes - Data payload to send
                - kind: DataPacket.Kind - RELIABLE or LOSSY delivery
                - destination_identities: list[str] - Target participant identities
                - topic: str - Optional topic for the message

        Returns:
            SendDataResponse: Empty response object
        SendDataTr?   N)
r   bytesnoncer/   r0   r1   r2   r   rA   r   )r$   r]   r'   r'   r(   	send_dataF  s   

zRoomService.send_data)+__name__
__module____qualname____doc__aiohttpClientSessionstrr#   r   r   r3   r   r   r8   r   r   r;   r   rC   r   r	   rF   r
   r   rJ   r   rM   r   rS   r   rV   r   r   rX   r   rZ   r   r   r\   r   r   ra   __classcell__r'   r'   r%   r(   r   "   s@     



)"rf   uuidr   livekit.protocol.roomr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   livekit.protocol.modelsr   r   _servicer   access_tokenr   r1   r   r'   r'   r'   r(   <module>   s    \