diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index 73455d5991..f8821bb1ec 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -1401,9 +1401,14 @@ void JsepTransportController::UpdateAggregateStates_n() { // None of the previous states apply and any RTCIceTransports are in the // "new" or "checking" state. new_ice_connection_state = PeerConnectionInterface::kIceConnectionChecking; - } else if (total_ice_completed + total_ice_closed == total_ice) { + } else if (total_ice_completed + total_ice_closed == total_ice || + all_completed) { // None of the previous states apply and all RTCIceTransports are in the // "completed" or "closed" state. + // + // TODO(https://bugs.webrtc.org/10356): The all_completed condition is added + // to mimic the behavior of the old ICE connection state, and should be + // removed once we get end-of-candidates signaling in place. new_ice_connection_state = PeerConnectionInterface::kIceConnectionCompleted; } else if (total_ice_connected + total_ice_completed + total_ice_closed == total_ice) { @@ -1415,6 +1420,16 @@ void JsepTransportController::UpdateAggregateStates_n() { } if (standardized_ice_connection_state_ != new_ice_connection_state) { + if (standardized_ice_connection_state_ == + PeerConnectionInterface::kIceConnectionChecking && + new_ice_connection_state == + PeerConnectionInterface::kIceConnectionCompleted) { + // Ensure that we never skip over the "connected" state. + invoker_.AsyncInvoke(RTC_FROM_HERE, signaling_thread_, [this] { + SignalStandardizedIceConnectionState( + PeerConnectionInterface::kIceConnectionConnected); + }); + } standardized_ice_connection_state_ = new_ice_connection_state; invoker_.AsyncInvoke( RTC_FROM_HERE, signaling_thread_, [this, new_ice_connection_state] { diff --git a/pc/peer_connection_integrationtest.cc b/pc/peer_connection_integrationtest.cc index f87a4476f2..c14bb91be7 100644 --- a/pc/peer_connection_integrationtest.cc +++ b/pc/peer_connection_integrationtest.cc @@ -281,6 +281,13 @@ class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, ice_connection_state_history_.clear(); } + // Every standardized ICE connection state in order that has been seen by the + // observer. + std::vector + standardized_ice_connection_state_history() const { + return standardized_ice_connection_state_history_; + } + // Every PeerConnection state in order that has been seen by the observer. std::vector peer_connection_state_history() const { @@ -894,6 +901,10 @@ class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, EXPECT_EQ(pc()->ice_connection_state(), new_state); ice_connection_state_history_.push_back(new_state); } + void OnStandardizedIceConnectionChange( + webrtc::PeerConnectionInterface::IceConnectionState new_state) override { + standardized_ice_connection_state_history_.push_back(new_state); + } void OnConnectionChange( webrtc::PeerConnectionInterface::PeerConnectionState new_state) override { peer_connection_state_history_.push_back(new_state); @@ -981,6 +992,8 @@ class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, std::vector ice_connection_state_history_; + std::vector + standardized_ice_connection_state_history_; std::vector peer_connection_state_history_; std::vector @@ -3928,7 +3941,7 @@ TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) { ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, caller()->ice_connection_state()); - ASSERT_EQ(PeerConnectionInterface::kIceConnectionConnected, + ASSERT_EQ(PeerConnectionInterface::kIceConnectionCompleted, caller()->standardized_ice_connection_state()); // Verify that the observer was notified of the intermediate transitions. @@ -3936,6 +3949,10 @@ TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) { ElementsAre(PeerConnectionInterface::kIceConnectionChecking, PeerConnectionInterface::kIceConnectionConnected, PeerConnectionInterface::kIceConnectionCompleted)); + EXPECT_THAT(caller()->standardized_ice_connection_state_history(), + ElementsAre(PeerConnectionInterface::kIceConnectionChecking, + PeerConnectionInterface::kIceConnectionConnected, + PeerConnectionInterface::kIceConnectionCompleted)); EXPECT_THAT( caller()->peer_connection_state_history(), ElementsAre(PeerConnectionInterface::PeerConnectionState::kConnecting, @@ -3963,7 +3980,7 @@ TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) { ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, caller()->ice_connection_state(), kDefaultTimeout, fake_clock); - ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionConnected, + ASSERT_EQ_SIMULATED_WAIT(PeerConnectionInterface::kIceConnectionCompleted, caller()->standardized_ice_connection_state(), kDefaultTimeout, fake_clock);