getStats()

getStats() is the API in WebRTC that is used to collect metrics (statistics) from an ongoing WebRTC session. It is usually called periodically throughout the lifetime of a WebRTC session to gauge the health of the session by the client.

The metrics returned are returned as a set of reports, each dealing with a different aspect of the session. A full breakdown of these report types and their fields is available in this WebRTC stats reference.

There are two types of metrics you can retrieve with getStats(), the set that is now called “legacy” stats and the spec-compliant stats. The spec-compliant ones are provided when calling getStats() using a promise. It is advisable to use the spec-complaint stats.

The data exposed via getStats() is also available in webrtc-internals.

Collecting getStats() is the easy part. Making sense of it is where it gets tricky: the reports pile up across the whole session, and the numbers only mean something in context - against the moments before and after, and against what the user actually experienced. That correlation across a full call is what tools like rtcStats automate, turning the raw reports into a read on what went wrong and when.

Additional reading

Tsahi Levent-Levi

Tsahi Levent-Levi

Independent WebRTC analyst. 20+ years in telecom, 13 focused on WebRTC. Writes for developers and product teams who need to understand, not just implement, real-time communications.