mediasoup::data_consumer

Enum DataConsumer

Source
#[non_exhaustive]
pub enum DataConsumer { Regular(RegularDataConsumer), Direct(DirectDataConsumer), }
Expand description

A data consumer represents an endpoint capable of receiving data messages from a mediasoup Router.

A data consumer can use SCTP (AKA DataChannel) to receive those messages, or can directly receive them in the Rust application if the data consumer was created on top of a DirectTransport.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Regular(RegularDataConsumer)

Data consumer created on transport other than DirectTransport.

§

Direct(DirectDataConsumer)

Data consumer created on DirectTransport.

Implementations§

Source§

impl DataConsumer

Source

pub fn id(&self) -> DataConsumerId

Data consumer identifier.

Source

pub fn data_producer_id(&self) -> DataProducerId

The associated data producer identifier.

Source

pub fn transport(&self) -> &Arc<dyn Transport>

Transport to which data consumer belongs.

Source

pub fn type(&self) -> DataConsumerType

The type of the data consumer.

Source

pub fn paused(&self) -> bool

Whether the data consumer is paused. It does not take into account whether the associated data producer is paused.

Source

pub fn producer_paused(&self) -> bool

Whether the associate data producer is paused.

Source

pub fn sctp_stream_parameters(&self) -> Option<SctpStreamParameters>

The SCTP stream parameters (just if the data consumer type is Sctp).

Source

pub fn label(&self) -> &String

The data consumer label.

Source

pub fn protocol(&self) -> &String

The data consumer sub-protocol.

Source

pub fn subchannels(&self) -> Vec<u16>

The data consumer subchannels.

Source

pub fn app_data(&self) -> &AppData

Custom application data.

Source

pub fn closed(&self) -> bool

Whether the data consumer is closed.

Source

pub async fn get_stats(&self) -> Result<Vec<DataConsumerStat>, RequestError>

Returns current statistics of the data consumer.

Check the RTC Statistics section for more details (TypeScript-oriented, but concepts apply here as well).

Source

pub async fn pause(&self) -> Result<(), RequestError>

Pauses the data consumer (no mossage is sent to the consuming endpoint).

Source

pub async fn resume(&self) -> Result<(), RequestError>

Resumes the data consumer (messages are sent again to the consuming endpoint).

Source

pub async fn get_buffered_amount(&self) -> Result<u32, RequestError>

Returns the number of bytes of data currently buffered to be sent over the underlying SCTP association.

§Notes on usage

The underlying SCTP association uses a common send buffer for all data consumers, hence the value given by this method indicates the data buffered for all data consumers in the transport.

Source

pub async fn set_buffered_amount_low_threshold( &self, threshold: u32, ) -> Result<(), RequestError>

Whenever the underlying SCTP association buffered bytes drop to this value, on_buffered_amount_low callback is called.

Source

pub async fn set_subchannels( &self, subchannels: Vec<u16>, ) -> Result<(), RequestError>

Sets subchannels to the worker DataConsumer.

Source

pub async fn add_subchannel(&self, subchannel: u16) -> Result<(), RequestError>

Adds a subchannel to the worker DataConsumer.

Source

pub async fn remove_subchannel( &self, subchannel: u16, ) -> Result<(), RequestError>

Removes a subchannel to the worker DataConsumer.

Source

pub fn on_message<F: Fn(&WebRtcMessage<'_>) + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when a message has been received from the corresponding data producer.

§Notes on usage

Just available in direct transports, this is, those created via Router::create_direct_transport.

Source

pub fn on_sctp_send_buffer_full<F: Fn() + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when a message could not be sent because the SCTP send buffer was full.

Source

pub fn on_buffered_amount_low<F: Fn(u32) + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Emitted when the underlying SCTP association buffered bytes drop down to the value set with DataConsumer::set_buffered_amount_low_threshold.

§Notes on usage

Only applicable for consumers of type Sctp.

Source

pub fn on_data_producer_close<F: FnOnce() + Send + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when the associated data producer is closed for whatever reason. The data consumer itself is also closed.

Source

pub fn on_pause<F: Fn() + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when the data consumer or its associated data producer is paused and, as result, the data consumer becomes paused.

Source

pub fn on_resume<F: Fn() + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when the data consumer or its associated data producer is resumed and, as result, the data consumer is no longer paused.

Source

pub fn on_data_producer_pause<F: Fn() + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when the associated data producer is paused.

Source

pub fn on_data_producer_resume<F: Fn() + Send + Sync + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when the associated data producer is resumed.

Source

pub fn on_transport_close<F: FnOnce() + Send + 'static>( &self, callback: F, ) -> HandlerId

Callback is called when the transport this data consumer belongs to is closed for whatever reason. The data consumer itself is also closed.

Source

pub fn on_close<F: FnOnce() + Send + 'static>(&self, callback: F) -> HandlerId

Callback is called when the data consumer is closed for whatever reason.

NOTE: Callback will be called in place if data consumer is already closed.

Source

pub fn downgrade(&self) -> WeakDataConsumer

Downgrade DataConsumer to WeakDataConsumer instance.

Trait Implementations§

Source§

impl Clone for DataConsumer

Source§

fn clone(&self) -> DataConsumer

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataConsumer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<DirectDataConsumer> for DataConsumer

Source§

fn from(producer: DirectDataConsumer) -> Self

Converts to this type from the input type.
Source§

impl From<RegularDataConsumer> for DataConsumer

Source§

fn from(producer: RegularDataConsumer) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.