
    %i.                         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e      Z!y)
    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                       e Zd ZdZdej
                  dededef fdZdede	fd	Z
d
edefdZdedefdZdede	fdZd
edefdZdedefdZdedefdZdeddfdZdeddfdZdede fdZ!de"defdZ#de$de%fdZ&de'de(fdZ) x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                 *    t         |   ||||       y )N)super__init__)selfr    r!   r"   r#   	__class__s        R/var/www/html/engine/venv/lib/python3.12/site-packages/livekit/api/room_service.pyr&   zRoomService.__init__0   s    #w
;    createreturnc           
         K   | j                   j                  t        d|| j                  t	        d            t
               d{   S 7 w)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+   s     r)   create_roomzRoomService.create_room3   sH     ( \\))kd;<
 
 	
 
   AAAAlistc           
         K   | j                   j                  t        d|| j                  t	        d            t
               d{   S 7 w)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)r1   r2   r3   r4   r   r   r'   r7   s     r)   
list_roomszRoomService.list_roomsO   sH      \\))kD9:
 
 	
 
r6   deletec           
         K   | j                   j                  t        d|| j                  t	        d            t
               d{   S 7 w)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)r1   r2   r3   r4   r   r   )r'   r=   s     r)   delete_roomzRoomService.delete_roomb   sH      \\))kd;<
 
 	
 
r6   updatec                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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)r1   r2   r3   r4   r   rF   r   r'   rA   s     r)   update_room_metadataz RoomService.update_room_metadatat   sN      \\)) kTLM
 
 	
 
   AAAAc                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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
        ListParticipantsTrD   N)r1   r2   r3   r4   r   rF   r
   r;   s     r)   list_participantszRoomService.list_participants   sN      \\))kT		JK$
 
 	
 
rI   getc                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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
        GetParticipantTrD   Nr1   r2   r3   r4   r   rF   r   )r'   rM   s     r)   get_participantzRoomService.get_participant   sN     * \\))kTIJ
 
 	
 
rI   removec                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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
        RemoveParticipantTrD   N)r1   r2   r3   r4   r   rF   r   )r'   rR   s     r)   remove_participantzRoomService.remove_participant   sN      \\))kTLM%
 
 	
 
rI   forwardNc                    K   | j                   j                  t        d|| j                  t	        d|j
                  |j                              t               d{    y7 w)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rE   rF   destination_roomN)r1   r2   r3   r4   r   rF   rZ   r   )r'   rV   s     r)   forward_participantzRoomService.forward_participant   sY      ll"" #',,IaIa
 '

 
	
 
	
   AA$A"A$movec                    K   | j                   j                  t        d|| j                  t	        d|j
                  |j                              t               d{    y7 w)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
        MoveParticipantTrY   N)r1   r2   r3   r4   r   rF   rZ   r   )r'   r]   s     r)   move_participantzRoomService.move_participant   s[      ll""#%)%:%: $
 	
 	
r\   c                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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
        MutePublishedTrackTrD   N)r1   r2   r3   r4   r   rF   r   rG   s     r)   mute_published_trackz RoomService.mute_published_track   sN     " \\)) kTLM!
 
 	
 
rI   c                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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
        UpdateParticipantTrD   NrP   rG   s     r)   update_participantzRoomService.update_participant  sN      \\))kTLM
 
 	
 
rI   c                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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
        UpdateSubscriptionsTrD   N)r1   r2   r3   r4   r   rF   r   rG   s     r)   update_subscriptionsz RoomService.update_subscriptions.  sN       \\))!kTLM'
 
 	
 
rI   sendc                    K   t               j                  |_        | j                  j	                  t
        d|| j                  t        d|j                              t               d{   S 7 w)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
        SendDataTrD   N)
r   bytesnoncer1   r2   r3   r4   r   rF   r   )r'   rj   s     r)   	send_datazRoomService.send_dataF  s[      W]]
\\))kT		JK
 
 	
 
s   A(A1*A/+A1)+__name__
__module____qualname____doc__aiohttpClientSessionstrr&   r   r   r5   r   r   r<   r   r   r@   r   rH   r	   r
   rL   r   r   rQ   r   rU   r   r[   r   r`   r   r   rc   r   rf   r   r   ri   r   r   ro   __classcell__)r(   s   @r)   r   r   "   s?   < 5 5 <C <# <[^ <
!
 

8
%5 
:K 
&
(9 
>P 
$
1J 
t 
&
,C 
H` 
&
)@ 
_ 
:
-
	"
*
1J 
t 
0
+A 
d 
4
$
 

2
/G 
O 
.
0
	$
0
O 
8H 
r*   )"rt   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   r3   r    r*   r)   <module>r~      sJ          . :  % z
' z
r*   