files/en-us/web/api/rtcicecandidatepairstats/index.md
{{APIRef("WebRTC")}}
The RTCIceCandidatePairStats dictionary of the WebRTC API is used to report statistics that provide insight into the quality and performance of an {{domxref("RTCPeerConnection")}} while connected and configured as described by the specified pair of {{Glossary("ICE")}} candidates.
The statistics can be obtained by iterating the {{domxref("RTCStatsReport")}} returned by {{domxref("RTCPeerConnection.getStats()")}} until you find an entry with the type of "candidate-pair".
true, indicates that the candidate pair described by this object is one which has been proposed for use, and will be (or was) used if its priority is the highest among the nominated candidate pairs. See {{RFC(5245, "", "7.1.3.2.4")}} for details.RTCIceCandidateStats object describing the remote end of the connection.The following properties are common to all WebRTC statistics objects.
<!-- RTCStats -->"candidate-pair", indicating the type of statistics that the object contains.The following properties have been removed from the specification and should no longer be used. You should update any existing code to avoid using them as soon as is practical. Check the compatibility table for details on which browsers support them and in which versions.
true if the candidate pair described by this object is the one currently in use.
The spec-compliant way to determine the selected candidate pair is to look for a stats object of type transport, which is an {{domxref("RTCTransportStats")}} object.
That object's {{domxref("RTCTransportStats.selectedCandidatePairId", "selectedCandidatePairId")}} property indicates whether or not the specified transport is the one being used.The currently-active ICE candidate pair—if any—can be obtained by calling the {{domxref("RTCIceTransport")}} method {{domxref("RTCIceTransport.getSelectedCandidatePair", "getSelectedCandidatePair()")}}, which returns an {{domxref("RTCIceCandidatePair")}} object, or null if there isn't a pair selected.
The active candidate pair describes the current configuration of the two ends of the {{domxref("RTCPeerConnection")}}.
Any candidate pair that isn't the active pair of candidates for a transport gets deleted if the {{domxref("RTCIceTransport")}} performs an ICE restart, at which point the {{domxref("RTCIceTransport.state", "state")}} of the ICE transport returns to new and negotiation starts once again.
For more information, see ICE restart.
This example computes the average time elapsed between connectivity checks.
if (rtcStats && rtcStats.type === "candidate-pair") {
let elapsed =
(rtcStats.lastRequestTimestamp - rtcStats.firstRequestTimestamp) /
rtcStats.requestsSent;
console.log(`Average time between ICE connectivity checks: ${elapsed} ms.`);
}
The code begins by looking at rtcStats to see if its {{domxref("RTCIceCandidatePairStats.type", "type")}} is candidate-pair.
If it is, then we know that rtcStats is in fact an RTCIceCandidatePairStats object.
We can then compute the average time elapsed between STUN connectivity checks and log that information.
{{Specifications}}
{{Compat}}