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

module.
This commit is contained in:
Boris Grozev 2015-09-15 15:34:16 -05:00
parent 68624b3427
commit c8f52d5fbd
5 changed files with 30 additions and 10 deletions

View File

@ -3,6 +3,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
@ -96,9 +97,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);
},
/**

View File

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

View File

@ -3,6 +3,7 @@
var logger = require("jitsi-meet-logger").getLogger(__filename);
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() ||
@ -649,7 +650,7 @@ StatsCollector.prototype.processStatsReport = function () {
upload:
calculatePacketLoss(lostPackets.upload, totalPackets.upload)
};
this.eventEmitter.emit("statistics.connectionstats",
this.eventEmitter.emit(StatisticsEvents.CONNECTION_STATS,
{
"bitrate": this.conferenceStats.bitrate,
"packetLoss": this.conferenceStats.packetLoss,
@ -715,7 +716,8 @@ StatsCollector.prototype.processAudioLevelReport = function () {
// but it seems to vary between 0 and around 32k.
audioLevel = audioLevel / 32767;
ssrcStats.setSsrcAudioLevel(ssrc, audioLevel);
this.eventEmitter.emit("statistics.audioLevel", ssrc, audioLevel);
this.eventEmitter.emit(
StatisticsEvents.AUDIO_LEVEL, ssrc, audioLevel);
}
}
};

View File

@ -2,6 +2,7 @@
var LocalStats = require("./LocalStatsCollector.js");
var RTPStats = require("./RTPStatsCollector.js");
var EventEmitter = require("events");
var StatisticsEvents = require("../../service/statistics/Events");
//var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
//var XMPPEvents = require("../../service/xmpp/XMPPEvents");
//var CallStats = require("./CallStats");
@ -43,12 +44,12 @@ Statistics.prototype.startLocalStats = function (stream) {
Statistics.prototype.addAudioLevelListener = function(listener)
{
this.eventEmitter.on("statistics.audioLevel", listener);
this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
}
Statistics.prototype.removeAudioLevelListener = function(listener)
{
this.eventEmitter.removeListener("statistics.audioLevel", listener);
this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
}
Statistics.prototype.dispose = function () {
@ -71,7 +72,7 @@ Statistics.prototype.stopLocal = function () {
Statistics.prototype.stopRemote = function () {
if (this.rtpStats) {
this.rtpStats.stop();
this.eventEmitter.emit("statistics.stop");
this.eventEmitter.emit(StatisticsEvents.STOP);
this.rtpStats = null;
}
}

View File

@ -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"
};