diff --git a/samples/js/demos/html/constraints-and-stats.html b/samples/js/demos/html/constraints-and-stats.html index 6f251a12ab..2f1beba622 100644 --- a/samples/js/demos/html/constraints-and-stats.html +++ b/samples/js/demos/html/constraints-and-stats.html @@ -8,6 +8,8 @@ var mystream; var pc1; var pc2; +var bytesPrev = 0; +var timestampPrev = 0; $ = function(id) { return document.getElementById(id); @@ -117,12 +119,10 @@ var statCollector = setInterval(function() { display("No stream"); if (pc2 && pc2.getRemoteStreams()[0]) { if (pc2.getStats) { - display('No stats callback'); pc2.getStats(function(stats) { - log('Raw stats ' + stats); var statsString = ''; var results = stats.result(); - log('Raw results ' + results); + var bitrateText = 'No bitrate stats'; for (var i = 0; i < results.length; ++i) { var res = results[i]; statsString += '

Report '; @@ -130,6 +130,20 @@ var statCollector = setInterval(function() { statsString += '

'; if (!res.local || res.local === res) { statsString += dumpStats(res); + // The bandwidth info for video is in a type ssrc stats record + // with googFrameHeightReceived defined. + // Should check for mediatype = video, but this is not + // implemented yet. + if (res.type == 'ssrc' && res.stat('googFrameHeightReceived')) { + var bytesNow = res.stat('bytesReceived'); + if (timestampPrev > 0) { + var bitRate = Math.round((bytesNow - bytesPrev) * 8 / + (res.timestamp - timestampPrev)); + bitrateText = bitRate + ' kbits/sec'; + } + timestampPrev = res.timestamp; + bytesPrev = bytesNow; + } } else { // Pre-227.0.1445 (188719) browser if (res.local) { @@ -143,7 +157,7 @@ var statCollector = setInterval(function() { } } $('stats').innerHTML = statsString; - display('No bitrate stats'); + display(bitrateText); }); } else { display('No stats function. Use at least Chrome 24.0.1285'); @@ -169,8 +183,15 @@ var statCollector = setInterval(function() { function dumpStats(obj) { var statsString = 'Timestamp:'; statsString += obj.timestamp; + if (obj.id) { + statsString += " id "; + statsString += obj.id; + } + if (obj.type) { + statsString += " type "; + statsString += obj.type; + } if (obj.names) { - log('Have names function'); names = obj.names(); for (var i = 0; i < names.length; ++i) { statsString += '
'; @@ -179,7 +200,6 @@ function dumpStats(obj) { statsString += obj.stat(names[i]); } } else { - log('No names function'); if (obj.stat('audioOutputLevel')) { statsString += "audioOutputLevel: "; statsString += obj.stat('audioOutputLevel');