pub trait Transport: Debug + Send + Sync {
Show 16 methods // Required methods fn id(&self) -> TransportId; fn router(&self) -> &Router; fn app_data(&self) -> &AppData; fn closed(&self) -> bool; fn produce<'life0, 'async_trait>( &'life0 self, producer_options: ProducerOptions ) -> Pin<Box<dyn Future<Output = Result<Producer, ProduceError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn consume<'life0, 'async_trait>( &'life0 self, consumer_options: ConsumerOptions ) -> Pin<Box<dyn Future<Output = Result<Consumer, ConsumeError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn produce_data<'life0, 'async_trait>( &'life0 self, data_producer_options: DataProducerOptions ) -> Pin<Box<dyn Future<Output = Result<DataProducer, ProduceDataError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn consume_data<'life0, 'async_trait>( &'life0 self, data_consumer_options: DataConsumerOptions ) -> Pin<Box<dyn Future<Output = Result<DataConsumer, ConsumeDataError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn enable_trace_event<'life0, 'async_trait>( &'life0 self, types: Vec<TransportTraceEventType> ) -> Pin<Box<dyn Future<Output = Result<(), RequestError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn on_new_producer( &self, callback: Arc<dyn Fn(&Producer) + Send + Sync + 'static> ) -> HandlerId; fn on_new_consumer( &self, callback: Arc<dyn Fn(&Consumer) + Send + Sync + 'static> ) -> HandlerId; fn on_new_data_producer( &self, callback: Arc<dyn Fn(&DataProducer) + Send + Sync + 'static> ) -> HandlerId; fn on_new_data_consumer( &self, callback: Arc<dyn Fn(&DataConsumer) + Send + Sync + 'static> ) -> HandlerId; fn on_trace( &self, callback: Arc<dyn Fn(&TransportTraceEventData) + Send + Sync + 'static> ) -> HandlerId; fn on_router_close( &self, callback: Box<dyn FnOnce() + Send + 'static> ) -> HandlerId; fn on_close( &self, callback: Box<dyn FnOnce() + Send + 'static> ) -> HandlerId;
}
Expand description

A transport connects an endpoint with a mediasoup router and enables transmission of media in both directions by means of Producer, Consumer, DataProducer and DataConsumer instances created on it.

mediasoup implements the following transports:

For additional methods see TransportGeneric.

Required Methods§

source

fn id(&self) -> TransportId

Transport id.

source

fn router(&self) -> &Router

Router to which transport belongs.

source

fn app_data(&self) -> &AppData

Custom application data.

source

fn closed(&self) -> bool

Whether the transport is closed.

source

fn produce<'life0, 'async_trait>( &'life0 self, producer_options: ProducerOptions ) -> Pin<Box<dyn Future<Output = Result<Producer, ProduceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Instructs the router to receive audio or video RTP (or SRTP depending on the transport). This is the way to inject media into mediasoup.

Transport will be kept alive as long as at least one producer instance is alive.

§Notes on usage

Check the RTP Parameters and Capabilities section for more details (TypeScript-oriented, but concepts apply here as well).

source

fn consume<'life0, 'async_trait>( &'life0 self, consumer_options: ConsumerOptions ) -> Pin<Box<dyn Future<Output = Result<Consumer, ConsumeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Instructs the router to send audio or video RTP (or SRTP depending on the transport). This is the way to extract media from mediasoup.

Transport will be kept alive as long as at least one consumer instance is alive.

§Notes on usage

Check the RTP Parameters and Capabilities section for more details (TypeScript-oriented, but concepts apply here as well).

When creating a consumer it’s recommended to set ConsumerOptions::paused to true, then transmit the consumer parameters to the consuming endpoint and, once the consuming endpoint has created its local side consumer, unpause the server side consumer using the Consumer::resume() method.

Reasons for create the server side consumer in paused mode:

  • If the remote endpoint is a WebRTC browser or application and it receives a RTP packet of the new consumer before the remote RTCPeerConnection is ready to process it (this is, before the remote consumer is created in the remote endpoint) it may happen that the RTCPeerConnection will wrongly associate the SSRC of the received packet to an already existing SDP m= section, so the imminent creation of the new consumer and its associated m= section will fail.
  • Also, when creating a video consumer, this is an optimization to make it possible for the consuming endpoint to render the video as far as possible. If the server side consumer was created with paused: false, mediasoup will immediately request a key frame to the producer and that key frame may reach the consuming endpoint even before it’s ready to consume it, generating “black” video until the device requests a keyframe by itself.
source

fn produce_data<'life0, 'async_trait>( &'life0 self, data_producer_options: DataProducerOptions ) -> Pin<Box<dyn Future<Output = Result<DataProducer, ProduceDataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Instructs the router to receive data messages. Those messages can be delivered by an endpoint via SCTP protocol (AKA DataChannel in WebRTC) or can be directly sent from the Rust application if the transport is a DirectTransport.

Transport will be kept alive as long as at least one data producer instance is alive.

source

fn consume_data<'life0, 'async_trait>( &'life0 self, data_consumer_options: DataConsumerOptions ) -> Pin<Box<dyn Future<Output = Result<DataConsumer, ConsumeDataError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Instructs the router to send data messages to the endpoint via SCTP protocol (AKA DataChannel in WebRTC) or directly to the Rust process if the transport is a DirectTransport.

Transport will be kept alive as long as at least one data consumer instance is alive.

source

fn enable_trace_event<'life0, 'async_trait>( &'life0 self, types: Vec<TransportTraceEventType> ) -> Pin<Box<dyn Future<Output = Result<(), RequestError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Instructs the transport to emit “trace” events. For monitoring purposes. Use with caution.

source

fn on_new_producer( &self, callback: Arc<dyn Fn(&Producer) + Send + Sync + 'static> ) -> HandlerId

Callback is called when a new producer is created.

source

fn on_new_consumer( &self, callback: Arc<dyn Fn(&Consumer) + Send + Sync + 'static> ) -> HandlerId

Callback is called when a new consumer is created.

source

fn on_new_data_producer( &self, callback: Arc<dyn Fn(&DataProducer) + Send + Sync + 'static> ) -> HandlerId

Callback is called when a new data producer is created.

source

fn on_new_data_consumer( &self, callback: Arc<dyn Fn(&DataConsumer) + Send + Sync + 'static> ) -> HandlerId

Callback is called when a new data consumer is created.

source

fn on_trace( &self, callback: Arc<dyn Fn(&TransportTraceEventData) + Send + Sync + 'static> ) -> HandlerId

source

fn on_router_close( &self, callback: Box<dyn FnOnce() + Send + 'static> ) -> HandlerId

Callback is called when the router this transport belongs to is closed for whatever reason. The transport itself is also closed. on_transport_close callbacks are also called on all its producers and consumers.

source

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

Callback is called when the router is closed for whatever reason.

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

Implementors§