Removes hard-coded constants and uses the events API in the statistics

module.
pull/361/head 677
Boris Grozev 9 years ago
parent 62d3b749bb
commit 506d0722bd
  1. 4
      modules/UI/UI.js
  2. 8
      modules/connectionquality/connectionquality.js
  3. 3
      modules/statistics/LocalStatsCollector.js
  4. 9
      modules/statistics/RTPStatsCollector.js
  5. 38
      modules/statistics/statistics.js
  6. 14
      service/statistics/Events.js

@ -30,6 +30,7 @@ var RTCEvents = require("../../service/RTC/RTCEvents");
var RTCBrowserType = require("../RTC/RTCBrowserType");
var StreamEventTypes = require("../../service/RTC/StreamEventTypes");
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var StatisticsEvents = require("../../service/statistics/Events");
var UIEvents = require("../../service/UI/UIEvents");
var MemberEvents = require("../../service/members/Events");
@ -180,7 +181,8 @@ function registerListeners() {
var userResource = APP.UI.getLargeVideoResource();
eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, userResource);
});
APP.statistics.addAudioLevelListener(function(jid, audioLevel) {
APP.statistics.addListener(StatisticsEvents.AUDIO_LEVEL,
function(jid, audioLevel) {
var resourceJid;
if(jid === APP.statistics.LOCAL_JID) {
resourceJid = AudioLevels.LOCAL_LEVEL;

@ -4,6 +4,7 @@ var EventEmitter = require("events");
var eventEmitter = new EventEmitter();
var CQEvents = require("../../service/connectionquality/CQEvents");
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var StatisticsEvents = require("../../service/statistics/Events");
/**
* local stats
@ -76,9 +77,10 @@ function parseMUCStats(stats) {
var ConnectionQuality = {
init: function () {
APP.xmpp.addListener(XMPPEvents.REMOTE_STATS, this.updateRemoteStats);
APP.statistics.addConnectionStatsListener(this.updateLocalStats);
APP.statistics.addRemoteStatsStopListener(this.stopSendingStats);
APP.statistics.addListener(StatisticsEvents.CONNECTION_STATS,
this.updateLocalStats);
APP.statistics.addListener(StatisticsEvents.STOP,
this.stopSendingStats);
},
/**

@ -4,6 +4,7 @@
*/
var RTCBrowserType = require('../RTC/RTCBrowserType');
var StatisticsEvents = require('../../service/statistics/Events');
/**
* Size of the webaudio analyzer buffer.
@ -105,7 +106,7 @@ LocalStatsCollector.prototype.start = function () {
if (audioLevel != self.audioLevel) {
self.audioLevel = animateLevel(audioLevel, self.audioLevel);
self.eventEmitter.emit(
"statistics.audioLevel",
StatisticsEvents.AUDIO_LEVEL,
self.statisticsService.LOCAL_JID,
self.audioLevel);
}

@ -2,6 +2,7 @@
/* jshint -W117 */
/* jshint -W101 */
var RTCBrowserType = require("../RTC/RTCBrowserType");
var StatisticsEvents = require("../../service/statistics/Events");
/* Whether we support the browser we are running into for logging statistics */
var browserSupported = RTCBrowserType.isChrome() ||
@ -646,7 +647,7 @@ StatsCollector.prototype.processStatsReport = function () {
upload:
calculatePacketLoss(lostPackets.upload, totalPackets.upload)
};
this.eventEmitter.emit("statistics.connectionstats",
this.eventEmitter.emit(StatisticsEvents.CONNECTION_STATS,
{
"bitrate": PeerStats.bitrate,
"packetLoss": PeerStats.packetLoss,
@ -712,8 +713,10 @@ StatsCollector.prototype.processAudioLevelReport = function () {
// but it seems to vary between 0 and around 32k.
audioLevel = audioLevel / 32767;
jidStats.setSsrcAudioLevel(ssrc, audioLevel);
if(jid != APP.xmpp.myJid())
this.eventEmitter.emit("statistics.audioLevel", jid, audioLevel);
if (jid != APP.xmpp.myJid()) {
this.eventEmitter.emit(
StatisticsEvents.AUDIO_LEVEL, jid, audioLevel);
}
}
}
};

@ -9,6 +9,7 @@ var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
var CallStats = require("./CallStats");
var RTCEvents = require("../../service/RTC/RTCEvents");
var StatisticsEvents = require("../../service/statistics/Events");
var eventEmitter = new EventEmitter();
@ -26,7 +27,7 @@ function stopLocal() {
function stopRemote() {
if (rtpStats) {
rtpStats.stop();
eventEmitter.emit("statistics.stop");
eventEmitter.emit(StatisticsEvents.STOP);
rtpStats = null;
}
}
@ -66,37 +67,12 @@ var statistics = {
*/
LOCAL_JID: 'local',
addAudioLevelListener: function(listener)
{
eventEmitter.on("statistics.audioLevel", listener);
},
removeAudioLevelListener: function(listener)
{
eventEmitter.removeListener("statistics.audioLevel", listener);
},
addConnectionStatsListener: function(listener)
{
eventEmitter.on("statistics.connectionstats", listener);
addListener: function(type, listener) {
eventEmitter.on(type, listener);
},
removeConnectionStatsListener: function(listener)
{
eventEmitter.removeListener("statistics.connectionstats", listener);
removeListener: function (type, listener) {
eventEmitter.removeListener(type, listener);
},
addRemoteStatsStopListener: function(listener)
{
eventEmitter.on("statistics.stop", listener);
},
removeRemoteStatsStopListener: function(listener)
{
eventEmitter.removeListener("statistics.stop", listener);
},
stop: function () {
stopLocal();
stopRemote();
@ -105,12 +81,10 @@ var statistics = {
eventEmitter.removeAllListeners();
}
},
stopRemoteStatistics: function()
{
stopRemote();
},
start: function () {
APP.RTC.addStreamListener(onStreamCreated,
StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);

@ -0,0 +1,14 @@
module.exports = {
/**
* An event carrying connection statistics.
*/
CONNECTION_STATS: "statistics.connectionstats",
/**
* FIXME: needs documentation.
*/
AUDIO_LEVEL: "statistics.audioLevel",
/**
* FIXME: needs documentation.
*/
STOP: "statistics.stop"
};
Loading…
Cancel
Save