RTCRtpReceiver: getStats() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2019.
TheRTCRtpReceiver methodgetStats() asynchronously requests anRTCStatsReport object which provides statistics about incoming traffic on the owningRTCPeerConnection, returning aPromise whose fulfillment handler will be called once the results are available.
In this article
Syntax
getStats()Parameters
None.
Return value
A JavaScriptPromise which is fulfilled once the statistics are available.The promise's fulfillment handler receives as a parameter aRTCStatsReport object containing the collected statistics.
The returned statistics include those from all streams which are coming in through theRTCRtpReceiver, as well as any of their dependencies.
These might include, for example, statistics withtypes:inbound-rtp,candidate-pair,local-candidate,remote-candidate.
Examples
This simple example obtains the statistics for anRTCRtpReceiver and updates an element'sinnerText to display the number of packets lost.
receiver.getStats().then((stats) => { document.getElementById("lost-packets").innerText = stats.packetsLost;});Specifications
| Specification |
|---|
| WebRTC: Real-Time Communication in Browsers> # widl-RTCRtpReceiver-getStats-Promise-RTCStatsReport> |