
    q	hP                       S SK J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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$J%r%  SSK&J'r'J(r(J)r)  SSK*J+r+J,r,  SSK-J.r.J/r/  SSK0J1r1  SSK2J3r3J4r4J5r5J6r6  \S   r7\ " S S5      5       r8\ " S S5      5       r9\ " S S5      5       r:\ " S S5      5       r; " S S\<5      r= " S  S!\\7   5      r>g)"    )annotationsN)	dataclassfield)CallableDictLiteralOptionalcastMapping   )EventEmitter)	FfiClient	FfiHandle)ffi_pb2)participant_pb2)room_pb2)ConnectionState)	TrackKind)RpcMethodInvocationEvent)BroadcastQueue)E2EEManagerE2EEOptions)LocalParticipantParticipantRemoteParticipant)RemoteAudioTrackRemoteVideoTrack)RemoteTrackPublicationTrackPublication)TranscriptionSegment)TextStreamReaderByteStreamReaderTextStreamHandlerByteStreamHandler)participant_connectedparticipant_disconnected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data_receivedsip_dtmf_receivedtranscription_receivede2ee_state_changedconnection_state_changed	connecteddisconnectedreconnectingreconnectedc                      \ rS rSr% \R
                  R                  rS\S'    \R                  R                  rS\S'    \" \S9rS\S'   S	rg
)RtcConfigurationK   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_ALLrC   __annotations__ContinualGatheringPolicyGATHER_CONTINUALLYrD   r   listrF   __static_attributes__rG       B/var/www/html/env/lib/python3.13/site-packages/livekit/rtc/room.pyrA   rA   K   s\     	##11 =  S++>>  M  <.3D.IK+IrT   rA   c                  R    \ rS rSr% SrS\S'    SrS\S'   SrS\S	'    SrS
\S'   Sr	g)RoomOptionsZ   Tboolauto_subscribeFdynacastNzE2EEOptions | Nonee2eezRtcConfiguration | None
rtc_configrG   )
rH   rI   rJ   rK   rZ   rO   r[   r\   r]   rS   rG   rT   rU   rW   rW   Z   s5    NDCHd#D
#,*.J'.'rT   rW   c                  H    \ rS rSr% S\S'    S\S'    S\S'    SrS	\S
'   Srg)
DataPackete   bytesdataz#proto_room.DataPacketKind.ValueTypekindRemoteParticipant | NoneparticipantNz
str | NonetopicrG   )rH   rI   rJ   rK   rO   rf   rS   rG   rT   rU   r_   r_   e   s)    
K)
--:))HE:0rT   r_   c                  <    \ rS rSr% S\S'    S\S'    SrS\S'   S	rg)
SipDTMFq   intcodestrdigitNrd   re   rG   )rH   rI   rJ   rK   rO   re   rS   rG   rT   rU   rh   rh   q   s     
I/J,0K)0NrT   rh   c                      \ rS rSrSS jrSrg)ConnectError{   c                    Xl         g Nmessage)selfrt   s     rU   __init__ConnectError.__init__|   s    rT   rs   N)rt   rl   )rH   rI   rJ   rK   rv   rS   rG   rT   rU   ro   ro   {   s    rT   ro   c                    ^  \ 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S(S jrS S)U 4S jjjr\" 5       4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    S0S jrS1S jrS2S jrS"S jrS"S jrS3S jrS4S jr     S5S jr!S#S jr"Sr#U =r$$ )6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        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)superrv   _ffi_handleasyncioget_event_loop_loopr   	proto_ffiFfiEvent_room_queuerL   RoomInfo_infoset_rpc_invocation_tasks_data_stream_tasks_remote_participantsr   CONN_DISCONNECTED_connection_stateFuturerl   _first_sid_future_local_participant_text_stream_readers_byte_stream_readers_text_stream_handlers_byte_stream_handlers)ru   loop	__class__s     rU   rv   Room.__init__   s     	045W335
))*<*<=?((*
8;"58UBD!!0!B!B!(!4!6;?AC!AC!CE"CE"rT   c                    U R                   b4  [        R                  R                  R	                  U R
                  5        g g rr   )r}   r   instancequeueunsubscribe
_ffi_queueru   s    rU   __del__Room.__del__   s1    '$$00A (rT   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    rU   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    rU   local_participantRoom.local_participant   s(     ""*OPP&&&rT   c                    U R                   $ )zhGets the connection state of the room.

Returns:
    ConnectionState: The connection state of the room.
)r   r   s    rU   connection_stateRoom.connection_state   s     %%%rT   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    rU   remote_participantsRoom.remote_participants   s     (((rT   c                .    U R                   R                  $ )zDGets the name of the room.

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

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

Returns:
    E2EEManager: The E2EE manager instance.
)_e2ee_managerr   s    rU   e2ee_managerRoom.e2ee_manager   s     !!!rT   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    rU   isconnectedRoom.isconnected   s1     D( L&&/*K*KK	
rT   c                "   > [         TU ]  X5      $ )aP  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)
    - **"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)
    - **"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

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

    room.on("participant_connected", on_participant_connected)
    ```
)r|   on)ru   eventcallbackr   s      rU   r   Room.on   s    T wz%**rT   c                  ^#    [         R                  " 5       nXR                  l        X$R                  l        UR
                  UR                  R                  l        UR                  UR                  R                  l        UR                  (       Gam  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R                  (       a  UR                  R                   UR                  R                  R                  l        UR                  R"                  UR                  R                  R                  l        UR                  R                  R                  R$                  R'                  UR                  R$                  5        [(        R*                  R,                  R/                  U R0                  5      U l        [(        R*                  R,                  R/                  5       n [(        R*                  R5                  U5      mUR7                  U4S j5      I Sh  vN n[(        R*                  R,                  R9                  U5        UR                  R:                  (       aR  [(        R*                  R,                  R9                  U R2                  5        [=        UR                  R:                  5      e[?        UR                  R@                  RB                  RD                  RF                  5      U l$        [K        U RH                  RD                  UR                  5      U l&        UR                  R@                  RB                  RN                  U l(        [R        RT                  U l+        [Y        U RZ                  UR                  R@                  R\                  5      U l/        UR                  R@                  R`                   HT  nU Rc                  URd                  5      nURf                   H&  n	[i        U	5      n
XRj                  U
Rl                  '   M(     MV     U R0                  Ro                  U Rq                  5       5      U l9        g GN0! [(        R*                  R,                  R9                  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")
    ```
c                ^   > U R                   R                  TR                   R                  :H  $ rr   )connectasync_ideresps    rU   <lambda>Room.connect.<locals>.<lambda>|  s    !)),,0E0EErT   N):r   
FfiRequestr   urltokenrZ   optionsr[   r\   encryption_typekey_provider_options
shared_keyratchet_saltfailure_toleranceratchet_window_sizer]   rC   rD   rF   extendr   r   r   	subscriber   r   requestwait_forr   errorro   r   resultroomhandleidr}   r   r   infor   r   CONN_CONNECTEDr   r   r   r   r   participants_create_remote_participantre   publicationsr   _track_publicationsr   create_task_listen_task_task)ru   r   r   r   reqr   cbptrpowned_publication_infopublicationr   s              @rU   r   Room.connect>  s    . ""$! .5-C-C*'.'7'7$<<<7>||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 ""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()9)9)@)@',,OZZ&&++00
!0!?!?"2bjj//AA#
 **##00B00@B +-//&45KL:E&&{7 +:	 1 ZZ++D,=,=,?@
=& $$007s1   L/W37V *V+V /H+WV +WW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ru   rf   handlerexisting_handlers       rU   register_byte_stream_handler!Room.register_byte_stream_handler  ?    5599%@#07&&u-MPUUVVrT   c                |    U R                   R                  U5      (       a  U R                   R                  U5        g g rr   )r   r   popru   rf   s     rU   unregister_byte_stream_handler#Room.unregister_byte_stream_handler  2    %%))%00&&**51 1rT   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       rU   register_text_stream_handler!Room.register_text_stream_handler  r   rT   c                |    U R                   R                  U5      (       a  U R                   R                  U5        g g rr   )r   r   r   r   s     rU   unregister_text_stream_handler#Room.unregister_text_stream_handler  r   rT   c                (  ^#    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        [        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        g GN- GN N{! [        R                  R                  R                  U5        f = f Nn7f)zDisconnects from the room.Nc                ^   > U R                   R                  TR                   R                  :H  $ rr   )
disconnectr   r   s    rU   r   !Room.disconnect.<locals>.<lambda>  s    1<<+@+@DOOD\D\+\rT   )r   _drain_rpc_invocation_tasks_drain_data_stream_tasksr   r   r}   r   r   room_handler   r   r   r   r   r   r   r   r   )ru   r   r   r   s      @rU   r   Room.disconnect  s    !!..000++---""$%)%5%5%<%<"""((224	8%%--c2D..!\]]]$$007jj  ,,T__= 	1- ^$$007sX   *FEFEA&F-7E" $E %E" )8F!F"9FF E" "+FF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)Nrt   rpc_method_invocationeosz&error running user callback for %s: %s)r   r   
WhichOneof_on_rpc_method_invocationr  
room_eventr  r}   r   HasField_on_room_eventr   logging	exceptionr   
put_nowaitjoinr  r  )ru   r   s     rU   r   Room._listen_task  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)ru   rpc_invocationtasks      rU   r
  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rT   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  aN  UR                  R                  nU R                  R                  U   nUR                  nU R	                  SXg5        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R&                  R)                  S 5        U R	                  SUR                  5        g US:X  am  U R                  UR*                  R                     n[-        UR*                  R.                  5      nXR0                  UR2                  '   U R	                  SX5        g US:X  ae  U R                  UR4                  R                     nUR0                  R                  UR4                  R"                  5      nU R	                  SX5        g US	:X  a  UR6                  R                  n	U	R                  n
U R                  UR6                  R                     nUR                  U
R2                     nS
Ul        U
R:                  [<        R>                  :X  a%  [A        U	5      nXl!        U R	                  S	XU5        g U
R:                  [<        RD                  :X  a%  [G        U	5      nXl!        U R	                  S	XU5        g g US:X  av  URH                  R                  nU R                  U   nUR                  URH                  R                     nUR                  nS Ul!        SUl        U R	                  SXU5        g US:X  ad  URJ                  R                  nU R                  U   nURJ                  RL                  nU R	                  SUURJ                  R                  U5        g US:X  a  URN                  R                  nU RQ                  U5      n[S        U[T        5      (       d   eUR                  URN                  R                     nS
UR                  l+        UR                  (       a  S
UR                  R                  l+        U R	                  SUU5        g US:X  a  URX                  R                  nU RQ                  U5      n[S        U[T        5      (       d   eUR                  URX                  R                     nSUR                  l+        UR                  (       a  SUR                  R                  l+        U R	                  SUU5        g US:X  ak  / nURZ                  R\                   H<  nU RQ                  U5      n[S        U[T        5      (       d   eUR_                  U5        M>     U R	                  SU5        g US:X  aO  U R`                  nURb                  R`                  U R                  l0        U R	                  SUU R`                  5        g US:X  ap  U R                  R2                  (       d/  U Rd                  R)                  URf                  R2                  5        URf                  R2                  U R                  l        g US:X  a  URh                  R                  nU RQ                  U5      n[S        U[T        5      (       d   eUR`                  nURh                  R`                  UR                  l0        U R	                  SUUUR`                  5        g US:X  a  URj                  R                  nU RQ                  U5      n[S        U[T        5      (       d   eURl                  nURj                  Rl                  UR                  l6        U R	                  SUUURl                  5        g US:X  a  URn                  R                  nURn                  Rp                  n[s        S URn                  Rt                   5       5      nU RQ                  U5      n[S        U[T        5      (       d   eUR                  Rp                  Rw                  5         UR                  Rp                  Ry                  S U 5       5        U R	                  SUU5        g US:X  aO  URz                  R                  nU RQ                  U5      nU R	                  SUURz                  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 RQ                  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        [        [        U R                  UR                  5      5      nU R	                  S[        U UR:                  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 RQ                  U5      U!5        g US$:X  a0  UR                  R                  n"U"U la        U R	                  S$U"5        g US%:X  a  U R	                  S%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 g s  snf ),Nrt   r%   r&   r'   r(   r)   r*   r+   r,   Tr-   Fr.   r/   r0   r1   r2   room_sid_changedr3   r4   r5   c              3  R   #    U  H  nUR                   UR                  4v   M     g 7frr   keyvalue.0entrys     rU   	<genexpr>&Room._on_room_event.<locals>.<genexpr>t  s$      &TE EKK(Ts   %'c              3  P   #    U  H  oR                   UR                  4v   M     g 7frr   r%  r(  s     rU   r+  r,  {  s     /aV`UEKK0HV`s   $&r6   r9   )r   textfinal
start_timeend_timelanguagedata_packet_receivedr'  userr7   )rb   rc   re   rf   sip_dtmfr8   )rk   rm   re   r:   r;   r<   r=   r>   r?   stream_header_receivedstream_chunk_receivedstream_trailer_received)sr	  r   r%   r   emitr&   participant_identityr   r   disconnect_reasonr   r'   	track_sidr   track_publicationstrackr(   publication_sidr)   _first_subscription
set_resultr*   r   r   r   r   r+   r,   _subscribedrc   r   
KIND_VIDEOr   _track
KIND_AUDIOr   r-   r.   r   r/   _retrieve_participant
isinstancer   mutedr0   r1   participant_identitiesappendr   r2   r   r#  r3   r4   r   r5   
attributesdictchanged_attributesclearupdater6   qualityr9   segmentsr    r   r.  r/  r0  r1  r2  r   r3  r4  rb   ctypesr
   data_ptrPOINTERc_bytedata_lencontentsra   r   r   r   _retrieve_remote_participantr_   rf   rh   r5  rk   rm   r:   stater;   r   r=   reason_handle_stream_headerr6  headerr~   r   _handle_stream_chunkr7  chunkr   r  r  r  _handle_stream_trailerr8  trailer)$ru   r   whichrparticipantidentityr   lpublicationltrackrpublicationowned_track_info
track_inforemote_video_trackremote_audio_trackrtrackr   re   r   speakersold_metadataold_namerK  rM  transcriptionsrQ  partpubpacket	which_valowned_buffer_infobuffer_infonative_datarb   
e2ee_stater   r   s$                                       rU   r  Room._on_room_event  s     +++::5;V;V;[;[\LII-|<0055JJH4488BL383Q3Q3c3cL0II0,?----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"
 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k!IIk"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 0e
s   +Ay
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)r	  r   r   rf   r  r   r!   r   	stream_idr   r"   r   warning)ru   r\  r:  stream_typetext_stream_handlertext_readerbyte_stream_handlerbyte_readers           rU   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rT   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rr   )r   r   r~  r   _on_chunk_update)ru   r^  r  file_readers       rU   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rr   )r   r   r~  r   _on_stream_closer   )ru   r`  r  r  s       rU   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ru   r   s     rU   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     rU   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   ru   rc  s     rU   rX  !Room._retrieve_remote_participant%  s    ((,,Xt<<rT   c                |    U(       a%  XR                   R                  :X  a  U R                   $ U R                  U5      $ )z2Retrieve a local or remote participant by identity)r   rc  rX  r  s     rU   rF  Room._retrieve_participant)  s3    $:$:$C$CC)))00::rT   c                    UR                   R                  U R                  ;   a  [        S5      e[	        U5      nX R                  UR                  '   U$ )Nzparticipant already exists)r   rc  r   r   r   )ru   
owned_infore   s      rU   r   Room._create_remote_participant0  sL     ??##t'@'@@899'
3:E!!+"6"67rT   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   )ru   r   s     rU   __repr__Room.__repr__:  s    !!&&((((//1Cse7499+[Obcrcwcwx|  yO  yO  dP  cQ  QR  S  	SrT   )r   r   r   r   r   r}   r   r   r   r   r   r   r   r   r   r   r   rr   )r   z#Optional[asyncio.AbstractEventLoop]returnNone)r  r  )r  rl   )r  r   )r  zConnectionState.ValueType)r  zMapping[str, RemoteParticipant])r  r   )r  rY   )r   
EventTypesr   zOptional[Callable]r  r   )r   rl   r   rl   r   rW   r  r  )rf   rl   r   r$   )rf   rl   )rf   rl   r   r#   )r  r   )r   zproto_room.RoomEvent)r\  zproto_room.DataStream.Headerr:  rl   )r^  zproto_room.DataStream.Chunk)r`  zproto_room.DataStream.Trailer)rc  rl   r  zOptional[RemoteParticipant])rc  rl   r  zOptional[Participant])r  z"proto_participant.OwnedParticipantr  r   )%rH   rI   rJ   rK   rv   r   propertyr   r   r   r   r   r   r   r   r   rW   r   r   r   r   r   r   r   r
  r  r[  r]  r_  r  r  rX  rF  r   r  rS   __classcell__)r   s   @rU   ry   ry      sb    59F1F 
F F8B 	, 	, 	' 	' & & ) )   # # " "	
J+ J+X JU [AzW2W2>&.8G$qDf2JM@6	=VS=;<	S SrT   ry   )?
__future__r   r~   rR  r  dataclassesr   r   typingr   r   r   r	   r
   r   event_emitterr   _ffi_clientr   r   _protor   r   r   proto_participantr   rL   _proto.room_pb2r   _proto.track_pb2r   _proto.rpc_pb2r   _utilsr   r\   r   r   re   r   r   r   r>  r   r   track_publicationr   r   ro  r    data_streamr!   r"   r#   r$   r  rA   rW   r_   rh   r   ro   ry   rG   rT   rU   <module>r     s    #    ( C C ' - ( 8 * , ' 4 " * I I 5 G /  
>    ( ( ( 1 1 1 O O O9 

S<
# 
SrT   