122 lines
3.6 KiB
JavaScript
122 lines
3.6 KiB
JavaScript
|
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.connectionquality=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||
|
/**
|
||
|
* local stats
|
||
|
* @type {{}}
|
||
|
*/
|
||
|
var stats = {};
|
||
|
|
||
|
/**
|
||
|
* remote stats
|
||
|
* @type {{}}
|
||
|
*/
|
||
|
var remoteStats = {};
|
||
|
|
||
|
/**
|
||
|
* Interval for sending statistics to other participants
|
||
|
* @type {null}
|
||
|
*/
|
||
|
var sendIntervalId = null;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Start statistics sending.
|
||
|
*/
|
||
|
function startSendingStats() {
|
||
|
sendStats();
|
||
|
sendIntervalId = setInterval(sendStats, 10000);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Sends statistics to other participants
|
||
|
*/
|
||
|
function sendStats() {
|
||
|
connection.emuc.addConnectionInfoToPresence(convertToMUCStats(stats));
|
||
|
connection.emuc.sendPresence();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts statistics to format for sending through XMPP
|
||
|
* @param stats the statistics
|
||
|
* @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
|
||
|
*/
|
||
|
function convertToMUCStats(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
|
||
|
};
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Converts statitistics to format used by VideoLayout
|
||
|
* @param stats
|
||
|
* @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
|
||
|
*/
|
||
|
function parseMUCStats(stats) {
|
||
|
return {
|
||
|
bitrate: {
|
||
|
download: stats.bitrate_download,
|
||
|
upload: stats.bitrate_upload
|
||
|
},
|
||
|
packetLoss: {
|
||
|
total: stats.packetLoss_total,
|
||
|
download: stats.packetLoss_download,
|
||
|
upload: stats.packetLoss_upload
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
|
||
|
var ConnectionQuality = {
|
||
|
/**
|
||
|
* Updates the local statistics
|
||
|
* @param data new statistics
|
||
|
*/
|
||
|
updateLocalStats: function (data) {
|
||
|
stats = data;
|
||
|
UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
|
||
|
if (sendIntervalId == null) {
|
||
|
startSendingStats();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Updates remote statistics
|
||
|
* @param jid the jid associated with the statistics
|
||
|
* @param data the statistics
|
||
|
*/
|
||
|
updateRemoteStats: function (jid, data) {
|
||
|
if (data == null || data.packetLoss_total == null) {
|
||
|
UI.updateConnectionStats(jid, null, null);
|
||
|
return;
|
||
|
}
|
||
|
remoteStats[jid] = parseMUCStats(data);
|
||
|
|
||
|
UI.updateConnectionStats(jid, 100 - data.packetLoss_total, remoteStats[jid]);
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Stops statistics sending.
|
||
|
*/
|
||
|
stopSendingStats: function () {
|
||
|
clearInterval(sendIntervalId);
|
||
|
sendIntervalId = null;
|
||
|
//notify UI about stopping statistics gathering
|
||
|
UI.onStatsStop();
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* Returns the local statistics.
|
||
|
*/
|
||
|
getStats: function () {
|
||
|
return stats;
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
module.exports = ConnectionQuality;
|
||
|
},{}]},{},[1])(1)
|
||
|
});
|