瀏覽代碼

Merge pull request #741 from jitsi/dc_stats

Changes the connection quality stats to be sent by the data channels
master
Дамян Минков 9 年之前
父節點
當前提交
60f7b9ab93
共有 2 個檔案被更改,包括 19 行新增72 行删除
  1. 18
    18
      conference.js
  2. 1
    54
      modules/connectionquality/connectionquality.js

+ 18
- 18
conference.js 查看文件

@@ -1133,27 +1133,27 @@ export default {
1133 1133
         room.on(ConferenceEvents.CONNECTION_STATS, function (stats) {
1134 1134
             ConnectionQuality.updateLocalStats(stats);
1135 1135
         });
1136
-        ConnectionQuality.addListener(
1137
-            CQEvents.LOCALSTATS_UPDATED,
1136
+
1137
+        ConnectionQuality.addListener(CQEvents.LOCALSTATS_UPDATED,
1138 1138
             (percent, stats) => {
1139 1139
                 APP.UI.updateLocalStats(percent, stats);
1140
+                room.sendDataChannelBroadcast({
1141
+                    type: this.commands.defaults.CONNECTION_QUALITY,
1142
+                    from: room.myUserId(),
1143
+                    values: stats });
1144
+            });
1140 1145
 
1141
-                // send local stats to other users
1142
-                room.sendCommandOnce(this.commands.defaults.CONNECTION_QUALITY,
1143
-                {
1144
-                    children: ConnectionQuality.convertToMUCStats(stats),
1145
-                    attributes: {
1146
-                        xmlns: 'http://jitsi.org/jitmeet/stats'
1147
-                    }
1148
-                });
1149
-            }
1150
-        );
1151
-
1152
-        // listen to remote stats
1153
-        room.addCommandListener(this.commands.defaults.CONNECTION_QUALITY,
1154
-            (values, from) => {
1155
-                ConnectionQuality.updateRemoteStats(from, values);
1156
-        });
1146
+        room.on(ConferenceEvents.DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED,
1147
+            (payload) => {
1148
+                switch(payload.type) {
1149
+                    case this.commands.defaults.CONNECTION_QUALITY:
1150
+                        ConnectionQuality.updateRemoteStats(payload.from,
1151
+                            payload.values);
1152
+                        break;
1153
+                    default:
1154
+                        console.warn("Unknown datachannel message", payload);
1155
+                }
1156
+            });
1157 1157
 
1158 1158
         ConnectionQuality.addListener(CQEvents.REMOTESTATS_UPDATED,
1159 1159
             (id, percent, stats) => {

+ 1
- 54
modules/connectionquality/connectionquality.js 查看文件

@@ -28,39 +28,6 @@ var localConnectionQuality = 100;
28 28
  */
29 29
 var remoteConnectionQuality = {};
30 30
 
31
-/**
32
- * Converts statistics to format used by VideoLayout
33
- * @param stats
34
- * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
35
- */
36
-function parseMUCStats(stats) {
37
-    if(!stats || !stats.children || !stats.children.length)
38
-        return null;
39
-    var children = stats.children;
40
-    var extractedStats = {};
41
-    children.forEach((child) => {
42
-        if(child.tagName !== "stat" || !child.attributes)
43
-            return;
44
-        var attrKeys = Object.keys(child.attributes);
45
-        if(!attrKeys || !attrKeys.length)
46
-            return;
47
-        attrKeys.forEach((attr) => {
48
-            extractedStats[attr] = child.attributes[attr];
49
-        });
50
-    });
51
-    return {
52
-        bitrate: {
53
-            download: extractedStats.bitrate_download,
54
-            upload: extractedStats.bitrate_upload
55
-        },
56
-        packetLoss: {
57
-            total: extractedStats.packetLoss_total,
58
-            download: extractedStats.packetLoss_download,
59
-            upload: extractedStats.packetLoss_upload
60
-        }
61
-    };
62
-}
63
-
64 31
 /**
65 32
  * Calculates the quality percent based on passed new and old value.
66 33
  * @param newVal the new value
@@ -90,8 +57,7 @@ export default {
90 57
      * @param data the statistics
91 58
      */
92 59
     updateRemoteStats: function (id, data) {
93
-        data = parseMUCStats(data);
94
-        if (!data || !data.packetLoss || !data.packetLoss.total) {
60
+        if (!data || !("packetLoss" in data) || !("total" in data.packetLoss)) {
95 61
             eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
96 62
             return;
97 63
         }
@@ -115,24 +81,5 @@ export default {
115 81
 
116 82
     addListener: function (type, listener) {
117 83
         eventEmitter.on(type, listener);
118
-    },
119
-
120
-    /**
121
-     * Converts statistics to format for sending through XMPP
122
-     * @param stats the statistics
123
-     * @returns [{tagName: "stat", attributes: {{bitrate_donwload: *}},
124
-     * {tagName: "stat", attributes: {{ bitrate_uplpoad: *}},
125
-     * {tagName: "stat", attributes: {{ packetLoss_total: *}},
126
-     * {tagName: "stat", attributes: {{ packetLoss_download: *}},
127
-     * {tagName: "stat", attributes: {{ packetLoss_upload: *}}]
128
-     */
129
-    convertToMUCStats: function (stats) {
130
-        return [
131
-            {tagName: "stat", attributes: {"bitrate_download": stats.bitrate.download}},
132
-            {tagName: "stat", attributes: {"bitrate_upload": stats.bitrate.upload}},
133
-            {tagName: "stat", attributes: {"packetLoss_total": stats.packetLoss.total}},
134
-            {tagName: "stat", attributes: {"packetLoss_download": stats.packetLoss.download}},
135
-            {tagName: "stat", attributes: {"packetLoss_upload": stats.packetLoss.upload}}
136
-        ];
137 84
     }
138 85
 };

Loading…
取消
儲存