pub async fn create_data_channel(
        &self,
        label: &str,
        options: Option<RTCDataChannelInit>,
    ) -> Result<Arc<RTCDataChannel>> {
        // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #2)
        if self.internal.is_closed.load(Ordering::SeqCst) {
            return Err(Error::ErrConnectionClosed);
        }

        let mut params = DataChannelParameters {
            label: label.to_owned(),
            ordered: true,
            ..Default::default()
        };

        // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #19)
        if let Some(options) = options {
            if let Some(id) = options.id {
                params.id = id;
            }

            // Ordered indicates if data is allowed to be delivered out of order. The
            // default value of true, guarantees that data will be delivered in order.
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #9)
            if let Some(ordered) = options.ordered {
                params.ordered = ordered;
            }

            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #7)
            if let Some(max_packet_life_time) = options.max_packet_life_time {
                params.max_packet_life_time = max_packet_life_time;
            }

            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #8)
            if let Some(max_retransmits) = options.max_retransmits {
                params.max_retransmits = max_retransmits;
            }

            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #10)
            if let Some(protocol) = options.protocol {
                params.protocol = protocol;
            }

            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #11)
            if params.protocol.len() > 65535 {
                return Err(Error::ErrProtocolTooLarge);
            }

            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #12)
            if let Some(negotiated) = options.negotiated {
                params.negotiated = negotiated;
            }
        }

        let d = Arc::new(RTCDataChannel::new(
            params,
            Arc::clone(&self.internal.setting_engine),
        ));

        // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #16)
        if d.max_packet_lifetime != 0 && d.max_retransmits != 0 {
            return Err(Error::ErrRetransmitsOrPacketLifeTime);
        }

        {
            let mut data_channels = self.internal.sctp_transport.data_channels.lock().await;
            data_channels.push(Arc::clone(&d));
        }
        self.internal
            .sctp_transport
            .data_channels_requested
            .fetch_add(1, Ordering::SeqCst);

        // If SCTP already connected open all the channels
        if self.internal.sctp_transport.state() == RTCSctpTransportState::Connected {
            d.open(Arc::clone(&self.internal.sctp_transport)).await?;
        }

        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;

        Ok(d)
    }
/// create_data_channel creates a new DataChannel object with the given label
/// and optional DataChannelInit used to configure properties of the
/// underlying channel such as data reliability.
create_data_channel creates a new DataChannel object with the given label
and optional DataChannelInit used to configure properties of the
underlying channel such as data reliability.
create_data_channel creates a new DataChannel object with the given label and optional DataChannelInit used to configure properties of the underlying channel such as data reliability .
pub async fn create_data_channel(
        &self,
        label: &str,
        options: Option<RTCDataChannelInit>,
    ) -> Result<Arc<RTCDataChannel>> {
        // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #2)
        if self.internal.is_closed.load(Ordering::SeqCst) {
            return Err(Error::ErrConnectionClosed);
        }
        let mut params = DataChannelParameters {
            label: label.to_owned(),
            ordered: true,
            ..Default::default()
        };
        // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #19)
        if let Some(options) = options {
            if let Some(id) = options.id {
                params.id = id;
            }
            // Ordered indicates if data is allowed to be delivered out of order. The
            // default value of true, guarantees that data will be delivered in order.
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #9)
            if let Some(ordered) = options.ordered {
                params.ordered = ordered;
            }
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #7)
            if let Some(max_packet_life_time) = options.max_packet_life_time {
                params.max_packet_life_time = max_packet_life_time;
            }
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #8)
            if let Some(max_retransmits) = options.max_retransmits {
                params.max_retransmits = max_retransmits;
            }
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #10)
            if let Some(protocol) = options.protocol {
                params.protocol = protocol;
            }
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #11)
            if params.protocol.len() > 65535 {
                return Err(Error::ErrProtocolTooLarge);
            }
            // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #12)
            if let Some(negotiated) = options.negotiated {
                params.negotiated = negotiated;
            }
        }
        let d = Arc::new(RTCDataChannel::new(
            params,
            Arc::clone(&self.internal.setting_engine),
        ));
        // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #16)
        if d.max_packet_lifetime != 0 && d.max_retransmits != 0 {
            return Err(Error::ErrRetransmitsOrPacketLifeTime);
        }
        {
            let mut data_channels = self.internal.sctp_transport.data_channels.lock().await;
            data_channels.push(Arc::clone(&d));
        }
        self.internal
            .sctp_transport
            .data_channels_requested
            .fetch_add(1, Ordering::SeqCst);
        // If SCTP already connected open all the channels
        if self.internal.sctp_transport.state() == RTCSctpTransportState::Connected {
            d.open(Arc::clone(&self.internal.sctp_transport)).await?;
        }
        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;
        Ok(d)
    }
pub async fn create_data_channel ( & self , label : & str , options : Option < RTCDataChannelInit > , ) -> Result < Arc < RTCDataChannel > > { // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #2) if self . internal . is_closed . load ( Ordering :: SeqCst ) { return Err ( Error :: ErrConnectionClosed ) ; } let mut params = DataChannelParameters { label : label . to_owned ( ) , ordered : true , .. Default :: default ( ) } ; // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #19) if let Some ( options ) = options { if let Some ( id ) = options . id { params . id = id ; } // Ordered indicates if data is allowed to be delivered out of order. The // default value of true, guarantees that data will be delivered in order. // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #9) if let Some ( ordered ) = options . ordered { params . ordered = ordered ; } // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #7) if let Some ( max_packet_life_time ) = options . max_packet_life_time { params . max_packet_life_time = max_packet_life_time ; } // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #8) if let Some ( max_retransmits ) = options . max_retransmits { params . max_retransmits = max_retransmits ; } // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #10) if let Some ( protocol ) = options . protocol { params . protocol = protocol ; } // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #11) if params . protocol . len ( ) > 65535 { return Err ( Error :: ErrProtocolTooLarge ) ; } // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #12) if let Some ( negotiated ) = options . negotiated { params . negotiated = negotiated ; } } let d = Arc :: new ( RTCDataChannel :: new ( params , Arc :: clone ( & self . internal . setting_engine ) , ) ) ; // https://w3c.github.io/webrtc-pc/#peer-to-peer-data-api (Step #16) if d . max_packet_lifetime != 0 && d . max_retransmits != 0 { return Err ( Error :: ErrRetransmitsOrPacketLifeTime ) ; } { let mut data_channels = self . internal . sctp_transport . data_channels . lock ( ) . await ; data_channels . push ( Arc :: clone ( & d ) ) ; } self . internal . sctp_transport . data_channels_requested . fetch_add ( 1 , Ordering :: SeqCst ) ; // If SCTP already connected open all the channels if self . internal . sctp_transport . state ( ) == RTCSctpTransportState :: Connected { d . open ( Arc :: clone ( & self . internal . sctp_transport ) ) . await ? ; } 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 ; Ok ( d ) }
create_data_channel creates a new DataChannel object with the given label
and optional DataChannelInit used to configure properties of the
underlying channel such as data reliability.
create_data_channel creates a new DataChannel object with the given label and optional DataChannelInit used to configure properties of the underlying channel such as data reliability .
&self
label
&str
options
Option<RTCDataChannelInit>