Skip to content

Commit

Permalink
Testing peerconnection.getstats()
Browse files Browse the repository at this point in the history
  • Loading branch information
Manjesh Malavalli committed Jun 10, 2013
1 parent 0b11eff commit 7d2d7fe
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions peerconnection.js
Expand Up @@ -906,6 +906,66 @@ GoCastJS.PeerConnection.prototype.Height = function(height) {
return this.player.height;
};

/**
* Get peerconnection network statistics.
* @memberof GoCastJS.PeerConnection
* @param {Function} onstats - function(stats) {} - callback with stats array.
*/
GoCastJS.PeerConnection.prototype.GetStats = function(onstats) {
var dumpstats = function(statobj) {
var ret = {}, statnames;

if (statobj.id) {
ret.id = statobj.id;
}
if (statobj.type) {
ret.type = statobj.type;
}
if (statobj.timestamp) {
ret.timestamp = statobj.timestamp;
}
if (statobj.names) {
statnames = statobj.names();
for (var i=0; i<statnames.length; i++) {
ret[statnames[i]] = statobj.stat(statnames[i]);
}
} else if (statobj.stat('audioOutputLevel')) {
ret.audioOutputLevel = statobj.stat('audioOutputLevel');
}

return ret;
};

onstats = onstats || function(stats) {};
if ('native' === this.apitype && this.peerconn.getStats) {
this.peerconn.getStats(function(stats) {
var statlist = stats.result(),
statsarr = [], ret;

for (var i=0; i<statlist.length; i++) {
if (!statlist[i].local || statlist[i].local === statlist[i]) {
statsarr.push(dumpstats(statlist[i]));
} else {
if (statlist[i].local) {
ret = dumpstats(statlist[i]);
ret.local = true;
statsarr.push(ret);
}
if (statlist.remote) {
ret = dumpstats(statlist[i]);
ret.remote = true;
statsarr.push(ret);
}
}
}

onstats(statsarr);
});
} else {
onstats([]);
}
}

/**
* Get plugin logs for debugging purposes.
* @memberof GoCastJS
Expand Down

0 comments on commit 7d2d7fe

Please sign in to comment.