Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peer connection state not become connected while ice_connection_state and dtls_transport_state are all connected #653

Open
lfld287 opened this issue Feb 12, 2025 · 3 comments

Comments

@lfld287
Copy link

lfld287 commented Feb 12, 2025

log:

webrtc-0.12.0\src\peer_connection\mod.rs:307 [INFO] 15:52:34.581448 - signaling state changed to have-local-offer
webrtc-ice-0.12.0\src\agent\agent_gather.rs:801 [WARN] 15:52:34.582244 - [controlled]: Unable to handle URL in gather_candidates_relay turn:172.31.2.27:3478?transport=tcp      
webrtc-0.12.0\src\peer_connection\mod.rs:307 [INFO] 15:52:34.658150 - signaling state changed to stable
webrtc-ice-0.12.0\src\agent\agent_internal.rs:312 [INFO] 15:52:34.659318 - [controlling]: Setting new connection state: Checking
webrtc-ice-0.12.0\src\agent\agent_internal.rs:374 [WARN] 15:52:34.659596 - [controlling]: pingAllCandidates called with no candidate pairs. Connection is not possible yet.     
webrtc-0.12.0\src\peer_connection\mod.rs:629 [INFO] 15:52:34.659593 - ICE connection state changed: checking
tests\offer_peer_test.rs:196 [INFO] 15:52:34.659863 - ICE connection state: Checking
webrtc-0.12.0\src\peer_connection\mod.rs:888 [INFO] 15:52:34.659959 - update_connection_state: ice=checking, dtls=new
webrtc-0.12.0\src\peer_connection\mod.rs:927 [INFO] 15:52:34.660055 - peer connection state changed: connecting
tests\offer_peer_test.rs:185 [INFO] 15:52:34.660165 - Peer connection state: Connecting
webrtc-ice-0.12.0\src\agent\agent_internal.rs:312 [INFO] 15:52:34.677261 - [controlling]: Setting new connection state: Connected
webrtc-0.12.0\src\peer_connection\mod.rs:629 [INFO] 15:52:34.677425 - ICE connection state changed: connected
tests\offer_peer_test.rs:206 [INFO] 15:52:34.677566 - DTLS transport state: Connecting
tests\offer_peer_test.rs:196 [INFO] 15:52:34.677883 - ICE connection state: Connected
webrtc-0.12.0\src\peer_connection\mod.rs:888 [INFO] 15:52:34.678245 - update_connection_state: ice=connected, dtls=connecting
tests\offer_peer_test.rs:206 [INFO] 15:52:34.686419 - DTLS transport state: Connected

test code:

#[tokio::test(flavor = "multi_thread")]
async fn test_pure_offer_peer() {
    //init env logger
    env_logger::Builder::new()
        .format(|buf, record| {
            writeln!(
                buf,
                "{}:{} [{}] {} - {}",
                record.file().unwrap_or("unknown").trim_start_matches("D:\\runtime\\rust_cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\"),
                record.line().unwrap_or(0),
                record.level(),
                chrono::Local::now().format("%H:%M:%S.%6f"),
                record.args()
            )
        })
        .filter(None, log::LevelFilter::Info)
        .init();

    let ctx = Context::new(None);
    let server_url = "my_test_signaling_server"; 
    let client_id = "remote_peer_id"; 
    let bitrate = 3000000;
    let frame_rate = 30;
    let i_frame_interval = 3;

    let room_id = create_room(&ctx, server_url).await.unwrap();

    let ice_servers = get_ice_servers(&ctx, server_url, "test").await.unwrap();

    let wrtc_api = create_api(Default::default()).unwrap();
    let mut config = RTCConfiguration::default();
    config.ice_transport_policy = RTCIceTransportPolicy::Relay;
    config.ice_servers = ice_servers;

    let pc = wrtc_api.new_peer_connection(config).await.unwrap();

    let pc = Arc::new(pc);

    let offer_handshake_handler = OfferHandshakeHandler::new(
        DiscardLogger {},
        pc.clone(),
        Arc::new(server_url.to_string()),
        room_id,
    );

    pc.on_ice_candidate({
        let handler = offer_handshake_handler.clone();
        Box::new(move |candidate| {
            let handler = handler.clone();
            Box::pin(async move {
                if let Some(candidate) = candidate {
                    match candidate.to_json() {
                        Ok(candidate_init) => {
                            handler.on_ice_candidate(candidate_init).await;
                        }
                        Err(_err) => {
                            //todo log
                        }
                    }
                }
            })
        })
    });

    pc.on_peer_connection_state_change({
        let handler = offer_handshake_handler.clone();
        Box::new(move |state| {
            Box::pin({
                let handler = handler.clone();
                async move {
                    log::info!("Peer connection state: {:?}", state);
                    handler.on_state(state).await;
                }
            })
        })
    });

    pc.on_ice_connection_state_change({
        Box::new(move |state| {
            Box::pin({
                async move {
                    log::info!("ICE connection state: {:?}", state);
                }
            })
        })
    });

    pc.dtls_transport().on_state_change({
        Box::new(move |state| {
            Box::pin({
                async move {
                    log::info!("DTLS transport state: {:?}", state);
                }
            })
        })
    });

    pc.add_transceiver_from_kind(Video, None).await.unwrap();
    pc.add_transceiver_from_kind(Audio, None).await.unwrap();

    let offer = pc.create_offer(None).await.unwrap();

    pc.set_local_description(offer.clone()).await.unwrap();

    let offer_str: String = serde_json::to_string(&offer).unwrap();

    let answer_str = send_offer_for_answer(
        &ctx,
        server_url,
        client_id,
        room_id,
        &offer_str,
        1280,
        bitrate,
        frame_rate,
        i_frame_interval,
    )
        .await
        .unwrap();

    let answer: RTCSessionDescription = serde_json::from_str(&answer_str).unwrap();

    pc.set_remote_description(answer).await.unwrap();

    tokio::time::sleep(tokio::time::Duration::from_secs(40)).await;
}

(remote peer can work with chrome and pion)

@lfld287
Copy link
Author

lfld287 commented Feb 12, 2025

after some debug, I find out it stuck at start_srtp()

@lfld287
Copy link
Author

lfld287 commented Feb 12, 2025

after some more debug , I found out it stuck at webrtc-srtp\src\Context\mod.rs Context::new()

@lfld287
Copy link
Author

lfld287 commented Feb 12, 2025

Add code from #649 (comment) solved the problem, no idea what's happening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant