
    /jT                    6   S SK Jr  S SKrS SKrS SKrS SKrS SKJrJr  S SK	J
r
JrJrJrJrJr  S SKrSSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*J+r+  SSK,J-r-J.r.J/r/  SSK0J1r1J2r2  SSK3J4r4J5r5  SSK6J7r7  SSK8J9r9J:r:J;r;J<r<  SSK=J>r>  \S   r?\ " S S5      5       r@\ " S S5      5       rA\ " S S5      5       rB\ " S S 5      5       rC\ " S! S"5      5       rD " S# S$\E5      rF " S% S&\\?   5      rGg)'    )annotationsN)	dataclassfield)CallableDictLiteralOptionalcastMapping   )EventEmitter)	FfiClient	FfiHandle)ffi_pb2)participant_pb2)room_pb2)	stats_pb2)DisconnectReason)ConnectionState)	TrackKind)RpcMethodInvocationEvent)BroadcastQueue)E2EEManagerE2EEOptions)LocalParticipantParticipantRemoteParticipant)RemoteAudioTrackRemoteVideoTrack)RemoteTrackPublicationTrackPublication)TranscriptionSegment)TextStreamReaderByteStreamReaderTextStreamHandlerByteStreamHandler)RemoteDataTrack)#participant_connectedparticipant_disconnectedparticipant_activelocal_track_publishedlocal_track_unpublishedlocal_track_subscribedtrack_publishedtrack_unpublishedtrack_subscribedtrack_unsubscribedtrack_subscription_failedtrack_mutedtrack_unmutedactive_speakers_changedroom_metadata_changedparticipant_metadata_changedparticipant_name_changedparticipant_attributes_changedconnection_quality_changed%participant_encryption_status_changedparticipant_permissions_changeddata_receivedsip_dtmf_receivedtranscription_receivede2ee_state_changedconnection_state_changed	connecteddisconnectedreconnectingreconnectedroom_updatedmovedtoken_refresheddata_track_publisheddata_track_unpublishedc                      \ rS rSr% \R
                  R                  rS\S'    \R                  R                  rS\S'    \" \S9rS\S'   S	rg
)RtcConfigurationX   z%proto_room.IceTransportType.ValueTypeice_transport_typez-proto_room.ContinualGatheringPolicy.ValueTypecontinual_gathering_policy)default_factoryzlist[proto_room.IceServer]ice_servers N)__name__
__module____qualname____firstlineno__
proto_roomIceTransportTypeTRANSPORT_ALLrN   __annotations__ContinualGatheringPolicyGATHER_CONTINUALLYrO   r   listrQ   __static_attributes__rR       A/app/agent/.venv/lib/python3.13/site-packages/livekit/rtc/room.pyrL   rL   X   s\     	##11 =  S++>>  M  <.3D.IK+Ir_   rL   c                      \ rS rSr% SrS\S'    SrS\S'   SrS\S	'    SrS\S
'    Sr	S\S'    Sr
S\S'    SrS\S'   Srg)RoomOptionsg   Tboolauto_subscribeFdynacastNzE2EEOptions | Nonee2ee
encryptionzRtcConfiguration | None
rtc_configzfloat | Noneconnect_timeoutzbool | Nonesingle_peer_connectionrR   )rS   rT   rU   rV   re   rZ   rf   rg   rh   ri   rj   rk   r^   rR   r_   r`   rb   rb   g   s^    NDCHd#D
#4%)J"),*.J'.'$(O\(b*.K.kr_   rb   c                  H    \ rS rSr% S\S'    S\S'    S\S'    SrS	\S
'   Srg)
DataPacketx   bytesdataz#proto_room.DataPacketKind.ValueTypekindRemoteParticipant | NoneparticipantNz
str | NonetopicrR   )rS   rT   rU   rV   rZ   rt   r^   rR   r_   r`   rm   rm   x   s)    
K)
--:))HE:0r_   rm   c                  <    \ rS rSr% S\S'    S\S'    SrS\S'   S	rg)
SipDTMF   intcodestrdigitNrr   rs   rR   )rS   rT   rU   rV   rZ   rs   r^   rR   r_   r`   rv   rv      s     
I/J,0K)0Nr_   rv   c                  *    \ rS rSr% S\S'   S\S'   Srg)RtcStats   zlist[proto_stats.RtcStats]publisher_statssubscriber_statsrR   N)rS   rT   rU   rV   rZ   r^   rR   r_   r`   r}   r}      s    //00r_   r}   c                      \ rS rSrSS jrSrg)ConnectError   c                    Xl         g Nmessage)selfr   s     r`   __init__ConnectError.__init__   s    r_   r   N)r   rz   )rS   rT   rU   rV   r   r^   rR   r_   r`   r   r      s    r_   r   c                  d  ^  \ rS rSr S(   S)U 4S jjjrS*S jr\S+S j5       r\S,S j5       r\S-S j5       r	\S.S j5       r
\S+S j5       r\S+S	 j5       r\S/S
 j5       r\S0S j5       r\S0S j5       r\S1S j5       r\S2S j5       r\S3S j5       r\S3S j5       rS2S jrS(S4U 4S jjjr\" 5       4S5S jjrS6S jrS7S jrS8S jrS9S jrS8S jr\R<                  S.   S:S jjrS*S jr S;S jr!S<S jr"    S=S jr#S>S jr$S?S  jr%S*S! jr&S*S" jr'S@S# jr(SAS$ jr)    SBS% jr*S+S& jr+S'r,U =r-$ )CRoom   c                  > [         TU ]  5         SU l        U=(       d    [        R                  " 5       U l        [        [        R                     " 5       U l	        [        R                  " 5       U l        [        5       U l        [        5       U l        0 U l        ["        R$                  U l        [        R(                  [*           " 5       U l        SU l        0 U l        0 U l        0 U l        0 U l        SU l        SU l        g)zInitializes a new Room instance.

Parameters:
    loop (Optional[asyncio.AbstractEventLoop]): The event loop to use. If not provided, the default event loop is used.
N)superr   _ffi_handleasyncioget_event_loop_loopr   	proto_ffiFfiEvent_room_queuerW   RoomInfo_infoset_rpc_invocation_tasks_data_stream_tasks_remote_participantsr   CONN_DISCONNECTED_connection_stateFuturerz   _first_sid_future_local_participant_text_stream_readers_byte_stream_readers_text_stream_handlers_byte_stream_handlers_token_server_url)r   loop	__class__s     r`   r   Room.__init__   s     	045W335
))*<*<=?((*
8;"58UBD!!0!B!B!(!4!6;?AC!AC!CE"CE""&'+r_   c                    U R                   b4  [        R                  R                  R	                  U R
                  5        g g r   )r   r   instancequeueunsubscribe
_ffi_queuer   s    r`   __del__Room.__del__   s1    '$$00A (r_   c                   #    U R                   R                  (       a  U R                   R                  $ U R                  I Sh  vN $  N7f)zjAsynchronously retrieves the session ID (SID) of the room.

Returns:
    str: The session ID of the room.
N)r   sidr   r   s    r`   r   Room.sid   s2      ::>>::>>!+++++s   AA
AA
c                J    U R                   c  [        S5      eU R                   $ )zkGets the local participant in the room.

Returns:
    LocalParticipant: The local participant in the room.
z1cannot access local participant before connecting)r   	Exceptionr   s    r`   local_participantRoom.local_participant   s(     ""*OPP&&&r_   c                    U R                   $ )zhGets the connection state of the room.

Returns:
    ConnectionState: The connection state of the room.
)r   r   s    r`   connection_stateRoom.connection_state   s     %%%r_   c                    U R                   $ )zGets the remote participants in the room.

Returns:
    dict[str, RemoteParticipant]: A dictionary of remote participants indexed by their
    identity.
)r   r   s    r`   remote_participantsRoom.remote_participants   s     (((r_   c                .    U R                   R                  $ )zDGets the name of the room.

Returns:
    str: The name of the room.
)r   namer   s    r`   r   	Room.name   s     zzr_   c                .    U R                   R                  $ )zYGets the metadata associated with the room.

Returns:
    str: The metadata of the room.
)r   metadatar   s    r`   r   Room.metadata   s     zz"""r_   c                    U R                   $ )zrGets the end-to-end encryption (E2EE) manager for the room.

Returns:
    E2EEManager: The E2EE manager instance.
)_e2ee_managerr   s    r`   e2ee_managerRoom.e2ee_manager   s     !!!r_   c                .    U R                   R                  $ )zGets the number of participants in the room.
This value is updated periodically, and is eventually consistent.

Returns:
    int: The number of participants in the room.
)r   num_participantsr   s    r`   r   Room.num_participants  s     zz***r_   c                .    U R                   R                  $ )zGets the number of publishers in the room.
This value is updated periodically, and is eventually consistent.

Returns:
    int: The number of publishers in the room.
)r   num_publishersr   s    r`   r   Room.num_publishers  s     zz(((r_   c                    [         R                   R                  U R                  R                  S-  [         R                  R
                  5      $ )z`Time when the room was created.

Returns:
    datetime.datetime: The creation time of the room.
  )datetimefromtimestampr   creation_timetimezoneutcr   s    r`   r   Room.creation_time  s=       ..JJ$$t+X->->-B-B
 	
r_   c                .    U R                   R                  $ )ziWhether the room is actively recording.

Returns:
    bool: True if actively recording, False otherwise.
)r   active_recordingr   s    r`   is_recordingRoom.is_recording"  s     zz***r_   c                @    [        U R                  R                  5      $ )zAmount of time to hold the room open after the last standard participant leaves.

Returns:
    float: The departure timeout of the room.
)floatr   departure_timeoutr   s    r`   r   Room.departure_timeout+  s     TZZ1122r_   c                @    [        U R                  R                  5      $ )zrAmount of time to keep the room open if no participants join.

Returns:
    float: The empty timeout of the room.
)r   r   empty_timeoutr   s    r`   r   Room.empty_timeout4  s     TZZ--..r_   c                f    U R                   SL=(       a    U R                  [        R                  :g  $ )zcChecks if the room is currently connected.

Returns:
    bool: True if connected, False otherwise.
N)r   r   r   r   r   s    r`   isconnectedRoom.isconnected=  s1     D( L&&/*K*KK	
r_   c                "   > [         TU ]  X5      $ )a  Registers an event handler for a specific event type.

Parameters:
    event (EventTypes): The name of the event to listen for.
    callback (Callable): The function to call when the event occurs.

Returns:
    Callable: The registered callback function.

Available events:
    - **"participant_connected"**: Called when a new participant joins the room.
        - Arguments: `participant` (RemoteParticipant)
    - **"participant_disconnected"**: Called when a participant leaves the room.
        - Arguments: `participant` (RemoteParticipant)
    - **"participant_active"**: Called when a remote participant becomes active and is ready to receive data messages.
        - Arguments: `participant` (RemoteParticipant)
    - **"local_track_published"**: Called when a local track is published.
        - Arguments: `publication` (LocalTrackPublication), `track` (Track)
    - **"local_track_unpublished"**: Called when a local track is unpublished.
        - Arguments: `publication` (LocalTrackPublication)
    - **"local_track_subscribed"**: Called when a local track is subscribed.
        - Arguments: `track` (Track)
    - **"track_published"**: Called when a remote participant publishes a track.
        - Arguments: `publication` (RemoteTrackPublication), `participant` (RemoteParticipant)
    - **"track_unpublished"**: Called when a remote participant unpublishes a track.
        - Arguments: `publication` (RemoteTrackPublication), `participant` (RemoteParticipant)
    - **"track_subscribed"**: Called when a track is subscribed.
        - Arguments: `track` (Track), `publication` (RemoteTrackPublication), `participant` (RemoteParticipant)
    - **"track_unsubscribed"**: Called when a track is unsubscribed.
        - Arguments: `track` (Track), `publication` (RemoteTrackPublication), `participant` (RemoteParticipant)
    - **"track_subscription_failed"**: Called when a track subscription fails.
        - Arguments: `participant` (RemoteParticipant), `track_sid` (str), `error` (str)
    - **"track_muted"**: Called when a track is muted.
        - Arguments: `participant` (Participant), `publication` (TrackPublication)
    - **"track_unmuted"**: Called when a track is unmuted.
        - Arguments: `participant` (Participant), `publication` (TrackPublication)
    - **"active_speakers_changed"**: Called when the list of active speakers changes.
        - Arguments: `speakers` (list[Participant])
    - **"room_metadata_changed"**: Called when the room's metadata is updated.
        - Arguments: `old_metadata` (str), `new_metadata` (str)
    - **"participant_metadata_changed"**: Called when a participant's metadata is updated.
        - Arguments: `participant` (Participant), `old_metadata` (str), `new_metadata` (str)
    - **"participant_name_changed"**: Called when a participant's name is changed.
        - Arguments: `participant` (Participant), `old_name` (str), `new_name` (str)
    - **"participant_attributes_changed"**: Called when a participant's attributes change.
        - Arguments: `changed_attributes` (dict), `participant` (Participant)
    - **"participant_encryption_status_changed"**: Called when a participant's encryption status changes.
        - Arguments `is_encrypted` (bool), `participant` (Participant)
    - **"connection_quality_changed"**: Called when a participant's connection quality changes.
        - Arguments: `participant` (Participant), `quality` (ConnectionQuality)
    - **"transcription_received"**: Called when a transcription is received.
        - Arguments: `segments` (list[TranscriptionSegment]), `participant` (Participant), `publication` (TrackPublication)
    - **"data_received"**: Called when data is received.
        - Arguments: `data_packet` (DataPacket)
    - **"sip_dtmf_received"**: Called when a SIP DTMF signal is received.
        - Arguments: `sip_dtmf` (SipDTMF)
    - **"e2ee_state_changed"**: Called when a participant's E2EE state changes.
        - Arguments: `participant` (Participant), `state` (EncryptionState)
    - **"connection_state_changed"**: Called when the room's connection state changes.
        - Arguments: `connection_state` (ConnectionState)
    - **"connected"**: Called when the room is successfully connected.
        - Arguments: None
    - **"disconnected"**: Called when the room is disconnected.
        - Arguments: `reason` (DisconnectReason)
    - **"reconnecting"**: Called when the room is attempting to reconnect.
        - Arguments: None
    - **"reconnected"**: Called when the room has successfully reconnected.
        - Arguments: None
    - **"room_updated"**: Called when any information about the room is updated.
        - Arguments: None
    - **"moved"**: Called when the participant has been moved to another room.
        - Arguments: None
    - **"data_track_published"**: Called when a remote participant publishes a data track.
        - Arguments: `track` (RemoteDataTrack)
    - **"data_track_unpublished"**: Called when a remote participant unpublishes a data track.
        - Arguments: `sid` (str)

Example:
    ```python
    def on_participant_connected(participant):
        print(f"Participant connected: {participant.identity}")

    room.on("participant_connected", on_participant_connected)
    ```
)r   on)r   eventcallbackr   s      r`   r   Room.onH  s    l wz%**r_   c                  ^#    Xl         X l        [        R                  " 5       nXR                  l        X$R                  l        UR                  UR                  R                  l        UR                  UR                  R                  l	        UR                  b1  [        UR                  S-  5      UR                  R                  l        UR                  b%  UR                  UR                  R                  l        UR                  (       Ga  [        R                   " S["        SS9  UR                  R$                  UR                  R                  R                  l        UR                  R&                  R(                  UR                  R                  R                  R&                  l        UR                  R&                  R*                  UR                  R                  R                  R&                  l        UR                  R&                  R,                  UR                  R                  R                  R&                  l        UR                  R&                  R.                  UR                  R                  R                  R&                  l        UR0                  (       Gam  UR0                  R$                  UR                  R                  R0                  l        UR0                  R&                  R(                  UR                  R                  R0                  R&                  l        UR0                  R&                  R*                  UR                  R                  R0                  R&                  l        UR0                  R&                  R,                  UR                  R                  R0                  R&                  l        UR0                  R&                  R.                  UR                  R                  R0                  R&                  l        UR2                  (       a  UR2                  R4                  UR                  R                  R2                  l        UR2                  R6                  UR                  R                  R2                  l        UR                  R                  R2                  R8                  R;                  UR2                  R8                  5        [<        R>                  R@                  RC                  U RD                  5      U l#        [<        R>                  R@                  RC                  5       n [<        R>                  RI                  U5      mURK                  U4S j5      I Sh  vN n[<        R>                  R@                  RM                  U5        UR                  RN                  (       aR  [<        R>                  R@                  RM                  U RF                  5        [Q        UR                  RN                  5      e[S        UR                  RT                  RV                  RX                  RZ                  5      U l.        [_        U R\                  RX                  UR0                  =(       d    UR                  5      U l0        UR                  RT                  RV                  Rb                  U l2        [f        Rh                  U l5        [m        U Rn                  UR                  RT                  Rp                  5      U l9        UR                  RT                  Rt                   HT  nU Rw                  URx                  5      nURz                   H&  n	[}        U	5      n
XR~                  U
R                  '   M(     MV     U RD                  R                  U R                  5       5      U lC        g GNC! [<        R>                  R@                  RM                  U5        f = f7f)a  Connects to a LiveKit room using the specified URL and token.

Parameters:
    url (str): The WebSocket URL of the LiveKit server to connect to.
    token (str): The access token for authentication and authorization.
    options (RoomOptions, optional): Additional options for the room connection.

Raises:
    ConnectError: If the connection fails.

Example:
    ```python
    room = Room()

    # Listen for events before connecting to the room
    @room.on("participant_connected")
    def on_participant_connected(participant):
        print(f"Participant connected: {participant.identity}")

    await room.connect("ws://localhost:7880", "your_token")
    ```
Nr   z:options.e2ee is deprecated, use options.encryption instead   )
stacklevelc                ^   > U R                   R                  TR                   R                  :H  $ r   )connectasync_ideresps    r`   <lambda>Room.connect.<locals>.<lambda>  s    !)),,0E0EEr_   )Dr   r   r   
FfiRequestr   urltokenre   optionsrf   rj   rx   connect_timeout_msrk   rg   warningswarnDeprecationWarningencryption_typekey_provider_options
shared_keyratchet_saltfailure_toleranceratchet_window_sizerh   ri   rN   rO   rQ   extendr   r   r   	subscriber   r   requestwait_forr   errorr   r   resultroomhandleidr   r   r   infor   r   CONN_CONNECTEDr   r   r   r   r   participants_create_remote_participantrs   publicationsr    _track_publicationsr   create_task_listen_task_task)r   r   r   r   reqr   cbptrpowned_publication_infopublicationr   s              @r`   r   Room.connect  sn    . ""$! .5-C-C*'.'7'7$"".589P9PSW9W5XCKK2))59@9W9WCKK6<<<MML" 8?||7S7SCKK$$411<< KK$$99D 11>> KK$$99F 11CC KK$$99K 11EE KK$$99M =D=O=O=_=_CKK**:""77BB KK**??J ""77DD KK**??L ""77II KK**??Q ""77KK KK**??S ""55 KK**= ""== KK**E KK**66==g>P>P>\>\] $,,22<<TZZH""((224	8%%--c2D+0>>E, &B $$007::$$00Arzz//00$RZZ%6%6%;%;%B%B%E%EF(##W%7%7%G7<<
 ZZ&&++00
!0!?!?"2bjj//AA#
 **##00B00@B +-//&45KL:E&&{7 +:	 1 ZZ++D,=,=,?@
A& $$007s1   U_37_ ?_ _ H>_3_ +_00_3c                f  ^#    U R                  5       (       d  [        S5      e[        R                  " 5       nU R                  R
                  UR                  l        [        R                  R                  R                  5       n [        R                  R                  U5      mUR                  U4S j5      I S h  vN n[        R                  R                  R                  U5        UR                  R                  (       a  [        UR                  R                  5      e[!        UR                  R"                  R$                  5      n[!        UR                  R"                  R&                  5      n[)        XES9$  N! [        R                  R                  R                  U5        f = f7f)Nzthe room isn't connectedc                ^   > U R                   R                  TR                   R                  :H  $ r   )get_session_statsr   r   s    r`   r   $Room.get_rtc_stats.<locals>.<lambda>'  s"    !--66$:P:P:Y:YYr_   )r   r   )r   RuntimeErrorr   r   r   r  r  room_handler   r   r   r  r  r  r   r  r]   r	  r   r   r}   )r   r  r   r  r   r   r   s         @r`   get_rtc_statsRoom.get_rtc_stats  s<    !!9::""$,0,<,<,C,C)""((224	8%%--c2D+0>>Y, &B $$007%%r3399::r33::JJK 4 4 ; ; L LM[[& $$007s1   BF17F >F?F B>F1F +F..F1c                x    U R                   R                  U5      nUc  X R                   U'   g [        SU-  5      e)Nz.byte stream handler for topic '%s' already set)r   get
ValueErrorr   rt   handlerexisting_handlers       r`   register_byte_stream_handler!Room.register_byte_stream_handler4  ?    5599%@#07&&u-MPUUVVr_   c                |    U R                   R                  U5      (       a  U R                   R                  U5        g g r   )r   r&  popr   rt   s     r`   unregister_byte_stream_handler#Room.unregister_byte_stream_handler;  2    %%))%00&&**51 1r_   c                x    U R                   R                  U5      nUc  X R                   U'   g [        SU-  5      e)Nz.text stream handler for topic '%s' already set)r   r&  r'  r(  s       r`   register_text_stream_handler!Room.register_text_stream_handler?  r-  r_   c                |    U R                   R                  U5      (       a  U R                   R                  U5        g g r   )r   r&  r/  r0  s     r`   unregister_text_stream_handler#Room.unregister_text_stream_handlerF  r3  r_   )reasonc               @  ^#    U R                  5       (       d  gU R                  5       I Sh  vN   U R                  5       I Sh  vN   [        R                  " 5       nU R
                  R                  UR                  l        XR                  l	        [        R                  R                  R                  5       n [        R                  R                  U5      mUR                  U4S j5      I Sh  vN   [        R                  R                  R!                  U5        U R"                  I Sh  vN   [        R                  R                  R!                  U R$                  5        U R&                  [(        R*                  :w  a^  XR,                  R.                  l        [(        R*                  U l        U R3                  SU R&                  5        U R3                  SU5        gg GN GN N! [        R                  R                  R!                  U5        f = f N7f)zDisconnects from the room.Nc                ^   > U R                   R                  TR                   R                  :H  $ r   )
disconnectr   r   s    r`   r   !Room.disconnect.<locals>.<lambda>Z  s    1<<+@+@DOOD\D\+\r_   rA   rC   )r   _drain_rpc_invocation_tasks_drain_data_stream_tasksr   r   r   r  r=  r"  r:  r   r   r   r  r  r  r   r  r   r   r   r   r   r   disconnect_reasonemit)r   r:  r  r   r   s       @r`   r=  Room.disconnectJ  s     !!..000++---""$%)%5%5%<%<" &""((224	8%%--c2D..!\]]]$$007jj  ,,T__= !!_%F%FF=C""((:%4%F%FD"II0$2H2HIIInf-	 G% 	1- ^$$007sY   *HG&HG)A6H=7G. 4G,5G. 98H1H2B5H)H,G. .+HHc                  #     U R                   R                  5       I S h  vN nUR                  S5      S:X  a  U R                  UR                  5        OkUR
                  R                  U R                  R                  :X  a=  UR
                  R                  S5      (       a  O[ U R                  UR
                  5        U R                  R                  U5        U R                  R!                  5       I S h  vN   M  U R#                  5       I S h  vN   U R%                  5       I S h  vN   g  GN! [         a>    [        R                  " SUR
                  R                  S5      UR
                  5         Nf = f N Nm NW7f)Nr   rpc_method_invocationeosz&error running user callback for %s: %s)r   r&  
WhichOneof_on_rpc_method_invocationrE  
room_eventr"  r   r  HasField_on_room_eventr   logging	exceptionr   
put_nowaitjoinr?  r@  )r   r   s     r`   r  Room._listen_taski  sB    //--//E	*.EE..u/J/JK!!--1A1A1H1HH##,,U33''(8(89 ''.""'')))) . ..000++---/ 0 ! %%@((33I>(( * 	1-se   FD2BF'D5 8F:F ;FFF,F-F5AE=:F<E==FFFc                   U R                   c  g UR                  U R                   R                  R                  :X  a  U R                  R                  U R                   R                  UR                  UR                  UR                  UR                  UR                  UR                  S-  5      5      nU R                  R                  U5        UR                  U R                  R                   5        g g )Ng     @@)r   local_participant_handler   r  r   r  _handle_rpc_method_invocationinvocation_idmethod
request_idcaller_identitypayloadresponse_timeout_msr   addadd_done_callbackdiscard)r   rpc_invocationtasks      r`   rH  Room._on_rpc_method_invocation  s    ""*22d6M6M6Y6Y6`6``::))''EE"00"))"--"22"**"66?	D &&**40""4#=#=#E#EF ar_   c                !   UR                  S5      nUS:X  a8  U R                  UR                  R                  5      nU R	                  SU5        g US:X  ai  UR
                  R                  nU R                  R                  U5      nUR
                  R                  UR                  l	        U R	                  SU5        g US:X  a_  U R                  UR                  R                  5      nU(       a2  [        R                  UR                  l        U R	                  SU5        g g US:X  aN  UR                   R"                  nU R$                  R&                  U   nUR(                  nU R	                  SXx5        g US:X  aB  UR*                  R,                  nU R$                  R&                  U   nU R	                  SU5        g US:X  ag  UR.                  R"                  nU R$                  R&                  U   nUR0                  R3                  S 5        U R	                  SUR(                  5        g US:X  am  U R                  UR4                  R                     n[7        UR4                  R8                  5      n	XR:                  U	R<                  '   U R	                  SX5        g US	:X  ae  U R                  UR>                  R                     nUR:                  R                  UR>                  R,                  5      n	U R	                  S	X5        g US
:X  a  UR@                  R(                  n
U
R                  nU R                  UR@                  R                     nUR&                  UR<                     n	SU	l!        URD                  [F        RH                  :X  a%  [K        U
5      nXl&        U R	                  S
XU5        g URD                  [F        RN                  :X  a%  [Q        U
5      nXl&        U R	                  S
XU5        g g US:X  av  URR                  R                  nU R                  U   nUR&                  URR                  R"                     n	U	R(                  nS U	l&        SU	l!        U R	                  SXU5        g US:X  ad  URT                  R                  nU R                  U   nURT                  RV                  nU R	                  SUURT                  R"                  U5        g US:X  a  URX                  R                  nU R[                  U5      n[]        U[^        5      (       d   eUR&                  URX                  R"                     nSUR                  l0        UR(                  (       a  SUR(                  R                  l0        U R	                  SUU5        g US:X  a  URb                  R                  nU R[                  U5      n[]        U[^        5      (       d   eUR&                  URb                  R"                     nSUR                  l0        UR(                  (       a  SUR(                  R                  l0        U R	                  SUU5        g US:X  ak  / nURd                  Rf                   H<  nU R[                  U5      n[]        U[^        5      (       d   eURi                  U5        M>     U R	                  SU5        g US:X  aO  U Rj                  nURl                  Rj                  U R                  l5        U R	                  SUU Rj                  5        g US:X  ap  U R                  R<                  (       d/  U Rn                  R3                  URp                  R<                  5        URp                  R<                  U R                  l        g US:X  a  URr                  R                  nU R[                  U5      n[]        U[^        5      (       d   eURj                  nURr                  Rj                  UR                  l5        U R	                  SUUURj                  5        g US:X  a  URt                  R                  nU R[                  U5      n[]        U[^        5      (       d   eURv                  nURt                  Rv                  UR                  l;        U R	                  SUUURv                  5        g US:X  a  URx                  R                  nURx                  Rz                  n[}        S URx                  R~                   5       5      nU R[                  U5      n[]        U[^        5      (       d   eUR                  Rz                  R                  5         UR                  Rz                  R                  S U 5       5        U R	                  SUU5        g US:X  aO  UR                  R                  nU R[                  U5      nU R	                  SUUR                  R                  5        g US:X  a  UR                  R                  nU R[                  U5      n[]        U[^        5      (       d   eUR                  R                  R                  UR                  R                  5        U R	                  SUUR                  5        g US:X  aO  UR                  R                  nU R[                  U5      nU R	                  SUUR                  R                  5        g US:X  a  UR                  nUR                   Vs/ s HM  n[        UR                  UR                  UR                  UR                  UR                  UR                  S9PMO     nnU R[                  UR                  5      nS nU(       a%  UR&                  R                  UR"                  5      nU R	                  SUUU5        g US:X  Ga  UR                  nUR                  S5      nUS :X  Ga  UR                  R                  nUR                  n[        R                  " UR                  [        R                  " [        R                  UR                  -  5      5      R                  n [        U 5      n![        UR                  R                  5      R                  5         [        [        U R                  UR                  5      5      nU R	                  S![        U!URD                  UUR                  R                  S"95        g US#:X  am  [        [        U R                  UR                  5      5      nU R	                  S$[        UR                  R                  UR                  R                  US%95        g g US&:X  aO  UR                  R                  nUR                  R                  n"U R	                  S&U R[                  U5      U"5        g US':X  a0  UR                  R                  n#U#U lk        U R	                  S'U#5        g US(:X  a'  U R	                  S(UR                  R                  5        g US):X  a  U R	                  S)5        g US*:X  a  U R	                  S*5        g US+:X  a;  U R                  UR                  R                  UR                  R                  5        g US,:X  az  [        R                  " U R                  UR                  R                  5      5      n$U R                  R                  U$5        U$R                  U R                  R                  5        g US-:X  az  [        R                  " U R                  UR                  R                  5      5      n$U R                  R                  U$5        U$R                  U R                  R                  5        g US.:X  a#  UR                  U l
        U R	                  S.5        g US/:X  a#  UR                  U l
        U R	                  S/5        g US0:X  aK  UR                  GR                    H/  n%U R[                  U%GR                  5      nU(       d  M(  U%Ul
        M1     g US1:X  a/  UGR                  GR                  U l        U R	                  S15        g US2:X  a4  G[        UGR                  R(                  5      n&U R	                  S2U&5        g US3:X  a(  U R	                  S3UGR                  R<                  5        g g s  snf )4Nr   r(   r)   r*   r+   r,   r-   r.   r/   r0   Tr1   Fr2   r3   r4   r5   r6   room_sid_changedr7   r8   r9   c              3  R   #    U  H  nUR                   UR                  4v   M     g 7fr   keyvalue.0entrys     r`   	<genexpr>&Room._on_room_event.<locals>.<genexpr>  s$      &TE EKK(Ts   %'c              3  P   #    U  H  oR                   UR                  4v   M     g 7fr   rc  rf  s     r`   ri  rj  %  s     /aV`UEKK0HV`s   $&r;   r<   r:   r?   )r  textfinal
start_timeend_timelanguagedata_packet_receivedre  userr=   )rp   rq   rs   rt   sip_dtmfr>   )ry   r{   rs   r@   rA   rC   rD   rE   stream_header_receivedstream_chunk_receivedstream_trailer_receivedrF   rG   participants_updatedrH   rI   rJ   )rG  r  r(   r  rB  r)   participant_identityr   r/  rA  r   _retrieve_remote_participantr*   proto_participantPARTICIPANT_STATE_ACTIVEstater+   	track_sidr   track_publicationstrackr,   publication_sidr-   _first_subscription
set_resultr.   r    r  r  r   r/   r0   _subscribedrq   r   
KIND_VIDEOr   _track
KIND_AUDIOr   r1   r2   r  r3   _retrieve_participant
isinstancer   mutedr4   r5   participant_identitiesappendr   r6   r   ra  r7   r8   r   r9   
attributesdictchanged_attributesclearupdater;   is_encryptedparticipant_permission_changed
permissionCopyFrompermissionsr:   qualityr?   segmentsr"   r  rl  rm  rn  ro  rp  r&  rq  rr  rp   ctypesr
   data_ptrPOINTERc_bytedata_lencontentsro   r   r  disposer   rm   rt   rv   rs  ry   r{   r@   rA   r   rC   r:  _handle_stream_headerrt  headerr   r  _handle_stream_chunkru  chunkr   rZ  r[  r\  _handle_stream_trailerrv  trailerrF   rG   rw  r  identityrH   r   r   r'   rI   rJ   )'r   r   whichrparticipantr  r  r   lpublicationltrackrpublicationowned_track_info
track_inforemote_video_trackremote_audio_trackrtrackr  rs   r  speakersold_metadataold_namer  r  transcriptionsr  partpubpacket	which_valowned_buffer_infobuffer_infonative_datarp   
e2ee_stater   r^  r  remote_data_tracks'                                          r`   rK  Room._on_room_event  s     +++::5;V;V;[;[\LII-|<0055JJH4488BL383Q3Q3c3cL0II0,?**2253K3K3`3`aB!2!K!K		.3  ----77C11DDSIL!''FII-|D////??C11DDSILII/>....88C11DDSIL,,77=II.0B0BC''44U5J5J5_5_`L1%2G2G2S2STLAM,,\-=-=>II'D))44U5L5L5a5abL';;??''77L II)<F(($55;;)..J44U5K5K5`5`aL':::>>JL'+L$)"6"66%56F%G"&8#		,.@P\]I$8$88%56F%G"&8#		,.@P\] 9 **//DDH44X>L'::5;S;S;];]^L!''F"&L',L$II*F,O1166KKH44X>L3399EII+//99	 m#((==H44X>Kk;7777%889J9J9T9TUK&*K#  04!!''-IIm[+>o%**??H44X>Kk;7777%889L9L9V9VWK&+K#  05!!''-IIo{K@//*,H!99PP"88B!+{;;;;, Q
 II/:--==L"'"="="F"FDJJII-|T]]K((::>>&&11%2H2H2L2LM"3377DJJN4499NNH44X>Kk;7777&//L).)K)K)T)TK&II.$$	 0055JJH44X>Kk;7777"''H%*%C%C%H%HK"II0+xIYIYZ66;;PPH==HHJ!% &"AATT& " 44X>Kk;7777((..0((///aV`/aaII0"
 ==BBWWH44X>KII7;;HH
 77;;PPH44X>Kk;7777((11%2V2V2a2abII1''
 2277LLH44X>KII,0088
 ..!88M '//
 0A %tt'' ||ZZZZ 0  
 --m.P.PQD+/C--11-2I2IJII.$D,,//F))'2IF"$*KK$4$4!/44$kk((NN6==;3G3G#GH ( 
 [)+22556>>@#%55f6Q6QR  		#!#[[$0$kk//	 j(#%55f6Q6QR  		'#__11$oo33$0 ) **//DDH1177JII*D,F,Fx,PR\]00$==CC%5D"II02BCn$IIne&8&8&?&?@n$IIn%m#IIm$..&&,,33,,AA --&&t'@'@A\A\AbAb'cdD##''-""4#:#:#B#BC//&&++E,I,I,Q,QRD ##''-""4#:#:#B#BCn$++DJIIn%gDJIIg,,22??"88G;(,K% @
 ''//55DKII'(,, /0J0J0P0P QII,.?@..II.0L0L0P0PQ /[
s    AACc                D   UR                  S5      nUS:X  av  U R                  R                  UR                  5      nUc"  [        R
                  " SUR                  5        g [        U5      nXPR                  UR                  '   U" XR5        g US:X  av  U R                  R                  UR                  5      nUc"  [        R
                  " SUR                  5        g [        U5      nXpR                  UR                  '   U" Xr5        g [        R                  " SU5        g )Ncontent_headertext_headerz:ignoring text stream with topic '%s', no callback attachedbyte_headerz:ignoring byte stream with topic '%s', no callback attachedz received unknown header type, %s)rG  r   r&  rt   rL  r  r#   r   	stream_idr   r$   r   warning)r   r  rx  stream_typetext_stream_handlertext_readerbyte_stream_handlerbyte_readers           r`   r  Room._handle_stream_header  s	    ''(89-'"&"<"<"@"@"N"*PLL *62K:E%%f&6&67B 	 M)"&"<"<"@"@"N"*PLL *62K:E%%f&6&67B 	 OO>Lr_   c                ,  #    U R                   R                  UR                  5      nU R                  R                  UR                  5      nU(       a  UR	                  U5      I S h  vN   g U(       a  UR	                  U5      I S h  vN   g g  N' N7fr   )r   r&  r  r   _on_chunk_update)r   r  r  file_readers       r`   r  Room._handle_stream_chunk  st     //33EOOD//33EOOD..u555..u555  65s$   A&B(B) B	B
BBc                  #    U R                   R                  UR                  5      nU R                  R                  UR                  5      nU(       a?  UR	                  U5      I S h  vN   U R                   R                  UR                  5        g U(       a?  UR	                  U5      I S h  vN   U R                  R                  UR                  5        g g  Nq N-7fr   )r   r&  r  r   _on_stream_closer/  )r   r  r  r  s       r`   r  Room._handle_stream_trailer  s     //33G4E4EF//33G4E4EF..w777%%))'*;*;<..w777%%))'*;*;<  8 8s%   A&C(C)AC.C/,CCc                   #    U R                   (       aL  U R                    H  nUR                  5         M     [        R                  " U R                   SS06I S h  vN   g g  N7fNreturn_exceptionsT)r   cancelr   gatherr   r^  s     r`   r?   Room._drain_rpc_invocation_tasks  sP     %%22 3..$"<"<UPTUUU & V   AA#A!A#c                   #    U R                   (       aL  U R                    H  nUR                  5         M     [        R                  " U R                   SS06I S h  vN   g g  N7fr  )r   r  r   r  r  s     r`   r@  Room._drain_data_stream_tasks  sO     ""// 0..$"9"9RTRRR # Sr  c                :    U R                   R                  US5      $ )z)Retrieve a remote participant by identityN)r   r&  r   r  s     r`   ry  !Room._retrieve_remote_participant  s    ((,,Xt<<r_   c                |    U(       a%  XR                   R                  :X  a  U R                   $ U R                  U5      $ )z2Retrieve a local or remote participant by identity)r   r  ry  r  s     r`   r  Room._retrieve_participant  s3    $:$:$C$CC)))00::r_   c                    UR                   R                  U R                  ;   a  [        S5      e[	        U5      nX R                  UR                  '   U$ )Nzparticipant already exists)r  r  r   r   r   )r   
owned_infors   s      r`   r  Room._create_remote_participant  sL     ??##t'@'@@899'
3:E!!+"6"67r_   c           
         SnU R                   R                  5       (       a  U R                   R                  5       nSU SU R                   SU R                   S[
        R                  " U R                  5       S3	$ )Nunknownzrtc.Room(sid=z, name=z, metadata=z, connection_state=))r   doner	  r   r   r   Namer   )r   r   s     r`   __repr__Room.__repr__  s    !!&&((((//1Cse7499+[Obcrcwcwx|  yO  yO  dP  cQ  QR  S  	Sr_   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   )r   z#Optional[asyncio.AbstractEventLoop]returnNone)r  r  )r  rz   )r  r   )r  zConnectionState.ValueType)r  zMapping[str, RemoteParticipant])r  r   )r  rx   )r  zdatetime.datetime)r  rd   )r  r   )r   
EventTypesr   zOptional[Callable]r  r   )r   rz   r   rz   r   rb   r  r  )r  r}   )rt   rz   r)  r&   )rt   rz   )rt   rz   r)  r%   )r:  zDisconnectReason.ValueTyper  r  )r]  r   )r   zproto_room.RoomEvent)r  zproto_room.DataStream.Headerrx  rz   )r  zproto_room.DataStream.Chunk)r  zproto_room.DataStream.Trailer)r  rz   r  zOptional[RemoteParticipant])r  rz   r  zOptional[Participant])r  z"proto_participant.OwnedParticipantr  r   ).rS   rT   rU   rV   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rb   r   r#  r+  r1  r5  r8  r   CLIENT_INITIATEDr=  r  rH  rK  r  r  r  r?  r@  ry  r  r  r  r^   __classcell__)r   s   @r`   r   r      s    59,1, 
, ,>B 	, 	, 	' 	' & & ) )   # # " " + + ) ) 
 
 + + 3 3 / /	
V+ V+p JU zAx\0W2W2
 7G6W6W.3.	.>.8G$_RB	2JM@6	=VS=;<	S Sr_   r   )H
__future__r   r   r   r  rL  dataclassesr   r   typingr   r   r   r	   r
   r   r   event_emitterr   _ffi_clientr   r   _protor   r   r   rz  r   rW   r   proto_stats_proto.participant_pb2r   _proto.room_pb2r   _proto.track_pb2r   _proto.rpc_pb2r   _utilsr   rg   r   r   rs   r   r   r   r  r   r   track_publicationr    r!   r  r"   data_streamr#   r$   r%   r&   
data_trackr'   r  rL   rb   rm   rv   r}   r   r   r   rR   r_   r`   <module>r      s   #     ( C C  ' - ( 8 * , 4 , ' 4 " * I I 5 G /  ( "$
N    l l l  1 1 1 O O O 1 1 1
9 
yS<
# ySr_   