Просмотр исходного кода

Revert "Changes the connection quality stats to be sent by the data channels"

master
bgrozev 9 лет назад
Родитель
Сommit
1f8dc54368
2 измененных файлов: 72 добавлений и 19 удалений
  1. 18
    18
      conference.js
  2. 54
    1
      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
-
1137
-        ConnectionQuality.addListener(CQEvents.LOCALSTATS_UPDATED,
1136
+        ConnectionQuality.addListener(
1137
+            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
-            });
1145 1140
 
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
-            });
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
+        });
1157 1157
 
1158 1158
         ConnectionQuality.addListener(CQEvents.REMOTESTATS_UPDATED,
1159 1159
             (id, percent, stats) => {

+ 54
- 1
modules/connectionquality/connectionquality.js Просмотреть файл

@@ -28,6 +28,39 @@ 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
+
31 64
 /**
32 65
  * Calculates the quality percent based on passed new and old value.
33 66
  * @param newVal the new value
@@ -57,7 +90,8 @@ export default {
57 90
      * @param data the statistics
58 91
      */
59 92
     updateRemoteStats: function (id, data) {
60
-        if (!data || !("packetLoss" in data) || !("total" in data.packetLoss)) {
93
+        data = parseMUCStats(data);
94
+        if (!data || !data.packetLoss || !data.packetLoss.total) {
61 95
             eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
62 96
             return;
63 97
         }
@@ -81,5 +115,24 @@ export default {
81 115
 
82 116
     addListener: function (type, listener) {
83 117
         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
+        ];
84 137
     }
85 138
 };

Загрузка…
Отмена
Сохранить