浏览代码

do not use xmpp in connectionquality module

master
isymchych 10 年前
父节点
当前提交
941cd13193
共有 3 个文件被更改,包括 68 次插入61 次删除
  1. 38
    0
      app.js
  2. 1
    5
      modules/UI/UI.js
  3. 29
    56
      modules/connectionquality/connectionquality.js

+ 38
- 0
app.js 查看文件

13
 require("jQuery-Impromptu");
13
 require("jQuery-Impromptu");
14
 require("autosize");
14
 require("autosize");
15
 
15
 
16
+var Commands = {
17
+    CONNECTION_QUALITY: "connectionQuality"
18
+};
19
+
16
 function createConference(connection, room) {
20
 function createConference(connection, room) {
17
     var localTracks = [];
21
     var localTracks = [];
18
     var remoteTracks = {};
22
     var remoteTracks = {};
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
     return new Promise(function (resolve, reject) {
267
     return new Promise(function (resolve, reject) {
230
         room.on(
268
         room.on(

+ 1
- 5
modules/UI/UI.js 查看文件

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

+ 29
- 56
modules/connectionquality/connectionquality.js 查看文件

3
 var EventEmitter = require("events");
3
 var EventEmitter = require("events");
4
 var eventEmitter = new EventEmitter();
4
 var eventEmitter = new EventEmitter();
5
 var CQEvents = require("../../service/connectionquality/CQEvents");
5
 var CQEvents = require("../../service/connectionquality/CQEvents");
6
-var XMPPEvents = require("../../service/xmpp/XMPPEvents");
7
 var StatisticsEvents = require("../../service/statistics/Events");
6
 var StatisticsEvents = require("../../service/statistics/Events");
8
 
7
 
9
 /**
8
 /**
18
  */
17
  */
19
 var remoteStats = {};
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
  * Converts statistics to format used by VideoLayout
21
  * Converts statistics to format used by VideoLayout
60
  * @param stats
22
  * @param stats
76
 
38
 
77
 var ConnectionQuality = {
39
 var ConnectionQuality = {
78
     init: function () {
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
     updateLocalStats: function (data) {
53
     updateLocalStats: function (data) {
91
         stats = data;
54
         stats = data;
92
         eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
55
         eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
93
-        if (!sendIntervalId) {
94
-            startSendingStats();
95
-        }
96
     },
56
     },
97
 
57
 
98
     /**
58
     /**
99
      * Updates remote statistics
59
      * Updates remote statistics
100
-     * @param jid the jid associated with the statistics
60
+     * @param id the id associated with the statistics
101
      * @param data the statistics
61
      * @param data the statistics
102
      */
62
      */
103
-    updateRemoteStats: function (jid, data) {
63
+    updateRemoteStats: function (id, data) {
104
         if (!data || !data.packetLoss_total) {
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
             return;
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
      * Stops statistics sending.
76
      * Stops statistics sending.
116
      */
77
      */
117
     stopSendingStats: function () {
78
     stopSendingStats: function () {
118
-        clearInterval(sendIntervalId);
119
-        sendIntervalId = null;
120
         //notify UI about stopping statistics gathering
79
         //notify UI about stopping statistics gathering
121
         eventEmitter.emit(CQEvents.STOP);
80
         eventEmitter.emit(CQEvents.STOP);
122
     },
81
     },
127
     getStats: function () {
86
     getStats: function () {
128
         return stats;
87
         return stats;
129
     },
88
     },
130
-    
89
+
131
     addListener: function (type, listener) {
90
     addListener: function (type, listener) {
132
         eventEmitter.on(type, listener);
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
 module.exports = ConnectionQuality;
110
 module.exports = ConnectionQuality;

正在加载...
取消
保存