diff --git a/webrtc/tools/rtcbot/bot/browser/bot.js b/webrtc/tools/rtcbot/bot/browser/bot.js index 8839802134..808d88a8b1 100644 --- a/webrtc/tools/rtcbot/bot/browser/bot.js +++ b/webrtc/tools/rtcbot/bot/browser/bot.js @@ -48,12 +48,49 @@ function createPeerConnection(doneCallback, failCallback) { pc.addStream(tempStream); }; + // Return an array of Objects, each Object is a copy of RTCStateReport + // and has the following attributes (id, type, names, and stats). + // names: array originaly returned by calling RTCStateReport.names(). + // stats: dictionary of stat name as key and stat value as dictionary + // value. + obj.getStats = function(callback, mediaTrack) { + pc.getStats(onStatsReady, mediaTrack); + + function onStatsReady(stateResponse) { + var outputReports = []; + var reports = stateResponse.result(); + for (index in reports) { + var report = {}; + report.id = reports[index].id; + report.type = reports[index].type; + report.names = reports[index].names(); + report.stats = []; + populateStats(reports[index], report.stats); + + outputReports.push(report); + } + + callback(outputReports); + } + + function populateStats(report, stats) { + var names = report.names(); + for (index in names) { + stats.push({ + name: names[index], + stat: report.stat(names[index]), + }); + } + + } + }; + pc.addEventListener('addstream', function(event) { remoteStreams[event.stream.id] = event.stream; }); doneCallback(obj); -} +}; function showStream(streamId, autoplay, muted) { var stream = getStreamFromIdentifier_(streamId); @@ -74,7 +111,7 @@ function getStreamFromIdentifier_(id) { return tempStream; console.log(id + " is not id for stream."); return null; -} +}; connectToServer({ ping: ping, diff --git a/webrtc/tools/rtcbot/test.js b/webrtc/tools/rtcbot/test.js index 36675ccbf1..23a3f9c219 100644 --- a/webrtc/tools/rtcbot/test.js +++ b/webrtc/tools/rtcbot/test.js @@ -79,7 +79,8 @@ Test.prototype = { function runTest(botType, testfile) { console.log("Running test: " + testfile); var script = vm.createScript(fs.readFileSync(testfile), testfile); - script.runInNewContext({ test: new Test(botType) }); + script.runInNewContext({ test: new Test(botType), setInterval: setInterval + setTimeout: setTimeout }); } runTest(process.argv[2], process.argv[3]);