pub async fn add_track(
        &self,
        track: Arc<dyn TrackLocal + Send + Sync>,
    ) -> Result<Arc<RTCRtpSender>> {
        if self.internal.is_closed.load(Ordering::SeqCst) {
            return Err(Error::ErrConnectionClosed);
        }

        {
            let rtp_transceivers = self.internal.rtp_transceivers.lock().await;
            for t in &*rtp_transceivers {
                if !t.stopped.load(Ordering::SeqCst)
                    && t.kind == track.kind()
                    && t.sender().await.is_none()
                {
                    let sender = Arc::new(
                        RTCRtpSender::new(
                            self.internal.setting_engine.get_receive_mtu(),
                            Arc::clone(&track),
                            Arc::clone(&self.internal.dtls_transport),
                            Arc::clone(&self.internal.media_engine),
                            Arc::clone(&self.interceptor),
                        )
                        .await,
                    );

                    if let Err(err) = t
                        .set_sender_track(Some(Arc::clone(&sender)), Some(Arc::clone(&track)))
                        .await
                    {
                        let _ = sender.stop().await;
                        let _ = t.set_sender(None).await;
                        return Err(err);
                    }

                    RTCPeerConnection::do_negotiation_needed(NegotiationNeededParams {
                        on_negotiation_needed_handler: Arc::clone(
                            &self.internal.on_negotiation_needed_handler,
                        ),
                        is_closed: Arc::clone(&self.internal.is_closed),
                        ops: Arc::clone(&self.internal.ops),
                        negotiation_needed_state: Arc::clone(
                            &self.internal.negotiation_needed_state,
                        ),
                        is_negotiation_needed: Arc::clone(&self.internal.is_negotiation_needed),
                        signaling_state: Arc::clone(&self.internal.signaling_state),
                        check_negotiation_needed_params: CheckNegotiationNeededParams {
                            sctp_transport: Arc::clone(&self.internal.sctp_transport),
                            rtp_transceivers: Arc::clone(&self.internal.rtp_transceivers),
                            current_local_description: self
                                .internal
                                .current_local_description
                                .clone(),
                            current_remote_description: self
                                .internal
                                .current_remote_description
                                .clone(),
                        },
                    })
                    .await;

                    return Ok(sender);
                }
            }
        }

        let transceiver = self
            .internal
            .new_transceiver_from_track(RTCRtpTransceiverDirection::Sendrecv, track)
            .await?;
        self.internal
            .add_rtp_transceiver(Arc::clone(&transceiver))
            .await;

        match transceiver.sender().await {
            Some(sender) => Ok(sender),
            None => Err(Error::ErrRTPSenderNil),
        }
    }
/// add_track adds a Track to the PeerConnection
add_track adds a Track to the PeerConnection
add_track adds a Track to the PeerConnection
pub async fn add_track(
        &self,
        track: Arc<dyn TrackLocal + Send + Sync>,
    ) -> Result<Arc<RTCRtpSender>> {
        if self.internal.is_closed.load(Ordering::SeqCst) {
            return Err(Error::ErrConnectionClosed);
        }
        {
            let rtp_transceivers = self.internal.rtp_transceivers.lock().await;
            for t in &*rtp_transceivers {
                if !t.stopped.load(Ordering::SeqCst)
                    && t.kind == track.kind()
                    && t.sender().await.is_none()
                {
                    let sender = Arc::new(
                        RTCRtpSender::new(
                            self.internal.setting_engine.get_receive_mtu(),
                            Arc::clone(&track),
                            Arc::clone(&self.internal.dtls_transport),
                            Arc::clone(&self.internal.media_engine),
                            Arc::clone(&self.interceptor),
                        )
                        .await,
                    );
                    if let Err(err) = t
                        .set_sender_track(Some(Arc::clone(&sender)), Some(Arc::clone(&track)))
                        .await
                    {
                        let _ = sender.stop().await;
                        let _ = t.set_sender(None).await;
                        return Err(err);
                    }
                    RTCPeerConnection::do_negotiation_needed(NegotiationNeededParams {
                        on_negotiation_needed_handler: Arc::clone(
                            &self.internal.on_negotiation_needed_handler,
                        ),
                        is_closed: Arc::clone(&self.internal.is_closed),
                        ops: Arc::clone(&self.internal.ops),
                        negotiation_needed_state: Arc::clone(
                            &self.internal.negotiation_needed_state,
                        ),
                        is_negotiation_needed: Arc::clone(&self.internal.is_negotiation_needed),
                        signaling_state: Arc::clone(&self.internal.signaling_state),
                        check_negotiation_needed_params: CheckNegotiationNeededParams {
                            sctp_transport: Arc::clone(&self.internal.sctp_transport),
                            rtp_transceivers: Arc::clone(&self.internal.rtp_transceivers),
                            current_local_description: self
                                .internal
                                .current_local_description
                                .clone(),
                            current_remote_description: self
                                .internal
                                .current_remote_description
                                .clone(),
                        },
                    })
                    .await;
                    return Ok(sender);
                }
            }
        }
        let transceiver = self
            .internal
            .new_transceiver_from_track(RTCRtpTransceiverDirection::Sendrecv, track)
            .await?;
        self.internal
            .add_rtp_transceiver(Arc::clone(&transceiver))
            .await;
        match transceiver.sender().await {
            Some(sender) => Ok(sender),
            None => Err(Error::ErrRTPSenderNil),
        }
    }
pub async fn add_track ( & self , track : Arc < dyn TrackLocal + Send + Sync > , ) -> Result < Arc < RTCRtpSender > > { if self . internal . is_closed . load ( Ordering :: SeqCst ) { return Err ( Error :: ErrConnectionClosed ) ; } { let rtp_transceivers = self . internal . rtp_transceivers . lock ( ) . await ; for t in & * rtp_transceivers { if ! t . stopped . load ( Ordering :: SeqCst ) && t . kind == track . kind ( ) && t . sender ( ) . await . is_none ( ) { let sender = Arc :: new ( RTCRtpSender :: new ( self . internal . setting_engine . get_receive_mtu ( ) , Arc :: clone ( & track ) , Arc :: clone ( & self . internal . dtls_transport ) , Arc :: clone ( & self . internal . media_engine ) , Arc :: clone ( & self . interceptor ) , ) . await , ) ; if let Err ( err ) = t . set_sender_track ( Some ( Arc :: clone ( & sender ) ) , Some ( Arc :: clone ( & track ) ) ) . await { let _ = sender . stop ( ) . await ; let _ = t . set_sender ( None ) . await ; return Err ( err ) ; } RTCPeerConnection :: do_negotiation_needed ( NegotiationNeededParams { on_negotiation_needed_handler : Arc :: clone ( & self . internal . on_negotiation_needed_handler , ) , is_closed : Arc :: clone ( & self . internal . is_closed ) , ops : Arc :: clone ( & self . internal . ops ) , negotiation_needed_state : Arc :: clone ( & self . internal . negotiation_needed_state , ) , is_negotiation_needed : Arc :: clone ( & self . internal . is_negotiation_needed ) , signaling_state : Arc :: clone ( & self . internal . signaling_state ) , check_negotiation_needed_params : CheckNegotiationNeededParams { sctp_transport : Arc :: clone ( & self . internal . sctp_transport ) , rtp_transceivers : Arc :: clone ( & self . internal . rtp_transceivers ) , current_local_description : self . internal . current_local_description . clone ( ) , current_remote_description : self . internal . current_remote_description . clone ( ) , } , } ) . await ; return Ok ( sender ) ; } } } let transceiver = self . internal . new_transceiver_from_track ( RTCRtpTransceiverDirection :: Sendrecv , track ) . await ? ; self . internal . add_rtp_transceiver ( Arc :: clone ( & transceiver ) ) . await ; match transceiver . sender ( ) . await { Some ( sender ) => Ok ( sender ) , None => Err ( Error :: ErrRTPSenderNil ) , } }
add_track adds a Track to the PeerConnection
add_track adds a Track to the PeerConnection
&self
track
Arc<dyn TrackLocal + Send + Sync>