o
    di                     @   sx   d dl Z d dlmZ d dlmZmZ d dlmZ ddlm	Z	 e 
eZeG dd dZG d	d
 d
eZddlmZ dS )    N)	dataclass)OptionalUnion)AsyncIOEventEmitter   )InvalidStateErrorc                   @   s~   e Zd ZU dZdZeed< 	 dZee	 ed< 	 dZ
ee	 ed< 	 dZeed< 	 dZeed	< 	 d
Zeed< 	 dZee	 ed< dS )RTCDataChannelParameterszy
    The :class:`RTCDataChannelParameters` dictionary describes the
    configuration of an :class:`RTCDataChannel`.
     labelNmaxPacketLifeTimemaxRetransmitsTorderedprotocolF
negotiatedid)__name__
__module____qualname____doc__r
   str__annotations__r   r   intr   r   boolr   r   r    r   r   I/home/ubuntu/.local/lib/python3.10/site-packages/aiortc/rtcdatachannel.pyr      s    
 r   c                	       s  e Zd ZdZ	d5dddededdf fd	d
ZedefddZ	edefddZ
e
jdeddfddZ
edefddZedee fddZedefddZedefddZedee fddZedee fddZedefddZedefdd Zed6d!d"Zd7d#d$Zd%eeef ddfd&d'Zd(eddfd)d*Zd+eddfd,d-Zd.eddfd/d0Zd1ed2eddfd3d4Z  Z S )8RTCDataChannela  
    The :class:`RTCDataChannel` interface represents a network channel which
    can be used for bidirectional peer-to-peer transfers of arbitrary data.

    :param transport: An :class:`RTCSctpTransport`.
    :param parameters: An :class:`RTCDataChannelParameters`.
    T	transportRTCSctpTransport
parameters	send_openreturnNc                    s   t    d| _d| _|j| _|| _d| _|| _|| _	| jj
r2| jd u s.| jdk s.| jdkr2td| jj
sF| j	rDd| _	| j|  d S d S | j|  d S )Nr   
connectingi  zEID must be in range 0-65534 if data channel is negotiated out-of-bandF)super__init___RTCDataChannel__bufferedAmount+_RTCDataChannel__bufferedAmountLowThresholdr   _RTCDataChannel__id_RTCDataChannel__parameters_RTCDataChannel__readyState_RTCDataChannel__transport_RTCDataChannel__send_openr   
ValueError_data_channel_open_data_channel_add_negotiated)selfr   r   r   	__class__r   r   r#   8   s&   
zRTCDataChannel.__init__c                 C      | j S )z`
        The number of bytes of data currently queued to be sent over the data channel.
        )r$   r.   r   r   r   bufferedAmountU      zRTCDataChannel.bufferedAmountc                 C   r1   )zY
        The number of bytes of buffered outgoing data that is considered "low".
        )r%   r2   r   r   r   bufferedAmountLowThreshold\   r4   z)RTCDataChannel.bufferedAmountLowThresholdvaluec                 C   s"   |dk s|dkrt d|| _d S )Nr   l    z:bufferedAmountLowThreshold must be in range 0 - 4294967295)r+   r%   )r.   r6   r   r   r   r5   c   s
   
c                 C      | j jS )zB
        Whether data channel was negotiated out-of-band.
        )r'   r   r2   r   r   r   r   k      zRTCDataChannel.negotiatedc                 C   r1   )zJ
        An ID number which uniquely identifies the data channel.
        r&   r2   r   r   r   r   r   r4   zRTCDataChannel.idc                 C   r7   )zj
        A name describing the data channel.

        These labels are not required to be unique.
        )r'   r
   r2   r   r   r   r
   y   s   zRTCDataChannel.labelc                 C   r7   )zm
        Indicates whether or not the data channel guarantees in-order delivery of
        messages.
        )r'   r   r2   r   r   r   r      s   zRTCDataChannel.orderedc                 C   r7   )z\
        The maximum time in milliseconds during which transmissions are attempted.
        )r'   r   r2   r   r   r   r      r8   z RTCDataChannel.maxPacketLifeTimec                 C   r7   )zL
        "The maximum number of retransmissions that are attempted.
        )r'   r   r2   r   r   r   r      r8   zRTCDataChannel.maxRetransmitsc                 C   r7   )z5
        The name of the subprotocol in use.
        )r'   r   r2   r   r   r   r      r8   zRTCDataChannel.protocolc                 C   r1   )zY
        A string indicating the current state of the underlying data transport.
        )r(   r2   r   r   r   
readyState   r4   zRTCDataChannel.readyStatec                 C   r1   )zO
        The :class:`RTCSctpTransport` over which data is transmitted.
        )r)   r2   r   r   r   r      r4   zRTCDataChannel.transportc                 C   s   | j |  dS )z)
        Close the data channel.
        N)r   _data_channel_closer2   r   r   r   close   s   zRTCDataChannel.closedatac                 C   s@   | j dkrtt|ttfstdt| | j| | dS )zI
        Send `data` across the data channel to the remote peer.
        openz#Cannot send unsupported data type: N)	r:   r   
isinstancer   bytesr+   typer   _data_channel_send)r.   r=   r   r   r   send   s
   
zRTCDataChannel.sendamountc                 C   s@   | j | jko| j | | jk}|  j |7  _ |r| d d S d S )Nbufferedamountlow)r$   r5   emit)r.   rD   crosses_thresholdr   r   r   _addBufferedAmount   s   z!RTCDataChannel._addBufferedAmountr   c                 C   s
   || _ d S )Nr9   )r.   r   r   r   r   _setId   s   
zRTCDataChannel._setIdstatec                 C   s\   || j kr*| d| j | || _ |dkr| d d S |dkr,| d |   d S d S d S )Nz
- %s -> %sr>   closedr<   )r(   _RTCDataChannel__log_debugrF   remove_all_listeners)r.   rJ   r   r   r   _setReadyState   s   

zRTCDataChannel._setReadyStatemsgargsc                 G   s    t jd| | jg|R   d S )NzRTCDataChannel(%s) )loggerdebugr&   )r.   rO   rP   r   r   r   __log_debug   s    zRTCDataChannel.__log_debug)T)r    r   )r    N)!r   r   r   r   r   r   r#   propertyr   r3   r5   setterr   r   r   r   r
   r   r   r   r   r:   r   r<   r   r@   rC   rH   rI   rN   objectrL   __classcell__r   r   r/   r   r   /   sT    
	r   )r   )loggingdataclassesr   typingr   r   pyee.asyncior   
exceptionsr   	getLoggerr   rQ   r   r   rtcsctptransportr   r   r   r   r   <module>   s    
" /