diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 2164e8e0d..5f22514f4 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.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; diff --git a/modules/connectionquality/connectionquality.js b/modules/connectionquality/connectionquality.js index 0ef0ff75b..4e2cb742f 100644 --- a/modules/connectionquality/connectionquality.js +++ b/modules/connectionquality/connectionquality.js @@ -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); }, /** diff --git a/modules/statistics/LocalStatsCollector.js b/modules/statistics/LocalStatsCollector.js index 7f30d9d70..a3df9ed26 100644 --- a/modules/statistics/LocalStatsCollector.js +++ b/modules/statistics/LocalStatsCollector.js @@ -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); } diff --git a/modules/statistics/RTPStatsCollector.js b/modules/statistics/RTPStatsCollector.js index e512ed7cd..0dbb6a737 100644 --- a/modules/statistics/RTPStatsCollector.js +++ b/modules/statistics/RTPStatsCollector.js @@ -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); + } } } }; diff --git a/modules/statistics/statistics.js b/modules/statistics/statistics.js index b33054092..5685cbd78 100644 --- a/modules/statistics/statistics.js +++ b/modules/statistics/statistics.js @@ -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); + addListener: function(type, listener) { + eventEmitter.on(type, listener); }, - - removeAudioLevelListener: function(listener) - { - eventEmitter.removeListener("statistics.audioLevel", listener); + removeListener: function (type, listener) { + eventEmitter.removeListener(type, listener); }, - - addConnectionStatsListener: function(listener) - { - eventEmitter.on("statistics.connectionstats", listener); - }, - - removeConnectionStatsListener: function(listener) - { - eventEmitter.removeListener("statistics.connectionstats", 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); diff --git a/service/statistics/Events.js b/service/statistics/Events.js new file mode 100644 index 000000000..261838262 --- /dev/null +++ b/service/statistics/Events.js @@ -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" +};