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.

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.

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.