changes to Adapter for getStats() in version 3.0.0

384 views
Skip to first unread message

Philipp Hancke

unread,
Jan 16, 2017, 1:27:36 PM1/16/17
to discuss...@googlegroups.com

adapter is going to make a major version bump really soon now. The planned changes are outlined below and are already in the main branch of the repository. They have not yet been published as version 3.0.0 to npm.


There are a number of breaking changes that affect the way getStats() works. Since Chrome just shipped spec-compliant statistics (behind a command line flag) in M56, and hope to release it in M58 (see the announcement), we wanted to allow using them from adapter. There are some related changes that also affect how getStats() works in Firefox and Microsoft Edge.


Spec-stats

If Chrome supports the spec-stats, adapter will not attempt to tinker with them. We use this logic to determine if the spec-stats are supported:

    RTCPeerConnection.prototype.getStats.length === 0

This is 2 (i.e. track and success callback) in the legacy getStats and 0 (track is optional) in the  new getStats. This allows you to test the new statistics today in Chrome Canary (M57+) with the experimental web platform flags enabled. Normal users should not yet be affected by this.


Note that if you use a callback as the first argument to getStats you will continue to get legacy stats both Chrome and adapter.


Iterating Map objects

Updating your code to the new stats will be a major effort since a lot of names changed compared to Chrome’s old statistics. So while you’re updating your code to match this you might as well overhaul it. One of these changes is the functionality to iterate the Map object with Object.keys which is now gone. If you wrote code like this:

pc.getStats(null).then(function(res) {

   Object.keys(res).forEach(function(key) {

       var report = res[key];

       // do something

   });

});

you need to change this to

  res.forEach(function(report) {

       // do something

   });

That is less code even!


Also, if you need to reference across reports you need to use .get(id-of-another-report) instead of using the array accessor. See

   https://github.com/webrtc/samples/pull/851

for the changes we had to make to the WebRTC samples because of this.


Slightly changed type names

Firefox statistics are already mostly spec-compliant. The major issue we found was that there were some hyphens missing from the type properties, see


   https://bugzilla.mozilla.org/show_bug.cgi?id=1322503


adapter adds the hyphen so you can safely write checks for "local-candidate" and "remote-candidate". We also do this for Microsoft Edge which implements some of those types and for Chrome which had "localcandidate" and "remotecandidate".


Let us know if there any questions!

Xander Dumaine

unread,
Jan 17, 2017, 12:10:03 PM1/17/17
to discuss-webrtc
Awesome! Thanks @fippo and team!
Reply all
Reply to author
Forward
0 new messages