Neither Chrome nor Firefox quite conforms to the spec for WebRTC statistics, nor is the spec done evolving. I’ll try to document some of their peculiarities here and to update this post when changes arise.
The spec says
RTCPeerConnection.getStats takes a nullable
MediaStreamTrack, a success callback, and a failure callback, in that order. The success callback is passed an
RTCStatsReport which has a getter for accessing its various
RTCStats by ID.
Chrome reverses the order of the first two parameters, and its success callback is passed a
result method returns a list of
RTCStatReport objects. Chrome’s
RTCStatsReport does not correspond to the spec’s type of the same name, but to its
RTCStats; it is just a dictionary.
Firefox matches the spec; but the callbacks are optional, and if both callbacks are omitted then a
Promise is returned. Presumably the spec will eventually prefer Promises as it already does for other methods.
The two APIs can be unified with the following code:
RTCStatsReport in Chrome) object is a dictionary with three default attributes:
id; and various other attributes: some required, depending on
type, and others that are implementation specific.
Firefox does not include
The spec defines various stats report types. Instead of
inboundrtp, Chrome uses
ssrc. The exact type can be inferred from the presence of attributes such as
The spec decrees that
roundtriptime shall be defined on an RTPOutboundRTPStreamStats object. Google calls this
googRtt. Firefox calls it
mozRtt and puts it on the inbound stats rather than the outbound.