浏览代码

Fixes the format of the data in connection quality module

master
hristoterezov 9 年前
父节点
当前提交
a56d462dae
共有 2 个文件被更改,包括 41 次插入22 次删除
  1. 6
    6
      app.js
  2. 35
    16
      modules/connectionquality/connectionquality.js

+ 6
- 6
app.js 查看文件

@@ -37,7 +37,7 @@ const ConferenceErrors = JitsiMeetJS.errors.conference;
37 37
 let localVideo, localAudio;
38 38
 
39 39
 const Commands = {
40
-    CONNECTION_QUALITY: "connectionQuality",
40
+    CONNECTION_QUALITY: "stats",
41 41
     EMAIL: "email",
42 42
     VIDEO_TYPE: "videoType",
43 43
     ETHERPAD: "etherpad",
@@ -325,10 +325,10 @@ function initConference(localTracks, connection) {
325 325
             APP.UI.updateLocalStats(percent, stats);
326 326
 
327 327
             // send local stats to other users
328
-            room.sendCommand(Commands.CONNECTION_QUALITY, {
329
-                value: APP.connectionquality.convertToMUCStats(stats),
328
+            room.sendCommandOnce(Commands.CONNECTION_QUALITY, {
329
+                children: APP.connectionquality.convertToMUCStats(stats),
330 330
                 attributes: {
331
-                    id: room.myUserId()
331
+                    xmlns: 'http://jitsi.org/jitmeet/stats'
332 332
                 }
333 333
             });
334 334
         }
@@ -340,8 +340,8 @@ function initConference(localTracks, connection) {
340 340
     // listen to remote stats
341 341
     room.addCommandListener(
342 342
         Commands.CONNECTION_QUALITY,
343
-        function ({value, attributes}) {
344
-            APP.connectionquality.updateRemoteStats(attributes.id, value);
343
+        function (values, from) {
344
+            APP.connectionquality.updateRemoteStats(from, values);
345 345
         }
346 346
     );
347 347
     APP.connectionquality.addListener(

+ 35
- 16
modules/connectionquality/connectionquality.js 查看文件

@@ -23,15 +23,29 @@ var remoteStats = {};
23 23
  * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
24 24
  */
25 25
 function parseMUCStats(stats) {
26
+    if(!stats || !stats.children || !stats.children.length)
27
+        return null;
28
+    var children = stats.children;
29
+    var extractedStats = {};
30
+    children.forEach((child) => {
31
+        if(child.tagName !== "stat" || !child.attributes)
32
+            return;
33
+        var attrKeys = Object.keys(child.attributes);
34
+        if(!attrKeys || !attrKeys.length)
35
+            return;
36
+        attrKeys.forEach((attr) => {
37
+            extractedStats[attr] = child.attributes[attr];
38
+        });
39
+    });
26 40
     return {
27 41
         bitrate: {
28
-            download: stats.bitrate_download,
29
-            upload: stats.bitrate_upload
42
+            download: extractedStats.bitrate_download,
43
+            upload: extractedStats.bitrate_upload
30 44
         },
31 45
         packetLoss: {
32
-            total: stats.packetLoss_total,
33
-            download: stats.packetLoss_download,
34
-            upload: stats.packetLoss_upload
46
+            total: extractedStats.packetLoss_total,
47
+            download: extractedStats.packetLoss_download,
48
+            upload: extractedStats.packetLoss_upload
35 49
         }
36 50
     };
37 51
 }
@@ -61,11 +75,12 @@ var ConnectionQuality = {
61 75
      * @param data the statistics
62 76
      */
63 77
     updateRemoteStats: function (id, data) {
64
-        if (!data || !data.packetLoss_total) {
78
+        data = parseMUCStats(data);
79
+        if (!data || !data.packetLoss || !data.packetLoss.total) {
65 80
             eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
66 81
             return;
67 82
         }
68
-        remoteStats[id] = parseMUCStats(data);
83
+        remoteStats[id] = data;
69 84
 
70 85
         eventEmitter.emit(
71 86
             CQEvents.REMOTESTATS_UPDATED, id, 100 - data.packetLoss_total, remoteStats[id]
@@ -94,17 +109,21 @@ var ConnectionQuality = {
94 109
     /**
95 110
      * Converts statistics to format for sending through XMPP
96 111
      * @param stats the statistics
97
-     * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
112
+     * @returns [{tagName: "stat", attributes: {{bitrate_donwload: *}},
113
+     * {tagName: "stat", attributes: {{ bitrate_uplpoad: *}},
114
+     * {tagName: "stat", attributes: {{ packetLoss_total: *}},
115
+     * {tagName: "stat", attributes: {{ packetLoss_download: *}},
116
+     * {tagName: "stat", attributes: {{ packetLoss_upload: *}}]
98 117
      */
99 118
     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
-        };
119
+        return [
120
+            {tagName: "stat", attributes: {"bitrate_download": stats.bitrate.download}},
121
+            {tagName: "stat", attributes: {"bitrate_upload": stats.bitrate.upload}},
122
+            {tagName: "stat", attributes: {"packetLoss_total": stats.packetLoss.total}},
123
+            {tagName: "stat", attributes: {"packetLoss_download": stats.packetLoss.download}},
124
+            {tagName: "stat", attributes: {"packetLoss_upload": stats.packetLoss.upload}}
125
+        ];
107 126
     }
108 127
 };
109 128
 
110
-module.exports = ConnectionQuality;
129
+module.exports = ConnectionQuality;

正在加载...
取消
保存