Browse Source

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

module.
dev1
Boris Grozev 10 years ago
parent
commit
742a0bc6ac

+ 5
- 3
modules/connectionquality/connectionquality.js View File

@@ -3,6 +3,7 @@ var EventEmitter = require("events");
3 3
 var eventEmitter = new EventEmitter();
4 4
 var CQEvents = require("../../service/connectionquality/CQEvents");
5 5
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
6
+var StatisticsEvents = require("../../service/statistics/Events");
6 7
 
7 8
 /**
8 9
  * local stats
@@ -96,9 +97,10 @@ function parseMUCStats(stats) {
96 97
 var ConnectionQuality = {
97 98
     init: function () {
98 99
         APP.xmpp.addListener(XMPPEvents.REMOTE_STATS, this.updateRemoteStats);
99
-        APP.statistics.addConnectionStatsListener(this.updateLocalStats);
100
-        APP.statistics.addRemoteStatsStopListener(this.stopSendingStats);
101
-
100
+        APP.statistics.addListener(StatisticsEvents.CONNECTION_STATS,
101
+                                   this.updateLocalStats);
102
+        APP.statistics.addListener(StatisticsEvents.STOP,
103
+                                   this.stopSendingStats);
102 104
     },
103 105
 
104 106
     /**

+ 3
- 2
modules/statistics/LocalStatsCollector.js View File

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

+ 4
- 2
modules/statistics/RTPStatsCollector.js View File

@@ -3,6 +3,7 @@
3 3
 
4 4
 var logger = require("jitsi-meet-logger").getLogger(__filename);
5 5
 var RTCBrowserType = require("../RTC/RTCBrowserType");
6
+var StatisticsEvents = require("../../service/statistics/Events");
6 7
 
7 8
 /* Whether we support the browser we are running into for logging statistics */
8 9
 var browserSupported = RTCBrowserType.isChrome() ||
@@ -649,7 +650,7 @@ StatsCollector.prototype.processStatsReport = function () {
649 650
         upload:
650 651
             calculatePacketLoss(lostPackets.upload, totalPackets.upload)
651 652
     };
652
-    this.eventEmitter.emit("statistics.connectionstats",
653
+    this.eventEmitter.emit(StatisticsEvents.CONNECTION_STATS,
653 654
         {
654 655
             "bitrate": this.conferenceStats.bitrate,
655 656
             "packetLoss": this.conferenceStats.packetLoss,
@@ -715,7 +716,8 @@ StatsCollector.prototype.processAudioLevelReport = function () {
715 716
             // but it seems to vary between 0 and around 32k.
716 717
             audioLevel = audioLevel / 32767;
717 718
             ssrcStats.setSsrcAudioLevel(ssrc, audioLevel);
718
-            this.eventEmitter.emit("statistics.audioLevel", ssrc, audioLevel);
719
+            this.eventEmitter.emit(
720
+                StatisticsEvents.AUDIO_LEVEL, ssrc, audioLevel);
719 721
         }
720 722
     }
721 723
 };

+ 4
- 3
modules/statistics/statistics.js View File

@@ -2,6 +2,7 @@
2 2
 var LocalStats = require("./LocalStatsCollector.js");
3 3
 var RTPStats = require("./RTPStatsCollector.js");
4 4
 var EventEmitter = require("events");
5
+var StatisticsEvents = require("../../service/statistics/Events");
5 6
 //var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
6 7
 //var XMPPEvents = require("../../service/xmpp/XMPPEvents");
7 8
 //var CallStats = require("./CallStats");
@@ -43,12 +44,12 @@ Statistics.prototype.startLocalStats = function (stream) {
43 44
 
44 45
 Statistics.prototype.addAudioLevelListener = function(listener)
45 46
 {
46
-    this.eventEmitter.on("statistics.audioLevel", listener);
47
+    this.eventEmitter.on(StatisticsEvents.AUDIO_LEVEL, listener);
47 48
 }
48 49
 
49 50
 Statistics.prototype.removeAudioLevelListener = function(listener)
50 51
 {
51
-    this.eventEmitter.removeListener("statistics.audioLevel", listener);
52
+    this.eventEmitter.removeListener(StatisticsEvents.AUDIO_LEVEL, listener);
52 53
 }
53 54
 
54 55
 Statistics.prototype.dispose = function () {
@@ -71,7 +72,7 @@ Statistics.prototype.stopLocal = function () {
71 72
 Statistics.prototype.stopRemote = function () {
72 73
     if (this.rtpStats) {
73 74
         this.rtpStats.stop();
74
-        this.eventEmitter.emit("statistics.stop");
75
+        this.eventEmitter.emit(StatisticsEvents.STOP);
75 76
         this.rtpStats = null;
76 77
     }
77 78
 }

+ 14
- 0
service/statistics/Events.js View File

@@ -0,0 +1,14 @@
1
+module.exports = {
2
+    /**
3
+     * An event carrying connection statistics.
4
+     */
5
+    CONNECTION_STATS: "statistics.connectionstats",
6
+    /**
7
+     * FIXME: needs documentation.
8
+     */
9
+    AUDIO_LEVEL: "statistics.audioLevel",
10
+    /**
11
+     * FIXME: needs documentation.
12
+     */
13
+    STOP: "statistics.stop"
14
+};

Loading…
Cancel
Save