#[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
Regular(RegularDataConsumer)
Data consumer created on transport other than
DirectTransport
.
Direct(DirectDataConsumer)
Data consumer created on DirectTransport
.
Implementations§
Source§impl DataConsumer
impl DataConsumer
Sourcepub fn id(&self) -> DataConsumerId
pub fn id(&self) -> DataConsumerId
Data consumer identifier.
Sourcepub fn data_producer_id(&self) -> DataProducerId
pub fn data_producer_id(&self) -> DataProducerId
The associated data producer identifier.
Sourcepub fn type(&self) -> DataConsumerType
pub fn type(&self) -> DataConsumerType
The type of the data consumer.
Sourcepub fn paused(&self) -> bool
pub fn paused(&self) -> bool
Whether the data consumer is paused. It does not take into account whether the associated data producer is paused.
Sourcepub fn producer_paused(&self) -> bool
pub fn producer_paused(&self) -> bool
Whether the associate data producer is paused.
Sourcepub fn sctp_stream_parameters(&self) -> Option<SctpStreamParameters>
pub fn sctp_stream_parameters(&self) -> Option<SctpStreamParameters>
The SCTP stream parameters (just if the data consumer type is Sctp
).
Sourcepub fn subchannels(&self) -> Vec<u16>
pub fn subchannels(&self) -> Vec<u16>
The data consumer subchannels.
Sourcepub async fn get_stats(&self) -> Result<Vec<DataConsumerStat>, RequestError>
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).
Sourcepub async fn pause(&self) -> Result<(), RequestError>
pub async fn pause(&self) -> Result<(), RequestError>
Pauses the data consumer (no mossage is sent to the consuming endpoint).
Sourcepub async fn resume(&self) -> Result<(), RequestError>
pub async fn resume(&self) -> Result<(), RequestError>
Resumes the data consumer (messages are sent again to the consuming endpoint).
Sourcepub async fn get_buffered_amount(&self) -> Result<u32, RequestError>
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.
Sourcepub async fn set_buffered_amount_low_threshold(
&self,
threshold: u32,
) -> Result<(), RequestError>
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.
Sourcepub async fn set_subchannels(
&self,
subchannels: Vec<u16>,
) -> Result<(), RequestError>
pub async fn set_subchannels( &self, subchannels: Vec<u16>, ) -> Result<(), RequestError>
Sets subchannels to the worker DataConsumer.
Sourcepub async fn add_subchannel(&self, subchannel: u16) -> Result<(), RequestError>
pub async fn add_subchannel(&self, subchannel: u16) -> Result<(), RequestError>
Adds a subchannel to the worker DataConsumer.
Sourcepub async fn remove_subchannel(
&self,
subchannel: u16,
) -> Result<(), RequestError>
pub async fn remove_subchannel( &self, subchannel: u16, ) -> Result<(), RequestError>
Removes a subchannel to the worker DataConsumer.
Sourcepub fn on_message<F: Fn(&WebRtcMessage<'_>) + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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
.
Sourcepub fn on_sctp_send_buffer_full<F: Fn() + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_buffered_amount_low<F: Fn(u32) + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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
.
Sourcepub fn on_data_producer_close<F: FnOnce() + Send + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_pause<F: Fn() + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_resume<F: Fn() + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_data_producer_pause<F: Fn() + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_data_producer_resume<F: Fn() + Send + Sync + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_transport_close<F: FnOnce() + Send + 'static>(
&self,
callback: F,
) -> HandlerId
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.
Sourcepub fn on_close<F: FnOnce() + Send + 'static>(&self, callback: F) -> HandlerId
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.
Sourcepub fn downgrade(&self) -> WeakDataConsumer
pub fn downgrade(&self) -> WeakDataConsumer
Downgrade DataConsumer
to WeakDataConsumer
instance.
Trait Implementations§
Source§impl Clone for DataConsumer
impl Clone for DataConsumer
Source§fn clone(&self) -> DataConsumer
fn clone(&self) -> DataConsumer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more