pub async fn create_webrtc_transport(
        user: Rc<RwLock<User>>,
        router: Router,
        is_consumer: bool,
    ) {
        let listen_ip = env::var("LISTEN_IP").unwrap();
        let announced_ip: String = env::var("ANNOUNCED_IP").unwrap();
        let arr: Vec<&str> = announced_ip.split(".").collect();
        let mut transport_options =
            WebRtcTransportOptions::new(TransportListenIps::new(TransportListenIp {
                ip: listen_ip.parse().unwrap(),
                announced_ip: Some(IpAddr::V4(Ipv4Addr::new(
                    arr[0].parse().unwrap(),
                    arr[1].parse().unwrap(),
                    arr[2].parse().unwrap(),
                    arr[3].parse().unwrap(),
                ))),
            }));
        transport_options.enable_tcp = true;
        transport_options.enable_udp = true;
        transport_options.prefer_tcp = true;
        if is_consumer {
            transport_options.app_data = AppData::new(TransportAppData {
                router_id: router.id(),
                is_consumer: true,
            });
            let user_addr = { user.as_ref().read().await.ws_actor_addr.clone() };
            let id = { user.as_ref().read().await.id };
            let consumer_transport = match router.create_webrtc_transport(transport_options).await {
                Ok(transport) => transport,
                Err(error) => {
                    user_addr.do_send(DisconnectMessage {
                        id,
                        send_to_client: true,
                        send_to_room: true,
                        message: error.to_string(),
                    });
                    return;
                }
            };
            user_addr.do_send(NewWebrtcTransportResponse {
                transport_type: String::from("consumer"),
                webrtc_transport: TransportOptions {
                    id: consumer_transport.id(),
                    dtls_parameters: consumer_transport.dtls_parameters(),
                    ice_candidates: consumer_transport.ice_candidates().clone(),
                    ice_parameters: consumer_transport.ice_parameters().clone(),
                },
            });
            {
                user.as_ref()
                    .write()
                    .await
                    .insert_transport(consumer_transport, true);
            }
        } else {
            transport_options.app_data = AppData::new(TransportAppData {
                router_id: router.id(),
                is_consumer: false,
            });
            let user_addr = { user.as_ref().read().await.ws_actor_addr.clone() };
            let id = { user.as_ref().read().await.id };
            let producer_transport = match router
                .create_webrtc_transport(transport_options.clone())
                .await
            {
                Ok(transport) => transport,
                Err(error) => {
                    user_addr.do_send(DisconnectMessage {
                        id,
                        send_to_client: true,
                        send_to_room: true,
                        message: error.to_string(),
                    });
                    return;
                }
            };
            user_addr.do_send(NewWebrtcTransportResponse {
                transport_type: String::from("producer"),
                webrtc_transport: TransportOptions {
                    id: producer_transport.id(),
                    dtls_parameters: producer_transport.dtls_parameters(),
                    ice_candidates: producer_transport.ice_candidates().clone(),
                    ice_parameters: producer_transport.ice_parameters().clone(),
                },
            });
            {
                user.as_ref()
                    .write()
                    .await
                    .insert_transport(producer_transport, false);
            }
        }
    }
///
/// create webrtc transport using listen ip and announced ip specified in environment variable.
///
create webrtc transport using listen ip and announced ip specified in environment variable.
create webrtc transport using listen ip and announced ip specified in environment variable .
pub async fn create_webrtc_transport(
        user: Rc<RwLock<User>>,
        router: Router,
        is_consumer: bool,
    ) {
        let listen_ip = env::var("LISTEN_IP").unwrap();
        let announced_ip: String = env::var("ANNOUNCED_IP").unwrap();
        let arr: Vec<&str> = announced_ip.split(".").collect();
        let mut transport_options =
            WebRtcTransportOptions::new(TransportListenIps::new(TransportListenIp {
                ip: listen_ip.parse().unwrap(),
                announced_ip: Some(IpAddr::V4(Ipv4Addr::new(
                    arr[0].parse().unwrap(),
                    arr[1].parse().unwrap(),
                    arr[2].parse().unwrap(),
                    arr[3].parse().unwrap(),
                ))),
            }));
        transport_options.enable_tcp = true;
        transport_options.enable_udp = true;
        transport_options.prefer_tcp = true;
        if is_consumer {
            transport_options.app_data = AppData::new(TransportAppData {
                router_id: router.id(),
                is_consumer: true,
            });
            let user_addr = { user.as_ref().read().await.ws_actor_addr.clone() };
            let id = { user.as_ref().read().await.id };
            let consumer_transport = match router.create_webrtc_transport(transport_options).await {
                Ok(transport) => transport,
                Err(error) => {
                    user_addr.do_send(DisconnectMessage {
                        id,
                        send_to_client: true,
                        send_to_room: true,
                        message: error.to_string(),
                    });
                    return;
                }
            };
            user_addr.do_send(NewWebrtcTransportResponse {
                transport_type: String::from("consumer"),
                webrtc_transport: TransportOptions {
                    id: consumer_transport.id(),
                    dtls_parameters: consumer_transport.dtls_parameters(),
                    ice_candidates: consumer_transport.ice_candidates().clone(),
                    ice_parameters: consumer_transport.ice_parameters().clone(),
                },
            });
            {
                user.as_ref()
                    .write()
                    .await
                    .insert_transport(consumer_transport, true);
            }
        } else {
            transport_options.app_data = AppData::new(TransportAppData {
                router_id: router.id(),
                is_consumer: false,
            });
            let user_addr = { user.as_ref().read().await.ws_actor_addr.clone() };
            let id = { user.as_ref().read().await.id };
            let producer_transport = match router
                .create_webrtc_transport(transport_options.clone())
                .await
            {
                Ok(transport) => transport,
                Err(error) => {
                    user_addr.do_send(DisconnectMessage {
                        id,
                        send_to_client: true,
                        send_to_room: true,
                        message: error.to_string(),
                    });
                    return;
                }
            };
            user_addr.do_send(NewWebrtcTransportResponse {
                transport_type: String::from("producer"),
                webrtc_transport: TransportOptions {
                    id: producer_transport.id(),
                    dtls_parameters: producer_transport.dtls_parameters(),
                    ice_candidates: producer_transport.ice_candidates().clone(),
                    ice_parameters: producer_transport.ice_parameters().clone(),
                },
            });
            {
                user.as_ref()
                    .write()
                    .await
                    .insert_transport(producer_transport, false);
            }
        }
    }
pub async fn create_webrtc_transport ( user : Rc < RwLock < User > > , router : Router , is_consumer : bool , ) { let listen_ip = env :: var ( " " ) . unwrap ( ) ; let announced_ip : String = env :: var ( " " ) . unwrap ( ) ; let arr : Vec < & str > = announced_ip . split ( " " ) . collect ( ) ; let mut transport_options = WebRtcTransportOptions :: new ( TransportListenIps :: new ( TransportListenIp { ip : listen_ip . parse ( ) . unwrap ( ) , announced_ip : Some ( IpAddr :: V4 ( Ipv4Addr :: new ( arr [ 0 ] . parse ( ) . unwrap ( ) , arr [ 1 ] . parse ( ) . unwrap ( ) , arr [ 2 ] . parse ( ) . unwrap ( ) , arr [ 3 ] . parse ( ) . unwrap ( ) , ) ) ) , } ) ) ; transport_options . enable_tcp = true ; transport_options . enable_udp = true ; transport_options . prefer_tcp = true ; if is_consumer { transport_options . app_data = AppData :: new ( TransportAppData { router_id : router . id ( ) , is_consumer : true , } ) ; let user_addr = { user . as_ref ( ) . read ( ) . await . ws_actor_addr . clone ( ) } ; let id = { user . as_ref ( ) . read ( ) . await . id } ; let consumer_transport = match router . create_webrtc_transport ( transport_options ) . await { Ok ( transport ) => transport , Err ( error ) => { user_addr . do_send ( DisconnectMessage { id , send_to_client : true , send_to_room : true , message : error . to_string ( ) , } ) ; return ; } } ; user_addr . do_send ( NewWebrtcTransportResponse { transport_type : String :: from ( " " ) , webrtc_transport : TransportOptions { id : consumer_transport . id ( ) , dtls_parameters : consumer_transport . dtls_parameters ( ) , ice_candidates : consumer_transport . ice_candidates ( ) . clone ( ) , ice_parameters : consumer_transport . ice_parameters ( ) . clone ( ) , } , } ) ; { user . as_ref ( ) . write ( ) . await . insert_transport ( consumer_transport , true ) ; } } else { transport_options . app_data = AppData :: new ( TransportAppData { router_id : router . id ( ) , is_consumer : false , } ) ; let user_addr = { user . as_ref ( ) . read ( ) . await . ws_actor_addr . clone ( ) } ; let id = { user . as_ref ( ) . read ( ) . await . id } ; let producer_transport = match router . create_webrtc_transport ( transport_options . clone ( ) ) . await { Ok ( transport ) => transport , Err ( error ) => { user_addr . do_send ( DisconnectMessage { id , send_to_client : true , send_to_room : true , message : error . to_string ( ) , } ) ; return ; } } ; user_addr . do_send ( NewWebrtcTransportResponse { transport_type : String :: from ( " " ) , webrtc_transport : TransportOptions { id : producer_transport . id ( ) , dtls_parameters : producer_transport . dtls_parameters ( ) , ice_candidates : producer_transport . ice_candidates ( ) . clone ( ) , ice_parameters : producer_transport . ice_parameters ( ) . clone ( ) , } , } ) ; { user . as_ref ( ) . write ( ) . await . insert_transport ( producer_transport , false ) ; } } }
create webrtc transport using listen ip and announced ip specified in environment variable.
create webrtc transport using listen ip and announced ip specified in environment variable .
user
Rc<RwLock<User>>
router
Router
is_consumer
bool
user
Rc<RwLock<User>>
router
Router
is_consumer
bool