
    /jr              	         S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	J
r
JrJrJrJrJrJrJr  S SKJr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)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2  SSK-J3r3  SSK4J5r5J6r6J7r7J8r8  SSK9J:r:  SSKJ;r<   " S S\=5      r> " S S\=5      r? " S S\=5      r@ " S S\=5      rA " S S \=5      rB " S! S"\=5      rC " S# S$\5      rD\S%/\
\\\E      \\E   4   4   rF\" S&\\3/\
\\\E      \\E   4   4   S'9rG " S( S)\D5      rH " S* S+\D5      rIg),    )annotationsN)	ListUnionCallableDict	AwaitableOptionalMappingcastTypeVar)abstractmethodABC   )	FfiClient	FfiHandle)ffi_pb2)participant_pb2)TrackPublishOptions)TranscriptionSegment)ParticipantTrackPermission)BroadcastQueue)
LocalTrack)LocalTrackPublicationRemoteTrackPublicationTrackPublication)Transcription)RpcError)"RpcMethodInvocationResponseRequest)logger)RpcInvocationData)TextStreamWriterByteStreamWriterByteStreamInfoSTREAM_CHUNK_SIZE)LocalDataTrack)data_track_pb2c                      \ rS rSrSS jrSrg)PublishTrackError=   c                    Xl         g Nmessageselfr-   s     H/app/agent/.venv/lib/python3.13/site-packages/livekit/rtc/participant.py__init__PublishTrackError.__init__>           r,   Nr-   strreturnNone__name__
__module____qualname____firstlineno__r1   __static_attributes__ r4   r0   r(   r(   =       r4   r(   c                      \ rS rSrSS jrSrg)UnpublishTrackErrorB   c                    Xl         g r+   r,   r.   s     r0   r1   UnpublishTrackError.__init__C   r3   r4   r,   Nr5   r9   r?   r4   r0   rB   rB   B   r@   r4   rB   c                      \ rS rSrSS jrSrg)PublishDataErrorG   c                    Xl         g r+   r,   r.   s     r0   r1   PublishDataError.__init__H   r3   r4   r,   Nr5   r9   r?   r4   r0   rG   rG   G   r@   r4   rG   c                      \ rS rSrSS jrSrg)PublishDTMFErrorL   c                    Xl         g r+   r,   r.   s     r0   r1   PublishDTMFError.__init__M   r3   r4   r,   Nr5   r9   r?   r4   r0   rL   rL   L   r@   r4   rL   c                      \ rS rSrSS jrSrg)PublishTranscriptionErrorQ   c                    Xl         g r+   r,   r.   s     r0   r1   "PublishTranscriptionError.__init__R   r3   r4   r,   Nr5   r9   r?   r4   r0   rQ   rQ   Q   r@   r4   rQ   c                      \ rS rSrSS jrSrg)PublishDataTrackErrorV   c                    Xl         g r+   r,   r.   s     r0   r1   PublishDataTrackError.__init__W   r3   r4   r,   Nr5   r9   r?   r4   r0   rV   rV   V   r@   r4   rV   c                     \ rS rSrSS jr\\SS j5       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5       r\SS j5       r\SS j5       r\  SS j5       rSrg)Participant[   c                n    UR                   U l        [        UR                  R                  5      U l        g r+   )info_infor   handleid_ffi_handle)r/   
owned_infos     r0   r1   Participant.__init__\   s&    __
$Z%6%6%9%9:r4   c                    g)E
A dictionary of track publications associated with the participant.
Nr?   r/   s    r0   track_publicationsParticipant.track_publications`   s     	r4   c                .    U R                   R                  $ r+   )r_   sidrg   s    r0   rk   Participant.sidh   s    zz~~r4   c                .    U R                   R                  $ r+   )r_   namerg   s    r0   rn   Participant.namel   s    zzr4   c                .    U R                   R                  $ r+   )r_   identityrg   s    r0   rq   Participant.identityp       zz"""r4   c                .    U R                   R                  $ r+   )r_   metadatarg   s    r0   ru   Participant.metadatat   rs   r4   c                @    [        U R                  R                  5      $ )z2Custom attributes associated with the participant.)dictr_   
attributesrg   s    r0   ry   Participant.attributesx   s     DJJ))**r4   c                .    U R                   R                  $ )zLParticipant's kind (e.g., regular participant, ingress, egress, sip, agent).)r_   kindrg   s    r0   r|   Participant.kind}   s     zzr4   c                .    U R                   R                  $ )zGParticipant's connection state (joining, joined, active, disconnected).)r_   staterg   s    r0   r   Participant.state   s     zzr4   c                    U R                   R                  S:X  a  g[        R                  R                  U R                   R                  S-  [        R                  R
                  S9$ )zMTimestamp of when the participant joined the room, or None if not yet joined.r   N  )tz)r_   	joined_atdatetimefromtimestamptimezoneutcrg   s    r0   r   Participant.joined_at   sW     ::1$  ..JJ  4'H,=,=,A,A / 
 	
r4   c                .    U R                   R                  $ )z.The participant's permissions within the room.)r_   
permissionrg   s    r0   permissionsParticipant.permissions   s     zz$$$r4   c                    U R                   R                  [        R                  R                  :X  a  gU R                   R                  $ )aX  Reason for the participant's disconnection.

Returns one of DisconnectReasons or None if the participant isn't disconnected. Common reasons are:
- CLIENT_INITIATED - the client initiated the disconnect
- DUPLICATE_IDENTITY - another participant with the same identity has joined the room
- SERVER_SHUTDOWN - the server instance is shutting down
- PARTICIPANT_REMOVED - RoomService.RemoveParticipant was called
- ROOM_DELETED - RoomService.DeleteRoom was called
- STATE_MISMATCH - the client is attempting to resume a session, but server is not aware of it
- JOIN_FAILURE - client was unable to connect fully

When dialing a participant via SIP, you may see the following reasons:
- USER_UNAVAILABLE - SIP callee did not respond in time
- USER_REJECTED - SIP callee rejected the call (busy)
- SIP_TRUNK_FAILURE - SIP protocol failure or unexpected response
N)r_   disconnect_reasonproto_participantDisconnectReasonUNKNOWN_REASONrg   s    r0   r   Participant.disconnect_reason   s6    ( ::''+<+M+M+\+\\zz+++r4   )rb   r_   Nrc   "proto_participant.OwnedParticipantr7   r8   )r7   zMapping[str, TrackPublication]r7   r6   )r7   dict[str, str])r7   z+proto_participant.ParticipantKind.ValueType)r7   z,proto_participant.ParticipantState.ValueType)r7   zdatetime.datetime | None)r7   z'proto_participant.ParticipantPermission)r7   z6Optional[proto_participant.DisconnectReason.ValueType])r:   r;   r<   r=   r1   propertyr   rh   rk   rn   rq   ru   ry   r|   r   r   r   r   r>   r?   r4   r0   r[   r[   [   s    ;        # # # # + +       
 
 % % ,	?, ,r4   r[   r    F)boundc                  L  ^  \ rS rSrSr      S$U 4S jjr\S%S j5       rS/ SS.         S&S jjrS'S	 jr	S(S
 jr
SS.         S)S jjr S*     S+S jjrS,S jrSS.     S-S jjr              S.S jrS/S jrS0S jrS1S jrSSSSSSSS.               S2S jjrSSSSS.         S3S jjrSSSSSSS.               S4S jjrSSSSS.           S5S jjr    S6S jr\" 5       4     S7S  jjrS8S! jrS9S" jrS#rU =r$ ):LocalParticipant   z+Represents the local participant in a room.c                L   > [         TU ]  U5        Xl        0 U l        0 U l        g r+   )superr1   _room_queue_track_publications_rpc_handlers)r/   
room_queuerc   	__class__s      r0   r1   LocalParticipant.__init__   s(    
 	$%EG 46r4   c                    U R                   $ rf   r   rg   s    r0   rh   #LocalParticipant.track_publications       
 '''r4   T )reliabledestination_identitiestopicc                 ^
#    [        U[        5      (       a  UR                  S5      n[        U5      n[        R
                  U-  " U6 n[        R                  " 5       nU R                  R                  UR                  l        [        R                  " U5      UR                  l        XWR                  l        X'R                  l        XGR                  l        UR                  R"                  R%                  U5        [&        R(                  R*                  R-                  5       n [&        R(                  R/                  U5      m
UR1                  U
4S j5      I Sh  vN n	[&        R(                  R*                  R3                  U5        U	R                  R4                  (       a  [7        U	R                  R4                  5      eg Nh! [&        R(                  R*                  R3                  U5        f = f7f)a  
Publish arbitrary data to the room.

Args:
    payload (Union[bytes, str]): The data to publish.
    reliable (bool, optional): Whether to send reliably or not. Defaults to True.
    destination_identities (List[str], optional): List of participant identities to send to. Defaults to [].
    topic (str, optional): The topic under which to publish the data. Defaults to "".

Raises:
    PublishDataError: If there is an error in publishing data.
zutf-8c                ^   > U R                   R                  TR                   R                  :H  $ r+   )publish_dataasync_ideresps    r0   <lambda>/LocalParticipant.publish_data.<locals>.<lambda>   s     !..11T5F5F5O5OOr4   N)
isinstancer6   encodelenctypesc_byte	proto_ffi
FfiRequestrb   r`   r   local_participant_handle	addressofdata_ptrdata_lenr   r   r   extendr   instancequeue	subscriberequestwait_forunsubscribeerrorrG   )r/   payloadr   r   r   r   cdatareqr   cbr   s             @r0   r   LocalParticipant.publish_data   so    ( gs##nnW-Gw<)G4""$484D4D4K4K1$*$4$4U$;!$,!$,!!&//667MN""((224	8%%--c2D+0>>O, &B $$007??  "2??#8#899 !& $$007s1   D$G8(7G
 G G
 $A$G8G
 
+G55G8c                 ^#    [         R                  " 5       nU R                  R                  UR                  l        X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 n[        R                  R                  R                  U5        UR                  R                  (       a  [!        UR                  R                  5      eg Nh! [        R                  R                  R                  U5        f = f7f)z
Publish SIP DTMF message.

Args:
    code (int): DTMF code.
    digit (str): DTMF digit.

Raises:
    PublishDTMFError: If there is an error in publishing SIP DTMF message.
c                ^   > U R                   R                  TR                   R                  :H  $ r+   )publish_sip_dtmfr   r   s    r0   r   /LocalParticipant.publish_dtmf.<locals>.<lambda>
  s"    !,,559N9N9W9WWr4   N)r   r   rb   r`   r   r   codedigitr   r   r   r   r   r   r   r   rL   )r/   r   r   r   r   r   r   s         @r0   publish_dtmfLocalParticipant.publish_dtmf   s      ""$8<8H8H8O8O5$(!%*"""((224	8%%--c2D+0>>W, &B $$007$$"2#6#6#<#<== %& $$007s1   BE7D) >D'?D) A$E'D) )+EEc                  ^#    [         R                  " 5       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                  R                  UR                  l        UR                  UR                  l        UR                  R                  R                  U5        U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(                  R1                  U5        UR                  R2                  (       a  [5        UR                  R2                  5      egs  snf  Nm! [$        R&                  R(                  R1                  U5        f = f7f)z
Publish transcription data to the room.

Args:
    transcription (Transcription): The transcription data to publish.

Raises:
    PublishTranscriptionError: If there is an error in publishing transcription.
)ra   text
start_timeend_timefinallanguagec                ^   > U R                   R                  TR                   R                  :H  $ r+   )publish_transcriptionr   r   s    r0   r   8LocalParticipant.publish_transcription.<locals>.<lambda>2  s"    !11::d>X>X>a>aar4   N)r   r   segmentsProtoTranscriptionSegmentra   r   r   r   r   r   rb   r`   r   r   participant_identityr   	track_sidtrack_idr   r   r   r   r   r   r   r   rQ   )r/   transcriptionr   sproto_segmentsr   r   r   s          @r0   r   &LocalParticipant.publish_transcription  s     ""$ #++

 , &44VV<<gg , 	 

 >B=M=M=T=T!!:9F9[9[!!6!!**11.A-:-D-D!!*""((224	8%%--c2D+0>>a, &B $$007##))+B,D,D,J,JKK *5

(& $$007s=   $G;AG;B*G;&7G GG "A)G;G +G88G;N)response_timeoutc               \  ^#    [         R                  " 5       nU R                  R                  UR                  l        XR                  l        X%R                  l        X5R                  l        Ub  [        US-  5      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%                  S5      (       a*  [&        R(                  " UR                  R*                  5      eUR                  R                  $  N! [        R                  R                  R#                  U5        f = f7f)a  
Initiate an RPC call to a remote participant.

Args:
    destination_identity (str): The `identity` of the destination participant
    method (str): The method name to call
    payload (str): The method payload
    response_timeout (Optional[float]): Timeout for receiving a response after initial connection

Returns:
    str: The response payload

Raises:
    RpcError: On failure. Details in `message`.
Nr   c                ^   > U R                   R                  TR                   R                  :H  $ r+   )perform_rpcr   r   s    r0   r   .LocalParticipant.perform_rpc.<locals>.<lambda>\  s     0F0F$JZJZJcJc0cr4   r   )r   r   rb   r`   r   r   destination_identitymethodr   intresponse_timeout_msr   r   r   r   r   r   r   HasFieldr   _from_protor   )	r/   r   r   r   r   r   r   r   r   s	           @r0   r   LocalParticipant.perform_rpc:  s+    . ""$373C3C3J3J0/C,!'")'256F6M2NCOO/""((224	8%%--c2D~~&cddB$$007>>""7++&&r~~';';<<~~%%% e$$007s1   B3F,77E> .E</E> 3B	F,<E> >+F))F,c                2   ^ ^ SUU 4S jjnUb  U" U5      $ U$ )a  
Establishes the participant as a receiver for calls of the specified RPC method.
Can be used either as a decorator or a regular method.

The handler will receive one argument of type `RpcInvocationData` and should return a string response which will be forwarded back to the caller.

The handler may be synchronous or asynchronous.

If unable to respond within `response_timeout`, the caller will hang up and receive an error on their side.

You may raise errors of type `RpcError` in the handler, and they will be forwarded to the caller.

Other errors raised in your handler will be caught and forwarded to the caller as "1500 Application Error".

Args:
    method_name (str): The name of the indicated RPC method.
    handler (Optional[Callable]): Handler to be invoked whenever an RPC request for this method is received.  Omit this argument to use the decorator syntax.

Returns:
    None (when used as a decorator it returns the decorator function)

Example:
    # As a decorator:
    @room.local_participant.register_rpc_method("greet")
    async def greet_handler(data: RpcInvocationData) -> str:
        print(f"Received greeting from {data.caller_identity}: {data.payload}")
        return f"Hello, {data.caller_identity}!"

    # As a regular method:
    async def greet_handler(data: RpcInvocationData) -> str:
        print(f"Received greeting from {data.caller_identity}: {data.payload}")
        return f"Hello, {data.caller_identity}!"

    room.local_participant.register_rpc_method('greet', greet_handler)
c                   > U TR                   T'   [        R                  " 5       nTR                  R                  UR
                  l        TUR
                  l        [        R                  R                  U5        U $ r+   )r   r   r   rb   r`   register_rpc_methodr   r   r   r   r   )handler_funcr   method_namer/   s     r0   register6LocalParticipant.register_rpc_method.<locals>.register  sc    .:D{+&&(C?C?O?O?V?VC##<-8C##*&&s+r4   )r   r   r7   r   r?   )r/   r   handlerr   s   ``  r0   r   $LocalParticipant.register_rpc_methode  s&    R	  	  G$$Or4   c                   U R                   R                  US5        [        R                  " 5       nU R                  R
                  UR                  l        XR                  l        [        R                  R                  U5        g)zs
Unregisters a previously registered RPC method.

Args:
    method (str): The name of the RPC method to unregister
N)r   popr   r   rb   r`   unregister_rpc_methodr   r   r   r   r   )r/   r   r   s      r0   r  &LocalParticipant.unregister_rpc_method  sb     	vt,""$=A=M=M=T=T!!:+1!!(""3'r4   )participant_permissionsc               *   Uc  / n[         R                  " 5       nU R                  R                  UR                  l        XR                  l        UR                  R                  R                  U5        [        R                  R                  U5        g)a\  
Set the track subscription permissions for the local participant.

Args:
    allow_all_participants (bool): Whether to allow all participants to subscribe to this participant's tracks.
    participant_permissions (List[ParticipantTrackPermission]): Participant-specific track subscription permissions, ignored if `allow_all_participants` is True.
N)r   r   rb   r`   "set_track_subscription_permissionsr   all_participants_allowedr   r   r   r   r   )r/   allow_all_participantsr  r   s       r0   r  3LocalParticipant.set_track_subscription_permissions  ss     #*&(#""$JNJZJZJaJa..GJ`..G..::AABYZ""3'r4   c           	       #    S nS n[        X4XV5      n	U R                  R                  U5      n
U
(       d/  [        R                  " [        R
                  R                  5      nO_ [        R                  " U
5      (       a%   [        R                  " U
" U	5      US9I S h  vN nO[        [        [            U
" U	5      5      n [*        R,                  " [/        U R0                  R2                  UU(       a  UR5                  5       OS US9S9n[6        R8                  R;                  U5      nUR<                  R>                  (       a0  UR<                  R>                  n[$        R>                  " SU 35        g g  N! [        R                   a/    [        R                  " [        R
                  R                  5      e[        R                   a/    [        R                  " [        R
                  R                  5      ef = f! [         a  nUn S nAGNOS nAf["         aL    [$        R&                  " SU S35        [        R                  " [        R
                  R(                  5      n GNf = f7f)N)timeoutz+Uncaught error returned by RPC handler for z'. Returning APPLICATION_ERROR instead. )r   invocation_idr   r   )rpc_method_invocation_responsez.error sending rpc method invocation response: ) r    r   getr   	_built_in	ErrorCodeUNSUPPORTED_METHODasyncioiscoroutinefunctionr   TimeoutErrorRESPONSE_TIMEOUTCancelledErrorRECIPIENT_DISCONNECTEDr   r	   r6   	Exceptionr   	exceptionAPPLICATION_ERRORr   r   r   rb   r`   	_to_protor   r   r   r  r   )r/   r  r   
request_idcaller_identityr   r   response_errorresponse_payloadparamsr   r   r   reserrs                  r0   _handle_rpc_method_invocation.LocalParticipant._handle_rpc_method_invocation  s     .2*.":Z$$((0%//0B0B0U0UVNZ..w77\181A1A#FO5E2 ,( (,HSM76?'K$ ""+M)-)9)9)@)@+4Bn..0(	,
   ((---3344::CLLI#OP 4;, #// V&001C1C1T1TUU"11 \&001C1C1Z1Z[[\  '!& Z  A& J< < "*!3!3H4F4F4X4X!YZso   A"I.%H  E9 E7 E9 $I.%H  B5I.7E9 9BG==H   
I+
HI.AI+'I.*I++I.c                  ^#    [         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        g N.! [        R                  R                  R                  U5        f = f7f)z
Set the metadata for the local participant.

Note: this requires `canUpdateOwnMetadata` permission.

Args:
    metadata (str): The new metadata.
c                ^   > U R                   R                  TR                   R                  :H  $ r+   )set_local_metadatar   r   s    r0   r   /LocalParticipant.set_metadata.<locals>.<lambda>  "    !..774;R;R;[;[[r4   N)r   r   rb   r`   r&  r   ru   r   r   r   r   r   r   r   )r/   ru   r   r   r   s       @r0   set_metadataLocalParticipant.set_metadata  s      ""$:>:J:J:Q:Q7*2'""((224	8%%--c2D..[   $$007	 $$0070   A3D77C .C/C 3*DC +D

Dc                  ^#    [         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        g N.! [        R                  R                  R                  U5        f = f7f)z
Set the name for the local participant.

Note: this requires `canUpdateOwnMetadata` permission.

Args:
    name (str): The new name.
c                ^   > U R                   R                  TR                   R                  :H  $ r+   )set_local_namer   r   s    r0   r   +LocalParticipant.set_name.<locals>.<lambda>  s"    !**33t7J7J7S7SSr4   N)r   r   rb   r`   r.  r   rn   r   r   r   r   r   r   r   )r/   rn   r   r   r   s       @r0   set_nameLocalParticipant.set_name  s      ""$6:6F6F6M6M3"&""((224	8%%--c2D..S   $$007	 $$007r+  c                0  ^#    [         R                  " 5       nU R                  R                  UR                  l        UR                  R                   Vs0 s H  o3R                  UR                  _M     nnUR                  U5        UR                  5        H5  u  pVUR                  R                  R                  5       nXSl        Xcl        M7     [        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        gs  snf  N3! [        R                  R                  R%                  U5        f = f7f)z
Set custom attributes for the local participant.

Note: this requires `canUpdateOwnMetadata` permission.

Args:
    attributes (dict[str, str]): A dictionary of attributes to set.
c                ^   > U R                   R                  TR                   R                  :H  $ r+   )set_local_attributesr   r   s    r0   r   1LocalParticipant.set_attributes.<locals>.<lambda><  s"    !0099T=V=V=_=__r4   N)r   r   rb   r`   r4  r   ry   keyvalueupdateitemsaddr   r   r   r   r   r   r   )	r/   ry   r   entryexisting_attributesr6  r7  r   r   s	           @r0   set_attributesLocalParticipant.set_attributes#  s@     ""$<@<L<L<S<S  9030H0H0S0S
0SuIIu{{"0S 	 
 	"":.-335JC,,77;;=EIK 6
 ""((224	8%%--c2D.._   $$007#
 $$007s=   AF E!6BF;7E( 2E&3E( 7/F&E( (+FF)r   r   ry   	stream_idreply_to_id
total_sizesender_identityc               b   #    [        U UUUUUUUS9nUR                  5       I Sh  vN   U$  N7f)z
Returns a TextStreamWriter that allows to write individual chunks of text to a text stream.
In most cases where you want to simply send a text message use send_text() instead.
)r   ry   r@  r   rA  r?  rB  N)r!   _send_header)	r/   r   r   ry   r?  r@  rA  rB  writers	            r0   stream_textLocalParticipant.stream_textA  sG      "!##9!+	
 !!### 	$   $/-/)r   r   ry   r@  c                  #    [        UR                  5       5      nU R                  UUUUUS9I S h  vN nUR                  U5      I S h  vN   UR	                  5       I S h  vN   UR
                  $  NA N* N7f)N)r   r   ry   r@  rA  )r   r   rF  writeacloser^   )r/   r   r   r   ry   r@  rA  rE  s           r0   	send_textLocalParticipant.send_text_  sz      '
''#9!#! ( 
 
 ll4   mmo{{
 	!s3   0A:A4A:A6A:#A8$A:6A:8A:application/octet-stream)rA  	mime_typery   r?  r   r   c               b   #    [        U UUUUUUUS9nUR                  5       I Sh  vN   U$  N7f)z
Returns a ByteStreamWriter that allows to write individual chunks of bytes to a byte stream.
In cases where you want to simply send a file from the file system use send_file() instead.
)rn   ry   rA  r?  rO  r   r   N)r"   rD  )	r/   rn   rA  rO  ry   r?  r   r   rE  s	            r0   stream_bytesLocalParticipant.stream_bytesv  sG      "!!#9	
 !!### 	$rH  )r   r   ry   r?  c          
       #    [         R                  R                  U5      n[         R                  R                  U5      n[        R
                  " U5      u  pUc  SnU R                  UUUUUUUS9I S h  vN n
[        R                  " US5       IS h  vN nUR                  [        5      I S h  vN =n(       a?  U
R                  U5      I S h  vN   UR                  [        5      I S h  vN =n(       a  M?  S S S 5      IS h  vN   U
R                  5       I S h  vN   U
R                  $  N N N Nd NI N2! , IS h  vN  (       d  f       NG= f N67f)NrN  )rn   rA  rO  ry   r?  r   r   rb)ospathgetsizebasename	mimetypes
guess_typerQ  aiofilesopenreadr$   rJ  rK  r^   )r/   	file_pathr   r   ry   r?  	file_size	file_namerO  _rE  fbytess                r0   	send_fileLocalParticipant.send_file  s     GGOOI.	GG$$Y/	 ++I6	2I)-):): !#9 *; *
 $
 ==D11Q!"(9!:::%:ll5))) "#(9!:::%: 21 mmo{{$
 2:) ; 2111 	s   A4E6D27ED4ED>3D64D>D8D>0D:1D>>E	D<
E!E"E4E6D>8D>:D><E>EEEEc               >  ^#    [         R                  " US9n[        R                  " 5       nU R                  R
                  UR                  l        UR                  R                  R                  U5        [        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#                  S5      (       a)  [%        UR                  R&                  R(                  5      e[+        UR                  R,                  5      $  N! [        R                  R                  R!                  U5        f = f7f)al  Publishes a data track.

Args:
    name: The track name used to identify the track to other participants.
        Must not be empty and must be unique per publisher.

Returns:
    The published data track. Use :meth:`LocalDataTrack.try_push` to
    send data frames on the track.

Raises:
    PublishDataTrackError: If there is an error publishing the data track.
)rn   c                ^   > U R                   R                  TR                   R                  :H  $ r+   )publish_data_trackr   r   s    r0   r   5LocalParticipant.publish_data_track.<locals>.<lambda>  r(  r4   Nr   )proto_data_trackDataTrackOptionsr   r   rb   r`   rh  r   optionsCopyFromr   r   r   r   r   r   r   r   rV   r   r-   r%   track)r/   rn   
proto_optsr   r   r   r   s         @r0   rh  #LocalParticipant.publish_data_track  s.    $ &66DA
""$:>:J:J:Q:Q7&&//
;""((224	8%%--c2D+0>>[, &B $$007  ))'22'(=(=(C(C(K(KLLb3399::& $$007s1   BF 7E/ E-E/ BF-E/ /+FFc                  ^#    [         R                  " 5       nUR                  R                  UR                  l        U R                  R                  UR                  l        UR                  R                  R                  U5        U R                  R                  5       n [        R                  R                  U5      mUR                  U4S j5      I Sh  vN nUR                  R                  (       a  [!        UR                  R                  5      e[#        UR                  R$                  5      nXl        UR(                  UR*                  l        X`R,                  UR(                  '   UR/                  5         UU R                  R1                  U5        $  N! U R                  R1                  U5        f = f7f)aC  
Publish a local track to the room.

Args:
    track (LocalTrack): The track to publish.
    options (TrackPublishOptions, optional): Options for publishing the track.

Returns:
    LocalTrackPublication: The publication of the published track.

Raises:
    PublishTrackError: If there is an error in publishing the track.
c                ^   > U R                   R                  TR                   R                  :H  $ r+   )publish_trackr   r   s    r0   r   0LocalParticipant.publish_track.<locals>.<lambda>  s     !//22d6H6H6Q6QQr4   N)r   r   rb   r`   rs  track_handler   rl  rm  r   r   r   r   r   r   r   r(   r   publication_trackrk   r_   r   	task_doner   )r/   rn  rl  r   r   r   track_publicationr   s          @r0   rs  LocalParticipant.publish_track  sQ      ""$).):):)A)A&595E5E5L5L2!!**73  **,	0%%--c2D+0>>Q, &B %%'(8(8(>(>?? 5b6F6F6R6R S',$/33EKKO>O$$%6%:%:;OO$((/& ((/s1   BG #7F  FB'F  G F   F==G c                  ^#    [         R                  " 5       nU R                  R                  UR                  l        XR                  l        SUR                  l        U R                  R                  5       n [        R                  R                  U5      mUR                  U4S j5      I Sh  vN nUR                  R                  (       a  [        UR                  R                  5      eU R                   R#                  U5      nSUl        UR'                  5         U R                  R)                  U5        g N! U R                  R)                  U5        f = f7f)z
Unpublish a track from the room.

Args:
    track_sid (str): The SID of the track to unpublish.

Raises:
    UnpublishTrackError: If there is an error in unpublishing the track.
Tc                ^   > U R                   R                  TR                   R                  :H  $ r+   )unpublish_trackr   r   s    r0   r   2LocalParticipant.unpublish_track.<locals>.<lambda>  s"    !++448L8L8U8UUr4   N)r   r   rb   r`   r}  r   r   stop_on_unpublishr   r   r   r   r   r   r   rB   r   r   rw  rx  r   )r/   r   r   r   r   rv  r   s         @r0   r}   LocalParticipant.unpublish_track  s     ""$7;7G7G7N7N4(1%04-  **,	0%%--c2D+0>>U, &B !!'')"*<*<*B*BCC2266yAK!%KOO((/& ((/s1   A6E :7E  1D>2A0E  "E >E   EE c                V    SU R                    SU R                   SU R                   S3$ )Nzrtc.LocalParticipant(sid=, identity=, name=)rk   rq   rn   rg   s    r0   __repr__LocalParticipant.__repr__"  s.    *488*KgVZV_V_U``abbr4   )r   r   r   )r   z"BroadcastQueue[proto_ffi.FfiEvent]rc   r   r7   r8   )r7   z#Mapping[str, LocalTrackPublication])
r   zUnion[bytes, str]r   boolr   z	List[str]r   r6   r7   r8   )r   r   r   r6   r7   r8   )r   r   r7   r8   )
r   r6   r   r6   r   r6   r   zOptional[float]r7   r6   r+   )r   r6   r   zOptional[F]r7   zUnion[F, Callable[[F], F]])r   r6   r7   r8   )r  r  r  z*Optional[List[ParticipantTrackPermission]]r7   r8   )r  r   r   r6   r  r6   r  r6   r   r6   r   floatr7   r8   )ru   r6   r7   r8   )rn   r6   r7   r8   )ry   r   r7   r8   )r   Optional[List[str]]r   r6   ry   Optional[Dict[str, str]]r?  
str | Noner@  r  rA  
int | NonerB  r  r7   r!   )
r   r6   r   r  r   r6   ry   r  r@  r  )rn   r6   rA  r  rO  r6   ry   r  r?  r  r   r  r   r6   r7   r"   )r^  r6   r   r6   r   r  ry   r  r?  r  r7   r#   )rn   r6   r7   r%   )rn  r   rl  r   r7   r   )r   r6   r7   r8   r   )r:   r;   r<   r=   __doc__r1   r   rh   r   r   r   r   r   r  r  r"  r)  r0  r=  rF  rL  rQ  rd  rh  r   rs  r}  r  r>   __classcell__r   s   @r0   r   r      s7   5767 77 
	7 ( ( ,.,:",: 	,:
 !*,: ,: 
,:\>8&L\ -1)& ")& 	)&
 )& *)& 
)&\  $44 4 
$	4l(& OS	( !%( "L	(
 
(,5Q5Q 5Q 	5Q
 5Q 5Q  5Q 
5Qn8,8,8B 7;/3 $"&!%&* !4 	
 -     $ 
D 7;/3"& !4	
  -  6 "&3/3 $6: 	
  -  !4  
D 6:/3 $ 	
 !4 -  
@$; $; 
	$;N AT@U'0'0*='0	'0R0>c cr4   r   c                  J   ^  \ rS rSrSU 4S jjr\SS j5       rSS jrSrU =r	$ )	RemoteParticipanti&  c                2   > [         TU ]  U5        0 U l        g r+   )r   r1   r   )r/   rc   r   s     r0   r1   RemoteParticipant.__init__'  s    $FH r4   c                    U R                   $ r   r   rg   s    r0   rh   $RemoteParticipant.track_publications+  r   r4   c                V    SU R                    SU R                   SU R                   S3$ )Nzrtc.RemoteParticipant(sid=r  r  r  r  rg   s    r0   r  RemoteParticipant.__repr__2  s.    +DHH:[wW[W`W`Vaabccr4   r   r   )r7   z$Mapping[str, RemoteTrackPublication]r   )
r:   r;   r<   r=   r1   r   rh   r  r>   r  r  s   @r0   r  r  &  s)    I ( (d dr4   r  )J
__future__r   r   r  r   rU  rY  r[  typingr   r   r   r   r   r	   r
   r   r   abcr   r   _ffi_clientr   r   _protor   r   r   r   _proto.room_pb2r   r   r   _proto.track_pb2r   _utilsr   rn  r   ry  r   r   r   r   r   rpcr   _proto.rpc_pb2r   logr   r    data_streamr!   r"   r#   r$   
data_trackr%   r&   rj  r  r(   rB   rG   rL   rQ   rV   r[   r6   
RpcHandlerr   r   r  r?   r4   r0   <module>r     sM   #    	   [ [ [ # - ( 8 #  
 )  >  "  ' 6	 
) 
y 
y 
	 
I 
P,# P,f *+U9Xc]3KXVY]3Z-[[\
x*+U9Xc]3KXVY]3Z-[[\
o	c{ o	cdd dr4   