浏览代码

Merge pull request #746 from jitsi/dc_stats2

Changes the connection quality stats to be sent by the data channels
j8
bgrozev 9 年前
父节点
当前提交
ae0e950c16
共有 2 个文件被更改,包括 18 次插入72 次删除
  1. 17
    18
      conference.js
  2. 1
    54
      modules/connectionquality/connectionquality.js

+ 17
- 18
conference.js 查看文件

1133
         room.on(ConferenceEvents.CONNECTION_STATS, function (stats) {
1133
         room.on(ConferenceEvents.CONNECTION_STATS, function (stats) {
1134
             ConnectionQuality.updateLocalStats(stats);
1134
             ConnectionQuality.updateLocalStats(stats);
1135
         });
1135
         });
1136
-        ConnectionQuality.addListener(
1137
-            CQEvents.LOCALSTATS_UPDATED,
1136
+
1137
+        ConnectionQuality.addListener(CQEvents.LOCALSTATS_UPDATED,
1138
             (percent, stats) => {
1138
             (percent, stats) => {
1139
                 APP.UI.updateLocalStats(percent, stats);
1139
                 APP.UI.updateLocalStats(percent, stats);
1140
+                room.broadcastEndpointMessage({
1141
+                    type: this.commands.defaults.CONNECTION_QUALITY,
1142
+                    values: stats });
1143
+            });
1140
 
1144
 
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
-        });
1145
+        room.on(ConferenceEvents.ENDPOINT_MESSAGE_RECEIVED,
1146
+            (participant, payload) => {
1147
+                switch(payload.type) {
1148
+                    case this.commands.defaults.CONNECTION_QUALITY:
1149
+                        ConnectionQuality.updateRemoteStats(participant.getId(),
1150
+                            payload.values);
1151
+                        break;
1152
+                    default:
1153
+                        console.warn("Unknown datachannel message", payload);
1154
+                }
1155
+            });
1157
 
1156
 
1158
         ConnectionQuality.addListener(CQEvents.REMOTESTATS_UPDATED,
1157
         ConnectionQuality.addListener(CQEvents.REMOTESTATS_UPDATED,
1159
             (id, percent, stats) => {
1158
             (id, percent, stats) => {

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

28
  */
28
  */
29
 var remoteConnectionQuality = {};
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
  * Calculates the quality percent based on passed new and old value.
32
  * Calculates the quality percent based on passed new and old value.
66
  * @param newVal the new value
33
  * @param newVal the new value
90
      * @param data the statistics
57
      * @param data the statistics
91
      */
58
      */
92
     updateRemoteStats: function (id, data) {
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
             eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
61
             eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
96
             return;
62
             return;
97
         }
63
         }
115
 
81
 
116
     addListener: function (type, listener) {
82
     addListener: function (type, listener) {
117
         eventEmitter.on(type, listener);
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
 };

正在加载...
取消
保存