|
@@ -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;
|