mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-06-16 14:15:07 +03:00
Status bar status and speed RIVM-16 RIVM-17
This commit is contained in:
parent
b129d689a3
commit
1e7d51bac6
13 changed files with 64 additions and 11 deletions
4
contrib/ui/mesh-ui/ui/assets/all.min.css
vendored
4
contrib/ui/mesh-ui/ui/assets/all.min.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -55,8 +55,7 @@ table {
|
||||||
table-layout: fixed;
|
table-layout: fixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
thead tr th:first-child,
|
.big-flag {
|
||||||
tbody tr td:first-child {
|
|
||||||
width: 50px;
|
width: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,3 +85,8 @@ td.fi {
|
||||||
width: 2em;
|
width: 2em;
|
||||||
background-position: 0;
|
background-position: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#footer-row td {
|
||||||
|
padding: 10px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ function add_table(peerList) {
|
||||||
var row = document.createElement("tr");
|
var row = document.createElement("tr");
|
||||||
row.className = "is-hidden";
|
row.className = "is-hidden";
|
||||||
var imgElement = document.createElement("td");
|
var imgElement = document.createElement("td");
|
||||||
imgElement.className = "fi fi-" + ui.lookupCountryCodeByAddress(peer);
|
imgElement.className = "big-flag fi fi-" + ui.lookupCountryCodeByAddress(peer);
|
||||||
var peerAddress = document.createElement("td");
|
var peerAddress = document.createElement("td");
|
||||||
var cellText = document.createTextNode(peer);
|
var cellText = document.createTextNode(peer);
|
||||||
peerAddress.appendChild(cellText);
|
peerAddress.appendChild(cellText);
|
||||||
|
@ -224,6 +224,10 @@ function togglePrivKeyVisibility() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function humanReadableSpeed(speed) {
|
||||||
|
var i = speed == 0 ? 0 : Math.floor(Math.log(speed) / Math.log(1024));
|
||||||
|
return (speed / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['Bps', 'kBps', 'MBps', 'GBps', 'TBps'][i];
|
||||||
|
}
|
||||||
|
|
||||||
var ui = {
|
var ui = {
|
||||||
countries: []
|
countries: []
|
||||||
|
@ -279,10 +283,10 @@ ui.getConnectedPeers = () =>
|
||||||
fetch('api/peers')
|
fetch('api/peers')
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
|
|
||||||
|
const regexMulticast = /:\/\/\[fe80::/;
|
||||||
ui.updateConnectedPeersHandler = (peers) => {
|
ui.updateConnectedPeersHandler = (peers) => {
|
||||||
$("peers").innerText = "";
|
$("peers").innerText = "";
|
||||||
const regexStrip = /%[^\]]*/gm;
|
const regexStrip = /%[^\]]*/gm;
|
||||||
const regexMulticast = /:\/\/\[fe80::/;
|
|
||||||
const sorted = peers.map(peer => ({"url": peer["remote"], "isMulticast": peer["remote"].match(regexMulticast)}))
|
const sorted = peers.map(peer => ({"url": peer["remote"], "isMulticast": peer["remote"].match(regexMulticast)}))
|
||||||
.sort((a, b) => a.isMulticast > b.isMulticast);
|
.sort((a, b) => a.isMulticast > b.isMulticast);
|
||||||
sorted.forEach(peer => {
|
sorted.forEach(peer => {
|
||||||
|
@ -297,11 +301,47 @@ ui.updateConnectedPeersHandler = (peers) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui.updateStatus = peers => {
|
||||||
|
let status = "st-error";
|
||||||
|
if(peers) {
|
||||||
|
if(peers.length) {
|
||||||
|
const isNonMulticastExists = peers.filter(peer => !peer["remote"].match(regexMulticast)).length;
|
||||||
|
status = isNonMulticastExists ? "st-multicast" : "st-connected";
|
||||||
|
} else {
|
||||||
|
status = "st-connecting"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Array.from($$("status")).forEach(node => node.classList.add("is-hidden"));
|
||||||
|
$(status).classList.remove("is-hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.updateSpeed = peers => {
|
||||||
|
if(peers) {
|
||||||
|
let rsbytes = {"bytes_recvd": peers.reduce((acc, peer) => acc + peer.bytes_recvd, 0),
|
||||||
|
"bytes_sent": peers.reduce((acc, peer) => acc + peer.bytes_sent, 0),
|
||||||
|
"timestamp": Date.now()};
|
||||||
|
if("_rsbytes" in ui) {
|
||||||
|
$("dn_speed").innerText = humanReadableSpeed((rsbytes.bytes_recvd - ui._rsbytes.bytes_recvd) * 1000 / (rsbytes.timestamp - ui._rsbytes.timestamp));
|
||||||
|
$("up_speed").innerText = humanReadableSpeed((rsbytes.bytes_sent - ui._rsbytes.bytes_sent) * 1000 / (rsbytes.timestamp - ui._rsbytes.timestamp));
|
||||||
|
}
|
||||||
|
ui._rsbytes = rsbytes;
|
||||||
|
} else {
|
||||||
|
delete ui._rsbytes;
|
||||||
|
$("dn_speed").innerText = "? Bs";
|
||||||
|
$("up_speed").innerText = "? Bs";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ui.updateConnectedPeers = () =>
|
ui.updateConnectedPeers = () =>
|
||||||
ui.getConnectedPeers()
|
ui.getConnectedPeers()
|
||||||
.then(ui.updateConnectedPeersHandler)
|
.then(peers => {ui.updateConnectedPeersHandler(peers);
|
||||||
|
ui.updateStatus(peers);
|
||||||
|
ui.updateSpeed(peers);
|
||||||
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
$("peers").innerText = error.message;
|
$("peers").innerText = error.message;
|
||||||
|
ui.updateStatus();
|
||||||
|
ui.updateSpeed();
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.lookupCountryCodeByAddress = (address) => {
|
ui.lookupCountryCodeByAddress = (address) => {
|
||||||
|
|
|
@ -167,9 +167,18 @@
|
||||||
|
|
||||||
<footer class="is-flex-align-items-flex-end" style="margin-top: auto">
|
<footer class="is-flex-align-items-flex-end" style="margin-top: auto">
|
||||||
<hr style="margin: 0px;background-color: #5d656d;">
|
<hr style="margin: 0px;background-color: #5d656d;">
|
||||||
<div id="version" class="content has-text-left" style="padding: 10px;padding-left: 50px;">
|
<table class="content"><tr id="footer-row">
|
||||||
v123456
|
<td id="version" style="padding-left: 50px;">v123456</td>
|
||||||
</div>
|
<td style="width: 100%;"></td>
|
||||||
|
<td>↓ <span id="dn_speed">? Bps</span></td>
|
||||||
|
<td>↑ <span id="up_speed">? Bps</span></td>
|
||||||
|
<td id="status" style="padding-right: 20px;padding-left: 30px;">
|
||||||
|
<i id="st-connecting" class="status fas fa-solid fa-spinner fa-spin"></i>
|
||||||
|
<i id="st-connected" class="status fas fa-solid fa-circle-nodes is-hidden"></i>
|
||||||
|
<i id="st-multicast" class="status fas fa-solid fa-circle-check is-hidden"></i>
|
||||||
|
<i id="st-error" class="status fas fa-solid fa-circle-exclamation is-hidden"></i>
|
||||||
|
</td>
|
||||||
|
</tr></table>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-brands-400.ttf
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-brands-400.ttf
Normal file
Binary file not shown.
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-brands-400.woff2
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-brands-400.woff2
Normal file
Binary file not shown.
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-regular-400.ttf
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-regular-400.ttf
Normal file
Binary file not shown.
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-regular-400.woff2
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-regular-400.woff2
Normal file
Binary file not shown.
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-solid-900.ttf
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-solid-900.ttf
Normal file
Binary file not shown.
Binary file not shown.
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-v4compatibility.ttf
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-v4compatibility.ttf
Normal file
Binary file not shown.
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-v4compatibility.woff2
Normal file
BIN
contrib/ui/mesh-ui/ui/webfonts/fa-v4compatibility.woff2
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue