Kaynağa Gözat

do not use xmpp in connectionquality module

master
isymchych 10 yıl önce
ebeveyn
işleme
941cd13193
3 değiştirilmiş dosya ile 68 ekleme ve 61 silme
  1. 38
    0
      app.js
  2. 1
    5
      modules/UI/UI.js
  3. 29
    56
      modules/connectionquality/connectionquality.js

+ 38
- 0
app.js Dosyayı Görüntüle

@@ -13,6 +13,10 @@ window.toastr = require("toastr");
13 13
 require("jQuery-Impromptu");
14 14
 require("autosize");
15 15
 
16
+var Commands = {
17
+    CONNECTION_QUALITY: "connectionQuality"
18
+};
19
+
16 20
 function createConference(connection, room) {
17 21
     var localTracks = [];
18 22
     var remoteTracks = {};
@@ -225,6 +229,40 @@ function initConference(connection, roomName) {
225 229
         }
226 230
     );
227 231
 
232
+    APP.connectionquality.addListener(
233
+        CQEvents.LOCALSTATS_UPDATED,
234
+        function (percent, stats) {
235
+            APP.UI.updateLocalStats(percent, stats);
236
+
237
+            // send local stats to other users
238
+            room.sendCommand(Commands.CONNECTION_QUALITY, {
239
+                value: APP.connectionquality.convertToMUCStats(stats),
240
+                attributes: {
241
+                    id: room.myUserId()
242
+                }
243
+            });
244
+        }
245
+    );
246
+
247
+    APP.connectionquality.addListener(
248
+        CQEvents.STOP,
249
+        function () {
250
+            APP.UI.hideStats();
251
+            room.removeCommand(Commands.CONNECTION_QUALITY);
252
+        }
253
+    );
254
+
255
+    // listen to remote stats
256
+    room.addCommandListener(Commands.CONNECTION_QUALITY, function (data) {
257
+        APP.connectionquality.updateRemoteStats(data.attributes.id, data.value);
258
+    });
259
+
260
+    APP.connectionquality.addListener(
261
+        CQEvents.REMOTESTATS_UPDATED,
262
+        function (id, percent, stats) {
263
+            APP.UI.updateRemoteStats(id, percent, stats);
264
+        }
265
+    );
228 266
 
229 267
     return new Promise(function (resolve, reject) {
230 268
         room.on(

+ 1
- 5
modules/UI/UI.js Dosyayı Görüntüle

@@ -233,9 +233,7 @@ UI.start = function () {
233 233
             // FIXME integrate logs
234 234
         });
235 235
         Feedback.init();
236
-    }
237
-    else
238
-    {
236
+    } else {
239 237
         $("#header").css("display", "none");
240 238
         $("#bottomToolbar").css("display", "none");
241 239
         $("#downloadlog").css("display", "none");
@@ -243,7 +241,6 @@ UI.start = function () {
243 241
         $("#remoteVideos").css("right", "0px");
244 242
         messageHandler.disableNotifications();
245 243
         $('body').popover("disable");
246
-//        $("[data-toggle=popover]").popover("disable");
247 244
         JitsiPopover.enabled = false;
248 245
     }
249 246
 
@@ -279,7 +276,6 @@ UI.start = function () {
279 276
             "newestOnTop": false
280 277
         };
281 278
 
282
-
283 279
         SettingsMenu.init();
284 280
     }
285 281
 

+ 29
- 56
modules/connectionquality/connectionquality.js Dosyayı Görüntüle

@@ -3,7 +3,6 @@
3 3
 var EventEmitter = require("events");
4 4
 var eventEmitter = new EventEmitter();
5 5
 var CQEvents = require("../../service/connectionquality/CQEvents");
6
-var XMPPEvents = require("../../service/xmpp/XMPPEvents");
7 6
 var StatisticsEvents = require("../../service/statistics/Events");
8 7
 
9 8
 /**
@@ -18,43 +17,6 @@ var stats = {};
18 17
  */
19 18
 var remoteStats = {};
20 19
 
21
-/**
22
- * Interval for sending statistics to other participants
23
- * @type {null}
24
- */
25
-var sendIntervalId = null;
26
-
27
-
28
-/**
29
- * Start statistics sending.
30
- */
31
-function startSendingStats() {
32
-    sendStats();
33
-    sendIntervalId = setInterval(sendStats, 10000);
34
-}
35
-
36
-/**
37
- * Sends statistics to other participants
38
- */
39
-function sendStats() {
40
-    APP.xmpp.addToPresence("connectionQuality", convertToMUCStats(stats));
41
-}
42
-
43
-/**
44
- * Converts statistics to format for sending through XMPP
45
- * @param stats the statistics
46
- * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
47
- */
48
-function convertToMUCStats(stats) {
49
-    return {
50
-        "bitrate_download": stats.bitrate.download,
51
-        "bitrate_upload": stats.bitrate.upload,
52
-        "packetLoss_total": stats.packetLoss.total,
53
-        "packetLoss_download": stats.packetLoss.download,
54
-        "packetLoss_upload": stats.packetLoss.upload
55
-    };
56
-}
57
-
58 20
 /**
59 21
  * Converts statistics to format used by VideoLayout
60 22
  * @param stats
@@ -76,11 +38,12 @@ function parseMUCStats(stats) {
76 38
 
77 39
 var ConnectionQuality = {
78 40
     init: function () {
79
-        APP.xmpp.addListener(XMPPEvents.REMOTE_STATS, this.updateRemoteStats);
80
-        APP.statistics.addListener(StatisticsEvents.CONNECTION_STATS,
81
-                                   this.updateLocalStats);
82
-        APP.statistics.addListener(StatisticsEvents.STOP,
83
-                                   this.stopSendingStats);
41
+        APP.statistics.addListener(
42
+            StatisticsEvents.CONNECTION_STATS, this.updateLocalStats
43
+        );
44
+        APP.statistics.addListener(
45
+            StatisticsEvents.STOP, this.stopSendingStats
46
+        );
84 47
     },
85 48
 
86 49
     /**
@@ -90,33 +53,29 @@ var ConnectionQuality = {
90 53
     updateLocalStats: function (data) {
91 54
         stats = data;
92 55
         eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
93
-        if (!sendIntervalId) {
94
-            startSendingStats();
95
-        }
96 56
     },
97 57
 
98 58
     /**
99 59
      * Updates remote statistics
100
-     * @param jid the jid associated with the statistics
60
+     * @param id the id associated with the statistics
101 61
      * @param data the statistics
102 62
      */
103
-    updateRemoteStats: function (jid, data) {
63
+    updateRemoteStats: function (id, data) {
104 64
         if (!data || !data.packetLoss_total) {
105
-            eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, jid, null, null);
65
+            eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
106 66
             return;
107 67
         }
108
-        remoteStats[jid] = parseMUCStats(data);
68
+        remoteStats[id] = parseMUCStats(data);
109 69
 
110
-        eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED,
111
-            jid, 100 - data.packetLoss_total, remoteStats[jid]);
70
+        eventEmitter.emit(
71
+            CQEvents.REMOTESTATS_UPDATED, id, 100 - data.packetLoss_total, remoteStats[id]
72
+        );
112 73
     },
113 74
 
114 75
     /**
115 76
      * Stops statistics sending.
116 77
      */
117 78
     stopSendingStats: function () {
118
-        clearInterval(sendIntervalId);
119
-        sendIntervalId = null;
120 79
         //notify UI about stopping statistics gathering
121 80
         eventEmitter.emit(CQEvents.STOP);
122 81
     },
@@ -127,11 +86,25 @@ var ConnectionQuality = {
127 86
     getStats: function () {
128 87
         return stats;
129 88
     },
130
-    
89
+
131 90
     addListener: function (type, listener) {
132 91
         eventEmitter.on(type, listener);
133
-    }
92
+    },
134 93
 
94
+    /**
95
+     * Converts statistics to format for sending through XMPP
96
+     * @param stats the statistics
97
+     * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
98
+     */
99
+    convertToMUCStats: function (stats) {
100
+        return {
101
+            "bitrate_download": stats.bitrate.download,
102
+            "bitrate_upload": stats.bitrate.upload,
103
+            "packetLoss_total": stats.packetLoss.total,
104
+            "packetLoss_download": stats.packetLoss.download,
105
+            "packetLoss_upload": stats.packetLoss.upload
106
+        };
107
+    }
135 108
 };
136 109
 
137 110
 module.exports = ConnectionQuality;

Loading…
İptal
Kaydet