This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
unnamed-project/public/index.html

59 lines
1.8 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>Unnamed Project</title>
</head>
<body>
<p>Home of <span id="nodeID"></></p>
<iframe id="frame" src="" title="listing"></iframe>
<p>Who else is around? (refresh to see new nodes)</p>
<ul id="allnodes">
</ul>
</body>
<script>
// retrieve who we are
var request = new XMLHttpRequest();
var localData;
request.open("GET", "/api/config", true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
localData = JSON.parse(this.response);
var span = document.getElementById("nodeID");
span.textContent = localData.nodeID;
}
// retrieve who is around
var ul = document.getElementById("allnodes");
var request = new XMLHttpRequest();
request.open("GET", "/api/nodes", true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response);
for (var i = 0; i < data.length; i++) {
var a = document.createElement("a");
a.textContent = data[i].nodeID
a.setAttribute("href", "http://" + data[i].addr + ":5555");
var li = document.createElement("li");
li.appendChild(a)
ul.appendChild(li);
if (data[i].nodeID === localData.nodeID) {
var frame = document.getElementById("frame");
frame.setAttribute("src", "http://" + data[i].addr + ":1312");
}
}
}
};
request.send();
};
request.send();
</script>
</html>