diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 0411ab2924..a340f9845d 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -1797,9 +1797,11 @@ void PeerConnection::SetConnectionState( connection_state_ = new_state; Observer()->OnConnectionChange(new_state); - // The connection state change to connected usually happens once per - // connection which makes it a good point to report metrics. - if (new_state == PeerConnectionState::kConnected) { + if (new_state == PeerConnectionState::kConnected && !was_ever_connected_) { + was_ever_connected_ = true; + + // The first connection state change to connected happens once per + // connection which makes it a good point to report metrics. // Record bundle-policy from configuration. Done here from // connectionStateChange to limit to actually established connections. BundlePolicyUsage policy = kBundlePolicyUsageMax; diff --git a/pc/peer_connection.h b/pc/peer_connection.h index d81f3c9918..98c5519950 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -707,6 +707,10 @@ class PeerConnection : public PeerConnectionInternal, std::unique_ptr rtp_manager_; rtc::WeakPtrFactory weak_factory_; + + // Did the connectionState ever change to `connected`? + // Used to gather metrics only the first such state change. + bool was_ever_connected_ RTC_GUARDED_BY(signaling_thread()) = false; }; } // namespace webrtc