pub struct DataChannel { /* private fields */ }
Expand description

The RTCDataChannel interface represents a network channel which can be used for bidirectional peer-to-peer transfers of arbitrary data. Every data channel is associated with an RTCPeerConnection, and each peer connection can have up to a theoretical maximum of 65,534 data channels (the actual limit may vary from browser to browser).

To create a data channel and ask a remote peer to join you, call the RTCPeerConnection’s createDataChannel() method. The peer being invited to exchange data receives a datachannel event (which has type RTCDataChannelEvent) to let it know the data channel has been added to the connection.

Implementations§

source§

impl DataChannel

source

pub fn set_on_open(&mut self, cb: Option<impl Fn() + Send + Sync + 'static>)

The WebRTC open event is sent to an RTCDataChannel object’s onopen event handler when the underlying transport used to send and receive the data channel’s messages is opened or reopened.

source

pub fn set_on_close(&mut self, cb: Option<impl Fn() + Send + Sync + 'static>)

The close event is sent to the onclose event handler on an RTCDataChannel instance when the data transport for the data channel has closed. Before any further data can be transferred using RTCDataChannel, a new ‘RTCDataChannel’ instance must be created.

source

pub fn set_on_buffered_amount_low( &mut self, cb: Option<impl Fn() + Send + Sync + 'static> )

A bufferedamountlow event is sent to an RTCDataChannel when the number of bytes currently in the outbound data transfer buffer falls below the threshold specified in bufferedAmountLowThreshold. bufferedamountlow events aren’t sent if bufferedAmountLowThreshold is 0.

source

pub fn set_on_error( &mut self, cb: Option<impl Fn(Error) + Send + Sync + 'static> )

A WebRTC error event is sent to an RTCDataChannel object’s onerror event handler when an error occurs on the data channel.

source

pub fn set_on_message( &mut self, cb: Option<impl Fn(&[u8]) + Send + Sync + 'static> )

The WebRTC message event is sent to the onmessage event handler on an RTCDataChannel object when a message has been received from the remote peer.

source

pub fn set_buffered_amount_low_threshold(&self, value: u32) -> Result<(), Error>

The RTCDataChannel property bufferedAmountLowThreshold is used to specify the number of bytes of buffered outgoing data that is considered “low.” The default value is 0. When the number of buffered outgoing bytes, as indicated by the bufferedAmount property, falls to or below this value, a bufferedamountlow event is fired. This event may be used, for example, to implement code which queues more messages to be sent whenever there’s room to buffer them. Listeners may be added with onbufferedamountlow or addEventListener().

The user agent may implement the process of actually sending data in any way it chooses; this may be done periodically during the event loop or truly asynchronously. As messages are actually sent, this value is reduced accordingly.

source

pub fn buffered_amount(&self) -> Result<u32, Error>

The read-only RTCDataChannel property bufferedAmount returns the number of bytes of data currently queued to be sent over the data channel. The queue may build up as a result of calls to the send() method. This only includes data buffered by the user agent itself; it doesn’t include any framing overhead or buffering done by the operating system or network hardware.

The user agent may implement the process of actually sending data in any way it chooses; this may be done periodically during the event loop or truly asynchronously. As messages are actually sent, this value is reduced accordingly.

source

pub fn close(&self) -> Result<(), Error>

The RTCDataChannel.close() method closes the RTCDataChannel. Either peer is permitted to call this method to initiate closure of the channel.

Closure of the data channel is not instantaneous. Most of the process of closing the connection is handled asynchronously; you can detect when the channel has finished closing by watching for a close event on the data channel.

source

pub fn send(&self, buf: &[u8]) -> Result<(), Error>

The send() method of the RTCDataChannel interface sends data across the data channel to the remote peer. This can be done any time except during the initial process of creating the underlying transport channel. Data sent before connecting is buffered if possible (or an error occurs if it’s not possible), and is also buffered if sent while the connection is closing or closed.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.