diff --git a/api/peer_connection_interface.h b/api/peer_connection_interface.h index 72e20b9200..2ae290c8d6 100644 --- a/api/peer_connection_interface.h +++ b/api/peer_connection_interface.h @@ -1203,6 +1203,14 @@ class PeerConnectionObserver { int error_code, const std::string& error_text) {} + // Gathering of an ICE candidate failed. + // See https://w3c.github.io/webrtc-pc/#event-icecandidateerror + virtual void OnIceCandidateError(const std::string& address, + int port, + const std::string& url, + int error_code, + const std::string& error_text) {} + // Ice candidates have been removed. // TODO(honghaiz): Make this a pure virtual method when all its subclasses // implement it. diff --git a/p2p/base/port.h b/p2p/base/port.h index 84340e831a..4200bed096 100644 --- a/p2p/base/port.h +++ b/p2p/base/port.h @@ -128,16 +128,19 @@ struct ProtocolAddress { struct IceCandidateErrorEvent { IceCandidateErrorEvent() = default; - IceCandidateErrorEvent(std::string host_candidate, + IceCandidateErrorEvent(std::string address, + int port, std::string url, int error_code, std::string error_text) - : host_candidate(std::move(host_candidate)), + : address(std::move(address)), + port(port), url(std::move(url)), error_code(error_code), error_text(std::move(error_text)) {} - std::string host_candidate; + std::string address; + int port = 0; std::string url; int error_code = 0; std::string error_text; diff --git a/p2p/base/stun_port.cc b/p2p/base/stun_port.cc index e259e8b302..4e1a1f6a97 100644 --- a/p2p/base/stun_port.cc +++ b/p2p/base/stun_port.cc @@ -544,8 +544,9 @@ void UDPPort::OnStunBindingOrResolveRequestFailed( rtc::StringBuilder url; url << "stun:" << stun_server_addr.ToString(); SignalCandidateError( - this, IceCandidateErrorEvent(GetLocalAddress().ToSensitiveString(), - url.str(), error_code, reason)); + this, IceCandidateErrorEvent(GetLocalAddress().HostAsSensitiveURIString(), + GetLocalAddress().port(), url.str(), + error_code, reason)); if (bind_request_failed_servers_.find(stun_server_addr) != bind_request_failed_servers_.end()) { return; diff --git a/p2p/base/stun_port_unittest.cc b/p2p/base/stun_port_unittest.cc index f0a2117ef4..dfc72362ce 100644 --- a/p2p/base/stun_port_unittest.cc +++ b/p2p/base/stun_port_unittest.cc @@ -226,9 +226,8 @@ TEST_F(StunPortTest, TestPrepareAddressFail) { cricket::SERVER_NOT_REACHABLE_ERROR, kTimeoutMs, fake_clock); ASSERT_NE(error_event_.error_text.find("."), std::string::npos); - ASSERT_NE( - error_event_.host_candidate.find(kLocalAddr.HostAsSensitiveURIString()), - std::string::npos); + ASSERT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()), + std::string::npos); std::string server_url = "stun:" + kBadAddr.ToString(); ASSERT_EQ(error_event_.url, server_url); } diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index 0dc67aa8c1..ed82e35009 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -885,7 +885,8 @@ void TurnPort::OnAllocateError(int error_code, const std::string& reason) { thread()->Post(RTC_FROM_HERE, this, MSG_ALLOCATE_ERROR); SignalCandidateError( this, - IceCandidateErrorEvent(GetLocalAddress().ToSensitiveString(), + IceCandidateErrorEvent(GetLocalAddress().HostAsSensitiveURIString(), + GetLocalAddress().port(), ReconstructedServerUrl(true /* use_hostname */), error_code, reason)); } diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index f9e0205cd6..e8c1a6e0f3 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc @@ -931,9 +931,9 @@ TEST_F(TurnPortTest, EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, STUN_ERROR_GLOBAL_FAILURE, kSimulatedRtt, fake_clock_); ASSERT_NE(error_event_.error_text.find("."), std::string::npos); - ASSERT_NE( - error_event_.host_candidate.find(kLocalAddr2.HostAsSensitiveURIString()), - std::string::npos); + ASSERT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()), + std::string::npos); + ASSERT_NE(error_event_.port, 0); std::string server_url = "turn:" + kTurnTcpIntAddr.ToString() + "?transport=tcp"; ASSERT_EQ(error_event_.url, server_url); diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 1339638f9f..0d43da4a51 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -4736,14 +4736,17 @@ void PeerConnection::OnIceCandidate( Observer()->OnIceCandidate(candidate.get()); } -void PeerConnection::OnIceCandidateError(const std::string& host_candidate, +void PeerConnection::OnIceCandidateError(const std::string& address, + int port, const std::string& url, int error_code, const std::string& error_text) { if (IsClosed()) { return; } - Observer()->OnIceCandidateError(host_candidate, url, error_code, error_text); + Observer()->OnIceCandidateError(address, port, url, error_code, error_text); + // Leftover not to break wpt test during migration to the new API. + Observer()->OnIceCandidateError(address + ":", url, error_code, error_text); } void PeerConnection::OnIceCandidatesRemoved( @@ -6348,7 +6351,7 @@ void PeerConnection::OnTransportControllerCandidatesGathered( void PeerConnection::OnTransportControllerCandidateError( const cricket::IceCandidateErrorEvent& event) { - OnIceCandidateError(event.host_candidate, event.url, event.error_code, + OnIceCandidateError(event.address, event.port, event.url, event.error_code, event.error_text); } diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 0e1a1f8ac3..9065982f00 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -569,7 +569,8 @@ class PeerConnection : public PeerConnectionInternal, void OnIceCandidate(std::unique_ptr candidate) RTC_RUN_ON(signaling_thread()); // Gathering of an ICE candidate failed. - void OnIceCandidateError(const std::string& host_candidate, + void OnIceCandidateError(const std::string& address, + int port, const std::string& url, int error_code, const std::string& error_text) diff --git a/pc/peer_connection_integrationtest.cc b/pc/peer_connection_integrationtest.cc index dd06b65ffa..d68b058a4b 100644 --- a/pc/peer_connection_integrationtest.cc +++ b/pc/peer_connection_integrationtest.cc @@ -977,11 +977,12 @@ class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp); last_candidate_gathered_ = candidate->candidate(); } - void OnIceCandidateError(const std::string& host_candidate, + void OnIceCandidateError(const std::string& address, + int port, const std::string& url, int error_code, const std::string& error_text) override { - error_event_ = cricket::IceCandidateErrorEvent(host_candidate, url, + error_event_ = cricket::IceCandidateErrorEvent(address, port, url, error_code, error_text); } void OnDataChannel( @@ -5708,8 +5709,7 @@ TEST_P(PeerConnectionIntegrationTest, OnIceCandidateError) { EXPECT_EQ_WAIT(401, caller()->error_event().error_code, kDefaultTimeout); EXPECT_EQ("Unauthorized", caller()->error_event().error_text); EXPECT_EQ("turn:88.88.88.0:3478?transport=udp", caller()->error_event().url); - EXPECT_NE(std::string::npos, - caller()->error_event().host_candidate.find(":")); + EXPECT_NE(caller()->error_event().address, ""); } TEST_F(PeerConnectionIntegrationTestUnifiedPlan, diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc index d8f2b65ac7..782cd21751 100644 --- a/test/peer_scenario/peer_scenario_client.cc +++ b/test/peer_scenario/peer_scenario_client.cc @@ -79,12 +79,13 @@ class LambdaPeerConnectionObserver final : public PeerConnectionObserver { for (const auto& handler : handlers_->on_ice_candidate) handler(candidate); } - void OnIceCandidateError(const std::string& host_candidate, + void OnIceCandidateError(const std::string& address, + int port, const std::string& url, int error_code, const std::string& error_text) override { for (const auto& handler : handlers_->on_ice_candidate_error) - handler(host_candidate, url, error_code, error_text); + handler(address, port, url, error_code, error_text); } void OnIceCandidatesRemoved( const std::vector& candidates) override { diff --git a/test/peer_scenario/peer_scenario_client.h b/test/peer_scenario/peer_scenario_client.h index 404ae90048..7517304eac 100644 --- a/test/peer_scenario/peer_scenario_client.h +++ b/test/peer_scenario/peer_scenario_client.h @@ -48,8 +48,11 @@ class PeerScenarioClient { on_ice_gathering_change; std::vector> on_ice_candidate; - std::vector> + std::vector> on_ice_candidate_error; std::vector&)>> on_ice_candidates_removed;