diff --git a/p2p/base/ice_transport_internal.h b/p2p/base/ice_transport_internal.h index fecae48b12..38b6bfe303 100644 --- a/p2p/base/ice_transport_internal.h +++ b/p2p/base/ice_transport_internal.h @@ -338,15 +338,11 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal { // SignalNetworkRouteChanged. sigslot::signal2 SignalRouteChange; - void AddCandidatePairChangeCallback( - const void* removal_tag, + void SetCandidatePairChangeCallback( absl::AnyInvocable callback) { - candidate_pair_change_callback_list_.AddReceiver(removal_tag, - std::move(callback)); - } - void RemoveCandidatePairChangeCallback(const void* removal_tag) { - candidate_pair_change_callback_list_.RemoveReceivers(removal_tag); + RTC_DCHECK(!candidate_pair_change_callback_); + candidate_pair_change_callback_ = std::move(callback); } // Invoked when there is conflict in the ICE role between local and remote @@ -389,8 +385,7 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal { protected: void SendGatheringStateEvent() { SignalGatheringState(this); } - webrtc::CallbackList - candidate_pair_change_callback_list_; + webrtc::CallbackList> @@ -406,6 +401,9 @@ class RTC_EXPORT IceTransportInternal : public rtc::PacketTransportInternal { absl::AnyInvocable candidates_removed_callback_; + absl::AnyInvocable + candidate_pair_change_callback_; + private: // TODO(bugs.webrtc.org/11943): remove when removing Signal void SignalGatheringStateFired(IceTransportInternal* transport) { diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 068e0f392b..241b423be8 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -1838,7 +1838,9 @@ void P2PTransportChannel::SwitchSelectedConnectionInternal( } else { pair_change.estimated_disconnected_time_ms = 0; } - candidate_pair_change_callback_list_.Send(pair_change); + if (candidate_pair_change_callback_) { + candidate_pair_change_callback_(pair_change); + } } ++selected_candidate_pair_changes_; diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index ad4b43bfd3..79ca2a5f26 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -3326,8 +3326,8 @@ class P2PTransportChannelPingTest : public ::testing::Test, &P2PTransportChannelPingTest::OnReadyToSend); ch->SignalStateChanged.connect( this, &P2PTransportChannelPingTest::OnChannelStateChanged); - ch->AddCandidatePairChangeCallback( - this, [this](const cricket::CandidatePairChangeEvent& event) { + ch->SetCandidatePairChangeCallback( + [this](const cricket::CandidatePairChangeEvent& event) { OnCandidatePairChanged(event); }); } diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index 268f5ffff7..dae7060658 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -464,8 +464,8 @@ JsepTransportController::CreateDtlsTransport( this, &JsepTransportController::OnTransportStateChanged_n); dtls->ice_transport()->SignalIceTransportStateChanged.connect( this, &JsepTransportController::OnTransportStateChanged_n); - dtls->ice_transport()->AddCandidatePairChangeCallback( - this, [this](const cricket::CandidatePairChangeEvent& event) { + dtls->ice_transport()->SetCandidatePairChangeCallback( + [this](const cricket::CandidatePairChangeEvent& event) { RTC_DCHECK_RUN_ON(network_thread_); OnTransportCandidatePairChanged_n(event); });