Fixes the format of the data in connection quality module
This commit is contained in:
parent
54f2364f18
commit
a56d462dae
12
app.js
12
app.js
|
@ -37,7 +37,7 @@ const ConferenceErrors = JitsiMeetJS.errors.conference;
|
||||||
let localVideo, localAudio;
|
let localVideo, localAudio;
|
||||||
|
|
||||||
const Commands = {
|
const Commands = {
|
||||||
CONNECTION_QUALITY: "connectionQuality",
|
CONNECTION_QUALITY: "stats",
|
||||||
EMAIL: "email",
|
EMAIL: "email",
|
||||||
VIDEO_TYPE: "videoType",
|
VIDEO_TYPE: "videoType",
|
||||||
ETHERPAD: "etherpad",
|
ETHERPAD: "etherpad",
|
||||||
|
@ -325,10 +325,10 @@ function initConference(localTracks, connection) {
|
||||||
APP.UI.updateLocalStats(percent, stats);
|
APP.UI.updateLocalStats(percent, stats);
|
||||||
|
|
||||||
// send local stats to other users
|
// send local stats to other users
|
||||||
room.sendCommand(Commands.CONNECTION_QUALITY, {
|
room.sendCommandOnce(Commands.CONNECTION_QUALITY, {
|
||||||
value: APP.connectionquality.convertToMUCStats(stats),
|
children: APP.connectionquality.convertToMUCStats(stats),
|
||||||
attributes: {
|
attributes: {
|
||||||
id: room.myUserId()
|
xmlns: 'http://jitsi.org/jitmeet/stats'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -340,8 +340,8 @@ function initConference(localTracks, connection) {
|
||||||
// listen to remote stats
|
// listen to remote stats
|
||||||
room.addCommandListener(
|
room.addCommandListener(
|
||||||
Commands.CONNECTION_QUALITY,
|
Commands.CONNECTION_QUALITY,
|
||||||
function ({value, attributes}) {
|
function (values, from) {
|
||||||
APP.connectionquality.updateRemoteStats(attributes.id, value);
|
APP.connectionquality.updateRemoteStats(from, values);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
APP.connectionquality.addListener(
|
APP.connectionquality.addListener(
|
||||||
|
|
|
@ -23,15 +23,29 @@ var remoteStats = {};
|
||||||
* @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
|
* @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
|
||||||
*/
|
*/
|
||||||
function parseMUCStats(stats) {
|
function parseMUCStats(stats) {
|
||||||
|
if(!stats || !stats.children || !stats.children.length)
|
||||||
|
return null;
|
||||||
|
var children = stats.children;
|
||||||
|
var extractedStats = {};
|
||||||
|
children.forEach((child) => {
|
||||||
|
if(child.tagName !== "stat" || !child.attributes)
|
||||||
|
return;
|
||||||
|
var attrKeys = Object.keys(child.attributes);
|
||||||
|
if(!attrKeys || !attrKeys.length)
|
||||||
|
return;
|
||||||
|
attrKeys.forEach((attr) => {
|
||||||
|
extractedStats[attr] = child.attributes[attr];
|
||||||
|
});
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
bitrate: {
|
bitrate: {
|
||||||
download: stats.bitrate_download,
|
download: extractedStats.bitrate_download,
|
||||||
upload: stats.bitrate_upload
|
upload: extractedStats.bitrate_upload
|
||||||
},
|
},
|
||||||
packetLoss: {
|
packetLoss: {
|
||||||
total: stats.packetLoss_total,
|
total: extractedStats.packetLoss_total,
|
||||||
download: stats.packetLoss_download,
|
download: extractedStats.packetLoss_download,
|
||||||
upload: stats.packetLoss_upload
|
upload: extractedStats.packetLoss_upload
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -61,11 +75,12 @@ var ConnectionQuality = {
|
||||||
* @param data the statistics
|
* @param data the statistics
|
||||||
*/
|
*/
|
||||||
updateRemoteStats: function (id, data) {
|
updateRemoteStats: function (id, data) {
|
||||||
if (!data || !data.packetLoss_total) {
|
data = parseMUCStats(data);
|
||||||
|
if (!data || !data.packetLoss || !data.packetLoss.total) {
|
||||||
eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
|
eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, id, null, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
remoteStats[id] = parseMUCStats(data);
|
remoteStats[id] = data;
|
||||||
|
|
||||||
eventEmitter.emit(
|
eventEmitter.emit(
|
||||||
CQEvents.REMOTESTATS_UPDATED, id, 100 - data.packetLoss_total, remoteStats[id]
|
CQEvents.REMOTESTATS_UPDATED, id, 100 - data.packetLoss_total, remoteStats[id]
|
||||||
|
@ -94,17 +109,21 @@ var ConnectionQuality = {
|
||||||
/**
|
/**
|
||||||
* Converts statistics to format for sending through XMPP
|
* Converts statistics to format for sending through XMPP
|
||||||
* @param stats the statistics
|
* @param stats the statistics
|
||||||
* @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
|
* @returns [{tagName: "stat", attributes: {{bitrate_donwload: *}},
|
||||||
|
* {tagName: "stat", attributes: {{ bitrate_uplpoad: *}},
|
||||||
|
* {tagName: "stat", attributes: {{ packetLoss_total: *}},
|
||||||
|
* {tagName: "stat", attributes: {{ packetLoss_download: *}},
|
||||||
|
* {tagName: "stat", attributes: {{ packetLoss_upload: *}}]
|
||||||
*/
|
*/
|
||||||
convertToMUCStats: function (stats) {
|
convertToMUCStats: function (stats) {
|
||||||
return {
|
return [
|
||||||
"bitrate_download": stats.bitrate.download,
|
{tagName: "stat", attributes: {"bitrate_download": stats.bitrate.download}},
|
||||||
"bitrate_upload": stats.bitrate.upload,
|
{tagName: "stat", attributes: {"bitrate_upload": stats.bitrate.upload}},
|
||||||
"packetLoss_total": stats.packetLoss.total,
|
{tagName: "stat", attributes: {"packetLoss_total": stats.packetLoss.total}},
|
||||||
"packetLoss_download": stats.packetLoss.download,
|
{tagName: "stat", attributes: {"packetLoss_download": stats.packetLoss.download}},
|
||||||
"packetLoss_upload": stats.packetLoss.upload
|
{tagName: "stat", attributes: {"packetLoss_upload": stats.packetLoss.upload}}
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ConnectionQuality;
|
module.exports = ConnectionQuality;
|
||||||
|
|
Loading…
Reference in New Issue