RTCDataChannel
The data channel, which carries text and binary messages between the peers over SCTP.
- webrtc.interfaces.rtc_data_channel.MAX_UNSIGNED_SHORT = 65535
The largest unsigned short, which bounds the label, the protocol and the retransmission limits of a channel
- webrtc.interfaces.rtc_data_channel.check_utf8_length(name, value)
Checks that a string, like the label of a channel, is at most 65535 bytes in UTF-8.
- class webrtc.interfaces.rtc_data_channel.RTCDataChannelInit(ordered=True, max_packet_life_time=None, max_retransmits=None, protocol='', negotiated=False, id=None, priority=RTCPriorityType.low)
The options of
webrtc.RTCPeerConnection.create_data_channel().webrtc.RTCPeerConnection.create_data_channel()checks them and raisesTypeErrorfor invalid ones.See MDN: RTCPeerConnection/createDataChannel.
- Parameters:
ordered (
bool, optional) β Whether messages arrive in the order they were sent,Trueby default.max_packet_life_time (
int, optional) β For how many milliseconds (0 to 65535) a message may be retransmitted. Setting it makes the channel unreliable.max_retransmits (
int, optional) β How many times (0 to 65535) a message may be retransmitted. Setting it makes the channel unreliable. It canβt be set together withmax_packet_life_time.protocol (
str, optional) β The subprotocol name, up to 65535 bytes in UTF-8, empty by default.negotiated (
bool, optional) β Whether the application creates the channel on both peers with the sameid. Otherwise the connection announces it to the remote peer.Falseby default.id (
int, optional) β The SCTP stream id (0 to 65534) of anegotiatedchannel. Itβs required for such a channel and ignored otherwise, because the connection picks the id.priority (
webrtc.RTCPriorityType, optional) β The priority of the channel,'low'by default.
- class webrtc.interfaces.rtc_data_channel.RTCDataChannel(native_obj=None)
A bidirectional channel of text and binary messages between the peers.
Created with
webrtc.RTCPeerConnection.create_data_channel(), or delivered by thedatachannelevent of the connection when the remote peer creates one.See MDN: RTCDataChannel.
- Events:
open (
webrtc.Event) β The channel is open and messages can be sent. It isnβt emitted if the channel closes before it opens.message (
webrtc.MessageEvent) β A message arrived. Itsdatais astrfor text, andbytesor awebrtc.Blobfor binary, depending onbinary_typeat delivery.bufferedamountlow (
webrtc.Event) βbuffered_amountdropped tobuffered_amount_low_thresholdor below.error (
webrtc.RTCErrorEvent) β The channel failed, and closes right after.closing (
webrtc.Event) β The channel started closing.close (
webrtc.Event) β The channel is closed.
Events
open:Eventbufferedamountlow:Eventclosing:Eventclose:Eventmessage:MessageEventerror:RTCErrorEvent
Handlers are registered with
on().- property label: str
The label the channel was created with. Several channels can share one.
See MDN: RTCDataChannel/label.
- Type:
- property ordered: bool
Whether messages arrive in the order they were sent.
See MDN: RTCDataChannel/ordered.
- Type:
- property max_packet_life_time: int | None
For how many milliseconds a message may be retransmitted, or
Noneif unlimited.See MDN: RTCDataChannel/maxPacketLifeTime.
- Type:
int, optional
- property max_retransmits: int | None
How many times a message may be retransmitted, or
Noneif unlimited.See MDN: RTCDataChannel/maxRetransmits.
- Type:
int, optional
- property protocol: str
The subprotocol name of the channel, or an empty string if thereβs none.
See MDN: RTCDataChannel/protocol.
- Type:
- property negotiated: bool
Whether the application negotiated the channel.
Otherwise the connection announced it to the remote peer. See MDN: RTCDataChannel/negotiated.
- Type:
- property id: int | None
The SCTP stream id of the channel.
Itβs
Noneuntil the connection assigns it. See MDN: RTCDataChannel/id.- Type:
int, optional
- property priority: webrtc.RTCPriorityType
The priority of the channel.
See MDN: RTCDataChannel/priority.
- Type:
- property ready_state: webrtc.RTCDataChannelState
The state of the channel. It changes along with its events.
- property buffered_amount: int
The bytes passed to
send()that arenβt sent yet.See MDN: RTCDataChannel/bufferedAmount.
- Type:
- property buffered_amount_low_threshold: int
The
buffered_amountat or below whichbufferedamountlowis emitted, 0 by default.Setting a value outside of 0 to 2**64-1 raises
ValueError.See MDN: RTCDataChannel/bufferedAmountLowThreshold.
- Type:
- property binary_type: BinaryType
What binary messages are delivered as,
'arraybuffer'by default.'arraybuffer'deliversbytesand'blob'awebrtc.Blob. Setting a value that isnβt a member raisesValueError.See MDN: RTCDataChannel/binaryType.
- Type:
- send(data)
Queues a message to the remote peer, adding its size to
buffered_amount.A
stris sent as a text message in UTF-8, anything else as a binary one.- Parameters:
data (
str, bytes-like orwebrtc.Blob) β The message.- Raises:
TypeError β If the data is neither a
str, bytes-like nor awebrtc.Blob, or the message is larger than the maximum message size of the SCTP transport.webrtc.InvalidStateError β If the channel isnβt open.
webrtc.OperationError β If the send queue is full.
- close()
Starts closing the channel, but messages queued before are still sent.
It does nothing if the channel is already closing. See MDN: RTCDataChannel/close.