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.