Browse Source

working initial prototype

master
decentral1se 7 months ago
parent
commit
3f9083f49d
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 42
      public/index.html
  2. 8
      unnamed-project.go

42
public/index.html

@ -7,16 +7,52 @@
<title>Unnamed Project</title>
</head>
<body>
<p>Hello, World!</p>
<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();
request.open('GET', '/api/config', true);
var localData;
request.open("GET", "/api/config", true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response);
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>

8
unnamed-project.go

@ -219,7 +219,7 @@ func parseAnnouncePacket(size int, addr *net.UDPAddr, packet []byte) (*nodeInfo,
err := json.Unmarshal([]byte(payload), nodeInfo)
nodeInfo.Addr = addr.IP.String()
nodeInfo.NodeID = fmt.Sprintf("%s-%s", nodeInfo.NodeID, nodeInfo.Addr)
nodeInfo.NodeID = fmt.Sprintf("%s", nodeInfo.NodeID)
if err != nil {
return nil, err
}
@ -335,11 +335,7 @@ func dashboardServe(conf *config, nodeList *list.List) {
dashboardMux.HandleFunc("/api/config", configHandler(conf))
dashboardMux.HandleFunc("/api/nodes", nodesHandler(nodeList))
// We don't want the dashboard to be public
address := "localhost"
if conf.Debug {
address = "0.0.0.0"
}
address := "0.0.0.0"
fmt.Printf("Starting dashboard at %s:%v\n", address, conf.FilePort)
err := http.ListenAndServe(fmt.Sprintf("%s:%v", address, conf.FilePort), dashboardMux)

Loading…
Cancel
Save