pub async fn start(&self, params: &RTCIceParameters, role: Option<RTCIceRole>) -> Result<()> {
        if self.state() != RTCIceTransportState::New {
            return Err(Error::ErrICETransportNotInNew);
        }

        self.ensure_gatherer().await?;

        if let Some(agent) = self.gatherer.get_agent().await {
            let state = Arc::clone(&self.state);

            let on_connection_state_change_handler =
                Arc::clone(&self.on_connection_state_change_handler);
            agent
                .on_connection_state_change(Box::new(move |ice_state: ConnectionState| {
                    let s = RTCIceTransportState::from(ice_state);
                    let on_connection_state_change_handler_clone =
                        Arc::clone(&on_connection_state_change_handler);
                    state.store(s as u8, Ordering::SeqCst);
                    Box::pin(async move {
                        let mut handler = on_connection_state_change_handler_clone.lock().await;
                        if let Some(f) = &mut *handler {
                            f(s).await;
                        }
                    })
                }))
                .await;

            let on_selected_candidate_pair_change_handler =
                Arc::clone(&self.on_selected_candidate_pair_change_handler);
            agent
                .on_selected_candidate_pair_change(Box::new(
                    move |local: &Arc<dyn Candidate + Send + Sync>,
                          remote: &Arc<dyn Candidate + Send + Sync>| {
                        let on_selected_candidate_pair_change_handler_clone =
                            Arc::clone(&on_selected_candidate_pair_change_handler);
                        let local = RTCIceCandidate::from(local);
                        let remote = RTCIceCandidate::from(remote);
                        Box::pin(async move {
                            let mut handler =
                                on_selected_candidate_pair_change_handler_clone.lock().await;
                            if let Some(f) = &mut *handler {
                                f(RTCIceCandidatePair::new(local, remote)).await;
                            }
                        })
                    },
                ))
                .await;

            let role = if let Some(role) = role {
                role
            } else {
                RTCIceRole::Controlled
            };

            let (cancel_tx, cancel_rx) = mpsc::channel(1);
            {
                let mut internal = self.internal.lock().await;
                internal.role = role;
                internal.cancel_tx = Some(cancel_tx);
            }

            let conn: Arc<dyn Conn + Send + Sync> = match role {
                RTCIceRole::Controlling => {
                    agent
                        .dial(
                            cancel_rx,
                            params.username_fragment.clone(),
                            params.password.clone(),
                        )
                        .await?
                }

                RTCIceRole::Controlled => {
                    agent
                        .accept(
                            cancel_rx,
                            params.username_fragment.clone(),
                            params.password.clone(),
                        )
                        .await?
                }

                _ => return Err(Error::ErrICERoleUnknown),
            };

            let config = Config {
                conn: Arc::clone(&conn),
                buffer_size: self.gatherer.setting_engine.get_receive_mtu(),
            };

            {
                let mut internal = self.internal.lock().await;
                internal.conn = Some(conn);
                internal.mux = Some(Mux::new(config));
            }

            Ok(())
        } else {
            Err(Error::ErrICEAgentNotExist)
        }
    }
/// Start incoming connectivity checks based on its configured role.
Start incoming connectivity checks based on its configured role.
Start incoming connectivity checks based on its configured role .
pub async fn start(&self, params: &RTCIceParameters, role: Option<RTCIceRole>) -> Result<()> {
        if self.state() != RTCIceTransportState::New {
            return Err(Error::ErrICETransportNotInNew);
        }
        self.ensure_gatherer().await?;
        if let Some(agent) = self.gatherer.get_agent().await {
            let state = Arc::clone(&self.state);
            let on_connection_state_change_handler =
                Arc::clone(&self.on_connection_state_change_handler);
            agent
                .on_connection_state_change(Box::new(move |ice_state: ConnectionState| {
                    let s = RTCIceTransportState::from(ice_state);
                    let on_connection_state_change_handler_clone =
                        Arc::clone(&on_connection_state_change_handler);
                    state.store(s as u8, Ordering::SeqCst);
                    Box::pin(async move {
                        let mut handler = on_connection_state_change_handler_clone.lock().await;
                        if let Some(f) = &mut *handler {
                            f(s).await;
                        }
                    })
                }))
                .await;
            let on_selected_candidate_pair_change_handler =
                Arc::clone(&self.on_selected_candidate_pair_change_handler);
            agent
                .on_selected_candidate_pair_change(Box::new(
                    move |local: &Arc<dyn Candidate + Send + Sync>,
                          remote: &Arc<dyn Candidate + Send + Sync>| {
                        let on_selected_candidate_pair_change_handler_clone =
                            Arc::clone(&on_selected_candidate_pair_change_handler);
                        let local = RTCIceCandidate::from(local);
                        let remote = RTCIceCandidate::from(remote);
                        Box::pin(async move {
                            let mut handler =
                                on_selected_candidate_pair_change_handler_clone.lock().await;
                            if let Some(f) = &mut *handler {
                                f(RTCIceCandidatePair::new(local, remote)).await;
                            }
                        })
                    },
                ))
                .await;
            let role = if let Some(role) = role {
                role
            } else {
                RTCIceRole::Controlled
            };
            let (cancel_tx, cancel_rx) = mpsc::channel(1);
            {
                let mut internal = self.internal.lock().await;
                internal.role = role;
                internal.cancel_tx = Some(cancel_tx);
            }
            let conn: Arc<dyn Conn + Send + Sync> = match role {
                RTCIceRole::Controlling => {
                    agent
                        .dial(
                            cancel_rx,
                            params.username_fragment.clone(),
                            params.password.clone(),
                        )
                        .await?
                }
                RTCIceRole::Controlled => {
                    agent
                        .accept(
                            cancel_rx,
                            params.username_fragment.clone(),
                            params.password.clone(),
                        )
                        .await?
                }
                _ => return Err(Error::ErrICERoleUnknown),
            };
            let config = Config {
                conn: Arc::clone(&conn),
                buffer_size: self.gatherer.setting_engine.get_receive_mtu(),
            };
            {
                let mut internal = self.internal.lock().await;
                internal.conn = Some(conn);
                internal.mux = Some(Mux::new(config));
            }
            Ok(())
        } else {
            Err(Error::ErrICEAgentNotExist)
        }
    }
pub async fn start ( & self , params : & RTCIceParameters , role : Option < RTCIceRole > ) -> Result < ( ) > { if self . state ( ) != RTCIceTransportState :: New { return Err ( Error :: ErrICETransportNotInNew ) ; } self . ensure_gatherer ( ) . await ? ; if let Some ( agent ) = self . gatherer . get_agent ( ) . await { let state = Arc :: clone ( & self . state ) ; let on_connection_state_change_handler = Arc :: clone ( & self . on_connection_state_change_handler ) ; agent . on_connection_state_change ( Box :: new ( move | ice_state : ConnectionState | { let s = RTCIceTransportState :: from ( ice_state ) ; let on_connection_state_change_handler_clone = Arc :: clone ( & on_connection_state_change_handler ) ; state . store ( s as u8 , Ordering :: SeqCst ) ; Box :: pin ( async move { let mut handler = on_connection_state_change_handler_clone . lock ( ) . await ; if let Some ( f ) = & mut * handler { f ( s ) . await ; } } ) } ) ) . await ; let on_selected_candidate_pair_change_handler = Arc :: clone ( & self . on_selected_candidate_pair_change_handler ) ; agent . on_selected_candidate_pair_change ( Box :: new ( move | local : & Arc < dyn Candidate + Send + Sync > , remote : & Arc < dyn Candidate + Send + Sync > | { let on_selected_candidate_pair_change_handler_clone = Arc :: clone ( & on_selected_candidate_pair_change_handler ) ; let local = RTCIceCandidate :: from ( local ) ; let remote = RTCIceCandidate :: from ( remote ) ; Box :: pin ( async move { let mut handler = on_selected_candidate_pair_change_handler_clone . lock ( ) . await ; if let Some ( f ) = & mut * handler { f ( RTCIceCandidatePair :: new ( local , remote ) ) . await ; } } ) } , ) ) . await ; let role = if let Some ( role ) = role { role } else { RTCIceRole :: Controlled } ; let ( cancel_tx , cancel_rx ) = mpsc :: channel ( 1 ) ; { let mut internal = self . internal . lock ( ) . await ; internal . role = role ; internal . cancel_tx = Some ( cancel_tx ) ; } let conn : Arc < dyn Conn + Send + Sync > = match role { RTCIceRole :: Controlling => { agent . dial ( cancel_rx , params . username_fragment . clone ( ) , params . password . clone ( ) , ) . await ? } RTCIceRole :: Controlled => { agent . accept ( cancel_rx , params . username_fragment . clone ( ) , params . password . clone ( ) , ) . await ? } _ => return Err ( Error :: ErrICERoleUnknown ) , } ; let config = Config { conn : Arc :: clone ( & conn ) , buffer_size : self . gatherer . setting_engine . get_receive_mtu ( ) , } ; { let mut internal = self . internal . lock ( ) . await ; internal . conn = Some ( conn ) ; internal . mux = Some ( Mux :: new ( config ) ) ; } Ok ( ( ) ) } else { Err ( Error :: ErrICEAgentNotExist ) } }
Start incoming connectivity checks based on its configured role.
Start incoming connectivity checks based on its configured role .
&self
params
&RTCIceParameters
role
Option<RTCIceRole>