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;
|
||||
|
||||
const Commands = {
|
||||
CONNECTION_QUALITY: "connectionQuality",
|
||||
CONNECTION_QUALITY: "stats",
|
||||
EMAIL: "email",
|
||||
VIDEO_TYPE: "videoType",
|
||||
ETHERPAD: "etherpad",
|
||||
|
@ -325,10 +325,10 @@ function initConference(localTracks, connection) {
|
|||
APP.UI.updateLocalStats(percent, stats);
|
||||
|
||||
// send local stats to other users
|
||||
room.sendCommand(Commands.CONNECTION_QUALITY, {
|
||||
value: APP.connectionquality.convertToMUCStats(stats),
|
||||
room.sendCommandOnce(Commands.CONNECTION_QUALITY, {
|
||||
children: APP.connectionquality.convertToMUCStats(stats),
|
||||
attributes: {
|
||||
id: room.myUserId()
|
||||
xmlns: 'http://jitsi.org/jitmeet/stats'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -340,8 +340,8 @@ function initConference(localTracks, connection) {
|
|||
// listen to remote stats
|
||||
room.addCommandListener(
|
||||
Commands.CONNECTION_QUALITY,
|
||||
function ({value, attributes}) {
|
||||
APP.connectionquality.updateRemoteStats(attributes.id, value);
|
||||
function (values, from) {
|
||||
APP.connectionquality.updateRemoteStats(from, values);
|
||||
}
|
||||
);
|
||||
APP.connectionquality.addListener(
|
||||
|
|
|
@ -23,15 +23,29 @@ var remoteStats = {};
|
|||
* @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
|
||||
*/
|
||||
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 {
|
||||
bitrate: {
|
||||
download: stats.bitrate_download,
|
||||
upload: stats.bitrate_upload
|
||||
download: extractedStats.bitrate_download,
|
||||
upload: extractedStats.bitrate_upload
|
||||
},
|
||||
packetLoss: {
|
||||
total: stats.packetLoss_total,
|
||||
download: stats.packetLoss_download,
|
||||
upload: stats.packetLoss_upload
|
||||
total: extractedStats.packetLoss_total,
|
||||
download: extractedStats.packetLoss_download,
|
||||
upload: extractedStats.packetLoss_upload
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -61,11 +75,12 @@ var ConnectionQuality = {
|
|||
* @param data the statistics
|
||||
*/
|
||||
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);
|
||||
return;
|
||||
}
|
||||
remoteStats[id] = parseMUCStats(data);
|
||||
remoteStats[id] = data;
|
||||
|
||||
eventEmitter.emit(
|
||||
CQEvents.REMOTESTATS_UPDATED, id, 100 - data.packetLoss_total, remoteStats[id]
|
||||
|
@ -94,17 +109,21 @@ var ConnectionQuality = {
|
|||
/**
|
||||
* Converts statistics to format for sending through XMPP
|
||||
* @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) {
|
||||
return {
|
||||
"bitrate_download": stats.bitrate.download,
|
||||
"bitrate_upload": stats.bitrate.upload,
|
||||
"packetLoss_total": stats.packetLoss.total,
|
||||
"packetLoss_download": stats.packetLoss.download,
|
||||
"packetLoss_upload": stats.packetLoss.upload
|
||||
};
|
||||
return [
|
||||
{tagName: "stat", attributes: {"bitrate_download": stats.bitrate.download}},
|
||||
{tagName: "stat", attributes: {"bitrate_upload": stats.bitrate.upload}},
|
||||
{tagName: "stat", attributes: {"packetLoss_total": stats.packetLoss.total}},
|
||||
{tagName: "stat", attributes: {"packetLoss_download": stats.packetLoss.download}},
|
||||
{tagName: "stat", attributes: {"packetLoss_upload": stats.packetLoss.upload}}
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = ConnectionQuality;
|
||||
module.exports = ConnectionQuality;
|
||||
|
|
Loading…
Reference in New Issue