8.2 RTCPeerConnection Interface Extensions

The Statistics API extends the RTCPeerConnection interface as described below.

  1. WebIDL partial interface RTCPeerConnection {
  2. Promise<RTCStatsReport> getStats(optional MediaStreamTrack? selector = null);
  3. };

Methods

getStats

Gathers stats for the given selector and reports the result asynchronously.

When the getStats() method is invoked, the user agent MUST run the following steps:

  1. Let selectorArg be the method’s first argument.

  2. Let connection be the RTCPeerConnection object on which the method was invoked.

  3. If selectorArg is null, let selector be null.

  4. If selectorArg is a MediaStreamTrack let selector be an RTCRtpSender or RTCRtpReceiver on connection which track attribute matches selectorArg. If no such sender or receiver exists, or if more than one sender or receiver fit this criteria, return a promise rejected with a newly created InvalidAccessError.

  5. Let p be a new promise.

  6. Run the following steps in parallel:

    1. Gather the stats indicated by selector according to the stats selection algorithm.

    2. Resolve p with the resulting RTCStatsReport object, containing the gathered stats.

  7. Return p.