Adding getStats function to the exposed PeerConnection in RtcBot
Exposed Peerconnection object has new function "getStats". This function returns the stats as array of reports, and each report is RTCStatReport with additional attributes names and stats. names: array of all the stat names in current report. Stats: dictionary and the key is the stat name, and value is the value of this stat. R=andresp@webrtc.org Review URL: https://webrtc-codereview.appspot.com/23779004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7319 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
730d270771
commit
24f62e1a28
@ -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,
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user