2015-07-28 21:52:32 +00:00
|
|
|
/* global APP, $ */
|
2015-09-11 02:42:15 +00:00
|
|
|
/* jshint -W101 */
|
2015-12-14 12:26:50 +00:00
|
|
|
import JitsiPopover from "../util/JitsiPopover";
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs new connection indicator.
|
|
|
|
* @param videoContainer the video container associated with the indicator.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2015-12-14 12:26:50 +00:00
|
|
|
function ConnectionIndicator(videoContainer, id) {
|
2015-01-07 14:54:03 +00:00
|
|
|
this.videoContainer = videoContainer;
|
|
|
|
this.bandwidth = null;
|
|
|
|
this.packetLoss = null;
|
|
|
|
this.bitrate = null;
|
|
|
|
this.showMoreValue = false;
|
|
|
|
this.resolution = null;
|
|
|
|
this.transport = [];
|
|
|
|
this.popover = null;
|
2015-12-14 12:26:50 +00:00
|
|
|
this.id = id;
|
2015-01-07 14:54:03 +00:00
|
|
|
this.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Values for the connection quality
|
|
|
|
* @type {{98: string,
|
|
|
|
* 81: string,
|
|
|
|
* 64: string,
|
|
|
|
* 47: string,
|
|
|
|
* 30: string,
|
|
|
|
* 0: string}}
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.connectionQualityValues = {
|
|
|
|
98: "18px", //full
|
|
|
|
81: "15px",//4 bars
|
|
|
|
64: "11px",//3 bars
|
|
|
|
47: "7px",//2 bars
|
|
|
|
30: "3px",//1 bar
|
|
|
|
0: "0px"//empty
|
|
|
|
};
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
ConnectionIndicator.getIP = function(value) {
|
2015-01-07 14:54:03 +00:00
|
|
|
return value.substring(0, value.lastIndexOf(":"));
|
|
|
|
};
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
ConnectionIndicator.getPort = function(value) {
|
2015-01-07 14:54:03 +00:00
|
|
|
return value.substring(value.lastIndexOf(":") + 1, value.length);
|
|
|
|
};
|
|
|
|
|
|
|
|
ConnectionIndicator.getStringFromArray = function (array) {
|
|
|
|
var res = "";
|
2015-07-28 21:52:32 +00:00
|
|
|
for(var i = 0; i < array.length; i++) {
|
2015-01-07 14:54:03 +00:00
|
|
|
res += (i === 0? "" : ", ") + array[i];
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates the html content.
|
|
|
|
* @returns {string} the html content.
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.generateText = function () {
|
2016-01-29 15:33:16 +00:00
|
|
|
var downloadBitrate, uploadBitrate, packetLoss, i;
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-02-06 15:46:50 +00:00
|
|
|
var translate = APP.translation.translateString;
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if(this.bitrate === null) {
|
2015-01-07 14:54:03 +00:00
|
|
|
downloadBitrate = "N/A";
|
|
|
|
uploadBitrate = "N/A";
|
|
|
|
}
|
2015-07-28 21:52:32 +00:00
|
|
|
else {
|
2015-01-07 14:54:03 +00:00
|
|
|
downloadBitrate =
|
|
|
|
this.bitrate.download? this.bitrate.download + " Kbps" : "N/A";
|
|
|
|
uploadBitrate =
|
|
|
|
this.bitrate.upload? this.bitrate.upload + " Kbps" : "N/A";
|
|
|
|
}
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if(this.packetLoss === null) {
|
2015-01-07 14:54:03 +00:00
|
|
|
packetLoss = "N/A";
|
2015-07-28 21:52:32 +00:00
|
|
|
} else {
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
packetLoss = "<span class='jitsipopover_green'>↓</span>" +
|
2015-07-28 21:52:32 +00:00
|
|
|
(this.packetLoss.download !== null ?
|
|
|
|
this.packetLoss.download : "N/A") +
|
2015-01-07 14:54:03 +00:00
|
|
|
"% <span class='jitsipopover_orange'>↑</span>" +
|
2015-07-28 21:52:32 +00:00
|
|
|
(this.packetLoss.upload !== null? this.packetLoss.upload : "N/A") +
|
|
|
|
"%";
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
|
2016-01-29 15:33:16 +00:00
|
|
|
// GENERATE RESOLUTIONS STRING
|
|
|
|
let resolutions = this.resolution || {};
|
|
|
|
let resolutionStr = Object.keys(resolutions).map(function (ssrc) {
|
|
|
|
let {width, height} = resolutions[ssrc];
|
|
|
|
return `${width}x${height}`;
|
|
|
|
}).join(', ') || 'N/A';
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
var result = "<table style='width:100%'>" +
|
|
|
|
"<tr>" +
|
2015-02-06 15:46:50 +00:00
|
|
|
"<td><span class='jitsipopover_blue' data-i18n='connectionindicator.bitrate'>" +
|
|
|
|
translate("connectionindicator.bitrate") + "</span></td>" +
|
2015-01-07 14:54:03 +00:00
|
|
|
"<td><span class='jitsipopover_green'>↓</span>" +
|
|
|
|
downloadBitrate + " <span class='jitsipopover_orange'>↑</span>" +
|
|
|
|
uploadBitrate + "</td>" +
|
|
|
|
"</tr><tr>" +
|
2015-02-06 15:46:50 +00:00
|
|
|
"<td><span class='jitsipopover_blue' data-i18n='connectionindicator.packetloss'>" +
|
|
|
|
translate("connectionindicator.packetloss") + "</span></td>" +
|
2015-01-07 14:54:03 +00:00
|
|
|
"<td>" + packetLoss + "</td>" +
|
|
|
|
"</tr><tr>" +
|
2015-02-06 15:46:50 +00:00
|
|
|
"<td><span class='jitsipopover_blue' data-i18n='connectionindicator.resolution'>" +
|
|
|
|
translate("connectionindicator.resolution") + "</span></td>" +
|
2016-01-29 15:33:16 +00:00
|
|
|
"<td>" + resolutionStr + "</td></tr></table>";
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-06-23 08:00:46 +00:00
|
|
|
if(this.videoContainer.videoSpanId == "localVideoContainer") {
|
2015-01-07 14:54:03 +00:00
|
|
|
result += "<div class=\"jitsipopover_showmore\" " +
|
2015-01-28 14:35:22 +00:00
|
|
|
"onclick = \"APP.UI.connectionIndicatorShowMore('" +
|
2015-12-14 12:26:50 +00:00
|
|
|
// FIXME: we do not know local id when this text is generated
|
|
|
|
//this.id + "')\" data-i18n='connectionindicator." +
|
2015-07-20 17:32:04 +00:00
|
|
|
"local')\" data-i18n='connectionindicator." +
|
2015-02-06 15:46:50 +00:00
|
|
|
(this.showMoreValue ? "less" : "more") + "'>" +
|
|
|
|
translate("connectionindicator." + (this.showMoreValue ? "less" : "more")) +
|
|
|
|
"</div><br />";
|
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if (this.showMoreValue) {
|
2015-01-07 14:54:03 +00:00
|
|
|
var downloadBandwidth, uploadBandwidth, transport;
|
2015-07-28 21:52:32 +00:00
|
|
|
if (this.bandwidth === null) {
|
2015-01-07 14:54:03 +00:00
|
|
|
downloadBandwidth = "N/A";
|
|
|
|
uploadBandwidth = "N/A";
|
2015-07-28 21:52:32 +00:00
|
|
|
} else {
|
2015-01-07 14:54:03 +00:00
|
|
|
downloadBandwidth = this.bandwidth.download?
|
|
|
|
this.bandwidth.download + " Kbps" :
|
|
|
|
"N/A";
|
|
|
|
uploadBandwidth = this.bandwidth.upload?
|
|
|
|
this.bandwidth.upload + " Kbps" :
|
|
|
|
"N/A";
|
|
|
|
}
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if (!this.transport || this.transport.length === 0) {
|
2015-01-07 14:54:03 +00:00
|
|
|
transport = "<tr>" +
|
2015-02-06 15:46:50 +00:00
|
|
|
"<td><span class='jitsipopover_blue' " +
|
|
|
|
"data-i18n='connectionindicator.address'>" +
|
|
|
|
translate("connectionindicator.address") + "</span></td>" +
|
2015-01-07 14:54:03 +00:00
|
|
|
"<td> N/A</td></tr>";
|
2015-07-28 21:52:32 +00:00
|
|
|
} else {
|
2015-01-07 14:54:03 +00:00
|
|
|
var data = {remoteIP: [], localIP:[], remotePort:[], localPort:[]};
|
2015-07-28 21:52:32 +00:00
|
|
|
for(i = 0; i < this.transport.length; i++) {
|
2015-01-07 14:54:03 +00:00
|
|
|
var ip = ConnectionIndicator.getIP(this.transport[i].ip);
|
|
|
|
var port = ConnectionIndicator.getPort(this.transport[i].ip);
|
|
|
|
var localIP =
|
|
|
|
ConnectionIndicator.getIP(this.transport[i].localip);
|
|
|
|
var localPort =
|
|
|
|
ConnectionIndicator.getPort(this.transport[i].localip);
|
2015-07-28 21:52:32 +00:00
|
|
|
if(data.remoteIP.indexOf(ip) == -1) {
|
2015-01-07 14:54:03 +00:00
|
|
|
data.remoteIP.push(ip);
|
|
|
|
}
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if(data.remotePort.indexOf(port) == -1) {
|
2015-01-07 14:54:03 +00:00
|
|
|
data.remotePort.push(port);
|
|
|
|
}
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if(data.localIP.indexOf(localIP) == -1) {
|
2015-01-07 14:54:03 +00:00
|
|
|
data.localIP.push(localIP);
|
|
|
|
}
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if(data.localPort.indexOf(localPort) == -1) {
|
2015-01-07 14:54:03 +00:00
|
|
|
data.localPort.push(localPort);
|
|
|
|
}
|
|
|
|
}
|
2015-02-06 15:46:50 +00:00
|
|
|
|
2015-02-27 17:58:05 +00:00
|
|
|
var local_address_key = "connectionindicator.localaddress";
|
|
|
|
var remote_address_key = "connectionindicator.remoteaddress";
|
2015-01-07 14:54:03 +00:00
|
|
|
var localTransport =
|
2015-02-06 15:46:50 +00:00
|
|
|
"<tr><td><span class='jitsipopover_blue' data-i18n='" +
|
2015-02-27 17:58:05 +00:00
|
|
|
local_address_key +"' data-i18n-options='" +
|
|
|
|
JSON.stringify({count: data.localIP.length}) + "'>" +
|
|
|
|
translate(local_address_key, {count: data.localIP.length}) +
|
|
|
|
"</span></td><td> " +
|
2015-01-07 14:54:03 +00:00
|
|
|
ConnectionIndicator.getStringFromArray(data.localIP) +
|
|
|
|
"</td></tr>";
|
|
|
|
transport =
|
2015-02-06 15:46:50 +00:00
|
|
|
"<tr><td><span class='jitsipopover_blue' data-i18n='" +
|
2015-02-27 17:58:05 +00:00
|
|
|
remote_address_key + "' data-i18n-options='" +
|
|
|
|
JSON.stringify({count: data.remoteIP.length}) + "'>" +
|
|
|
|
translate(remote_address_key,
|
|
|
|
{count: data.remoteIP.length}) +
|
|
|
|
"</span></td><td> " +
|
2015-01-07 14:54:03 +00:00
|
|
|
ConnectionIndicator.getStringFromArray(data.remoteIP) +
|
|
|
|
"</td></tr>";
|
2015-02-06 15:46:50 +00:00
|
|
|
|
2015-02-27 17:58:05 +00:00
|
|
|
var key_remote = "connectionindicator.remoteport",
|
|
|
|
key_local = "connectionindicator.localport";
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-02-06 15:46:50 +00:00
|
|
|
transport += "<tr>" +
|
|
|
|
"<td>" +
|
|
|
|
"<span class='jitsipopover_blue' data-i18n='" + key_remote +
|
2015-02-27 17:58:05 +00:00
|
|
|
"' data-i18n-options='" +
|
|
|
|
JSON.stringify({count: this.transport.length}) + "'>" +
|
|
|
|
translate(key_remote, {count: this.transport.length}) +
|
|
|
|
"</span></td><td>";
|
2015-02-06 15:46:50 +00:00
|
|
|
localTransport += "<tr>" +
|
|
|
|
"<td>" +
|
|
|
|
"<span class='jitsipopover_blue' data-i18n='" + key_local +
|
2015-02-27 17:58:05 +00:00
|
|
|
"' data-i18n-options='" +
|
|
|
|
JSON.stringify({count: this.transport.length}) + "'>" +
|
|
|
|
translate(key_local, {count: this.transport.length}) +
|
|
|
|
"</span></td><td>";
|
2015-02-06 15:46:50 +00:00
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
transport +=
|
|
|
|
ConnectionIndicator.getStringFromArray(data.remotePort);
|
|
|
|
localTransport +=
|
|
|
|
ConnectionIndicator.getStringFromArray(data.localPort);
|
|
|
|
transport += "</td></tr>";
|
|
|
|
transport += localTransport + "</td></tr>";
|
|
|
|
transport +="<tr>" +
|
2015-02-06 15:46:50 +00:00
|
|
|
"<td><span class='jitsipopover_blue' data-i18n='connectionindicator.transport'>" +
|
|
|
|
translate("connectionindicator.transport") + "</span></td>" +
|
2015-01-07 14:54:03 +00:00
|
|
|
"<td>" + this.transport[0].type + "</td></tr>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
result += "<table style='width:100%'>" +
|
|
|
|
"<tr>" +
|
|
|
|
"<td>" +
|
2015-02-06 15:46:50 +00:00
|
|
|
"<span class='jitsipopover_blue' data-i18n='connectionindicator.bandwidth'>" +
|
|
|
|
translate("connectionindicator.bandwidth") + "</span>" +
|
2015-01-07 14:54:03 +00:00
|
|
|
"</td><td>" +
|
|
|
|
"<span class='jitsipopover_green'>↓</span>" +
|
|
|
|
downloadBandwidth +
|
|
|
|
" <span class='jitsipopover_orange'>↑</span>" +
|
|
|
|
uploadBandwidth + "</td></tr>";
|
|
|
|
|
|
|
|
result += transport + "</table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows or hide the additional information.
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.showMore = function () {
|
|
|
|
this.showMoreValue = !this.showMoreValue;
|
|
|
|
this.updatePopoverData();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
function createIcon(classes) {
|
2015-01-07 14:54:03 +00:00
|
|
|
var icon = document.createElement("span");
|
2015-07-28 21:52:32 +00:00
|
|
|
for(var i in classes) {
|
2015-01-07 14:54:03 +00:00
|
|
|
icon.classList.add(classes[i]);
|
|
|
|
}
|
|
|
|
icon.appendChild(
|
|
|
|
document.createElement("i")).classList.add("icon-connection");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the indicator
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.create = function () {
|
|
|
|
this.connectionIndicatorContainer = document.createElement("div");
|
|
|
|
this.connectionIndicatorContainer.className = "connectionindicator";
|
|
|
|
this.connectionIndicatorContainer.style.display = "none";
|
2015-07-28 21:52:32 +00:00
|
|
|
this.videoContainer.container.appendChild(
|
|
|
|
this.connectionIndicatorContainer);
|
2015-01-07 14:54:03 +00:00
|
|
|
this.popover = new JitsiPopover(
|
2015-06-23 08:00:46 +00:00
|
|
|
$("#" + this.videoContainer.videoSpanId + " > .connectionindicator"),
|
2015-02-06 15:46:50 +00:00
|
|
|
{content: "<div class=\"connection_info\" data-i18n='connectionindicator.na'>" +
|
|
|
|
APP.translation.translateString("connectionindicator.na") + "</div>",
|
2015-01-07 14:54:03 +00:00
|
|
|
skin: "black"});
|
|
|
|
|
|
|
|
this.emptyIcon = this.connectionIndicatorContainer.appendChild(
|
|
|
|
createIcon(["connection", "connection_empty"]));
|
|
|
|
this.fullIcon = this.connectionIndicatorContainer.appendChild(
|
|
|
|
createIcon(["connection", "connection_full"]));
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the indicator
|
|
|
|
*/
|
2015-07-28 21:52:32 +00:00
|
|
|
ConnectionIndicator.prototype.remove = function() {
|
2015-07-10 09:57:20 +00:00
|
|
|
if (this.connectionIndicatorContainer.parentNode) {
|
|
|
|
this.connectionIndicatorContainer.parentNode.removeChild(
|
|
|
|
this.connectionIndicatorContainer);
|
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
this.popover.forceHide();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the data of the indicator
|
|
|
|
* @param percent the percent of connection quality
|
|
|
|
* @param object the statistics data.
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.updateConnectionQuality =
|
2015-07-28 21:52:32 +00:00
|
|
|
function (percent, object) {
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-07-28 21:52:32 +00:00
|
|
|
if (percent === null) {
|
2015-01-07 14:54:03 +00:00
|
|
|
this.connectionIndicatorContainer.style.display = "none";
|
|
|
|
this.popover.forceHide();
|
|
|
|
return;
|
2015-07-28 21:52:32 +00:00
|
|
|
} else {
|
2015-01-07 14:54:03 +00:00
|
|
|
if(this.connectionIndicatorContainer.style.display == "none") {
|
|
|
|
this.connectionIndicatorContainer.style.display = "block";
|
2015-06-23 08:00:46 +00:00
|
|
|
this.videoContainer.updateIconPositions();
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.bandwidth = object.bandwidth;
|
|
|
|
this.bitrate = object.bitrate;
|
|
|
|
this.packetLoss = object.packetLoss;
|
|
|
|
this.transport = object.transport;
|
2015-07-28 21:52:32 +00:00
|
|
|
if (object.resolution) {
|
2015-01-07 14:54:03 +00:00
|
|
|
this.resolution = object.resolution;
|
|
|
|
}
|
2015-07-28 21:52:32 +00:00
|
|
|
for (var quality in ConnectionIndicator.connectionQualityValues) {
|
|
|
|
if (percent >= quality) {
|
2015-01-07 14:54:03 +00:00
|
|
|
this.fullIcon.style.width =
|
|
|
|
ConnectionIndicator.connectionQualityValues[quality];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.updatePopoverData();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the resolution
|
|
|
|
* @param resolution the new resolution
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.updateResolution = function (resolution) {
|
|
|
|
this.resolution = resolution;
|
|
|
|
this.updatePopoverData();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the content of the popover
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.updatePopoverData = function () {
|
|
|
|
this.popover.updateContent(
|
2015-12-14 15:40:30 +00:00
|
|
|
`<div class="connection_info">${this.generateText()}</div>`
|
|
|
|
);
|
2015-02-06 15:46:50 +00:00
|
|
|
APP.translation.translateElement($(".connection_info"));
|
2015-01-07 14:54:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the popover
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.hide = function () {
|
|
|
|
this.popover.forceHide();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the indicator
|
|
|
|
*/
|
|
|
|
ConnectionIndicator.prototype.hideIndicator = function () {
|
|
|
|
this.connectionIndicatorContainer.style.display = "none";
|
|
|
|
if(this.popover)
|
|
|
|
this.popover.forceHide();
|
|
|
|
};
|
|
|
|
|
2015-12-14 12:26:50 +00:00
|
|
|
export default ConnectionIndicator;
|