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