{"id":259,"date":"2017-02-25T01:35:47","date_gmt":"2017-02-25T01:35:47","guid":{"rendered":"https:\/\/blog.mozilla.org\/webrtc\/?p=259"},"modified":"2018-03-23T20:17:41","modified_gmt":"2018-03-23T20:17:41","slug":"fiddle-week-spec-compliant-getstats","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/","title":{"rendered":"Fiddle-of-the-week: Spec-compliant getStats"},"content":{"rendered":"<p>Firefox has supported <code>getStats<\/code> to the spec for a couple of years now, and Chrome Canary finally has a spec-compliant version, so it&#8217;s a good time to check in how to write code that (soon!) will work across browsers.<\/p>\n<p>Unfortunately, the <a href=\"https:\/\/w3c.github.io\/webrtc-pc\/#rtcpeerconnection-interface-extensions-2\">specification<\/a> has changed several times over the years, even <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=1322503\">breaking Firefox<\/a>. Here&#8217;s how to tell whether your <code>getStats<\/code> code is up to spec as of 2017<!--more-->:<\/p>\n<ol>\n<li>It uses promises (the callback version was removed from the spec!)<\/li>\n<li>You iterate on a <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Map\">maplike<\/a> stats report object.<\/li>\n<li>Type fields have hyphens. E.g. <code>\"inbound-rtp\"<\/code>, <em><strong>NOT<\/strong><\/em> <code>\"inboundrtp\"<\/code>.<\/li>\n<li>No <code>goog<\/code> or <code>moz<\/code> prefixes.<\/li>\n<\/ol>\n<p>Oh, goodness, I hear you say. <a href=\"https:\/\/github.com\/webrtc\/adapter\">adapter.js<\/a> to the rescue. Here&#8217;s an example that works in Firefox and Chrome Canary:<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/jsfiddle.net\/jib1\/omnobf19\/embedded\/js,result,html\/\" allow=\"camera; microphone\" width=\"100%\" height=\"620px\" frameborder=\"0\"><\/iframe><\/p>\n<p>Click the &#8220;Result&#8221; tab above to see it run. Tick the &#8220;Mute&#8221; checkbox and see if your browser stops sending video packets!<\/p>\n<p>There&#8217;s still a lot of work to do. Firefox supports only a subset of what the spec mandates. The point of this blog however, is to help you write spec-compliant code, so we all converge on the spec, for a healthier web.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"Firefox has supported getStats to the spec for a couple of years now, and Chrome Canary finally has a spec-compliant version, so it&#8217;s a good time to check in how to write code that (soon!) will work across browsers. Unfortunately, the specification has changed several times over the years, even breaking Firefox. Here&#8217;s how to [&hellip;]","protected":false},"author":1399,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"coauthors":[301098],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Fiddle-of-the-week: Spec-compliant getStats - Advancing WebRTC<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fiddle-of-the-week: Spec-compliant getStats - Advancing WebRTC\" \/>\n<meta property=\"og:description\" content=\"Firefox has supported getStats to the spec for a couple of years now, and Chrome Canary finally has a spec-compliant version, so it&#8217;s a good time to check in how to write code that (soon!) will work across browsers. Unfortunately, the specification has changed several times over the years, even breaking Firefox. Here&#8217;s how to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/\" \/>\n<meta property=\"og:site_name\" content=\"Advancing WebRTC\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-25T01:35:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-03-23T20:17:41+00:00\" \/>\n<meta name=\"author\" content=\"Jan-Ivar Bruaroey\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jan-Ivar Bruaroey\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/\",\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/\",\"name\":\"Fiddle-of-the-week: Spec-compliant getStats - Advancing WebRTC\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#website\"},\"datePublished\":\"2017-02-25T01:35:47+00:00\",\"dateModified\":\"2018-03-23T20:17:41+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/webrtc\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fiddle-of-the-week: Spec-compliant getStats\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/\",\"name\":\"Advancing WebRTC\",\"description\":\"Committed to moving Firefox and WebRTC forward\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/webrtc\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd\",\"name\":\"Jan-Ivar Bruaroey\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/image\/5f3d49a61b032619d0d33c4cc7c7433f\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g\",\"caption\":\"Jan-Ivar Bruaroey\"},\"url\":\"https:\/\/blog.mozilla.org\/webrtc\/author\/jbruaroeymozilla-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Fiddle-of-the-week: Spec-compliant getStats - Advancing WebRTC","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/","og_locale":"en_US","og_type":"article","og_title":"Fiddle-of-the-week: Spec-compliant getStats - Advancing WebRTC","og_description":"Firefox has supported getStats to the spec for a couple of years now, and Chrome Canary finally has a spec-compliant version, so it&#8217;s a good time to check in how to write code that (soon!) will work across browsers. Unfortunately, the specification has changed several times over the years, even breaking Firefox. Here&#8217;s how to [&hellip;]","og_url":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/","og_site_name":"Advancing WebRTC","article_published_time":"2017-02-25T01:35:47+00:00","article_modified_time":"2018-03-23T20:17:41+00:00","author":"Jan-Ivar Bruaroey","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jan-Ivar Bruaroey","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/","url":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/","name":"Fiddle-of-the-week: Spec-compliant getStats - Advancing WebRTC","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/#website"},"datePublished":"2017-02-25T01:35:47+00:00","dateModified":"2018-03-23T20:17:41+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/webrtc\/fiddle-week-spec-compliant-getstats\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/webrtc\/"},{"@type":"ListItem","position":2,"name":"Fiddle-of-the-week: Spec-compliant getStats"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/webrtc\/#website","url":"https:\/\/blog.mozilla.org\/webrtc\/","name":"Advancing WebRTC","description":"Committed to moving Firefox and WebRTC forward","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/webrtc\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/f2eb9712b8d85b70aebe1faf24e731fd","name":"Jan-Ivar Bruaroey","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webrtc\/#\/schema\/person\/image\/5f3d49a61b032619d0d33c4cc7c7433f","url":"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/16d7e05dc9f8a855a02e0796b00aad3f?s=96&d=mm&r=g","caption":"Jan-Ivar Bruaroey"},"url":"https:\/\/blog.mozilla.org\/webrtc\/author\/jbruaroeymozilla-com\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts\/259"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/users\/1399"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/comments?post=259"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/posts\/259\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/media?parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/categories?post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/tags?post=259"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webrtc\/wp-json\/wp\/v2\/coauthors?post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}