Browse Source

Merge branch 'websocket-ui'

famtool
Jeff Becker 8 years ago
parent
commit
189fabc2cc
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 33
      websocket-ui/index.html
  2. 33
      websocket-ui/ui.js

33
websocket-ui/index.html

@ -3,11 +3,36 @@
<title> websocket events </title> <title> websocket events </title>
<script type="text/javascript" src="leftpad.js"> <script type="text/javascript" src="leftpad.js">
</script> </script>
<style>
pre#log {
z-index: 1;
color: white;
position: fixed;
right: 0px;
top: 0px;
height: 100%;
font-size: 10px;
box-shadow: 0px 0px 10px 10px #1a1a1a;
background: rgba(1,1,1,0.5);
border-radius: 5px;
}
body, canvas#main {
background: #222;
}
canvas#main {
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}
</style>
</head> </head>
<body style="background: #222;"> <body>
<pre id="log" style="z-index: 1; color: white; position: fixed; right: 0px; top: 0px; font-size: 10px;"> <pre id="log"></pre>
</pre> <canvas id="main">
<canvas id="main" style="background: #222; position: fixed; left: 0px; top: 0px; z-index: -1">
</canvas> </canvas>
<script type="text/javascript" src="ui.js"> <script type="text/javascript" src="ui.js">
</script> </script>

33
websocket-ui/ui.js

@ -1,4 +1,4 @@
var url = "ws://127.0.0.1:7666"; var url = "ws://127.0.0.1:7665";
var l = document.getElementById("log"); var l = document.getElementById("log");
var c = document.getElementById("main"); var c = document.getElementById("main");
@ -96,8 +96,8 @@ function tunnelTestFailed(tid) {
function tunnelFailed(tid) { function tunnelFailed(tid) {
if(!tunnels[tid]) return; if(!tunnels[tid]) return;
logit("Tunnel " + tid + " has failed"); logit("Tunnel " + tid + " has failed");
tunnels[tid].state = "failed"; delete tunnels[tid];
tunnels[tid].color = "red"; tunnels.length--;
} }
function tunnelExpiring(tid) { function tunnelExpiring(tid) {
@ -130,7 +130,7 @@ function tunnelCreated(tid) {
function logit(msg) { function logit(msg) {
console.log(msg); console.log(msg);
var t = document.createTextNode(msg); var t = document.createTextNode(leftpad(msg, 25));
var e = document.createElement("div"); var e = document.createElement("div");
e.appendChild(t); e.appendChild(t);
l.appendChild(e); l.appendChild(e);
@ -243,9 +243,12 @@ setInterval(function() {
} }
for ( var h in tpeers ) { for ( var h in tpeers ) {
if( h == "length") continue;
drawPeer(getPeer(h)); drawPeer(getPeer(h));
} }
var newPeers = {};
var counter = 0;
for ( var ed in e ) { for ( var ed in e ) {
var edge = e[ed]; var edge = e[ed];
draw.beginPath(); draw.beginPath();
@ -253,9 +256,20 @@ setInterval(function() {
draw.lineWidth = edge[3]; draw.lineWidth = edge[3];
draw.moveTo(edge[0].x * c.width, edge[0].y * c.height); draw.moveTo(edge[0].x * c.width, edge[0].y * c.height);
draw.lineTo(edge[1].x * c.width, edge[1].y * c.height); draw.lineTo(edge[1].x * c.width, edge[1].y * c.height);
draw.stroke(); if(!newPeers[edge[0].name]) {
newPeers[edge[0].name] = edge[0];
counter ++;
}
if(!newPeers[edge[1].name]) {
newPeers[edge[1].name] = edge[1];
counter ++;
}
draw.stroke();
} }
newPeers.length = counter;
tpeers = newPeers;
// draw nodes // draw nodes
@ -312,10 +326,11 @@ setInterval(function() {
draw.beginPath(); draw.beginPath();
var txt = ident.substr(0, 6); var txt = ident.substr(0, 6);
draw.fillText(txt, x1-5, y1-5); draw.fillText(txt, x1-5, y1-5);
/**
if(i * 10 < c.height) { if(i * 10 < c.height) {
txt += "| "+leftpad(nodes[ident].recv+" msg/s in", 15)+ " | "+leftpad(nodes[ident].send+" msg/s out", 15)+" |"; txt += "| "+leftpad(nodes[ident].recv+" msg/s in", 15)+ " | "+leftpad(nodes[ident].send+" msg/s out", 15)+" |";
draw.fillText(txt, 100, 20 + (i*10)); draw.fillText(txt, 100, 20 + (i*10));
} } */
nodes[ident].recv = 0; nodes[ident].recv = 0;
nodes[ident].send = 0; nodes[ident].send = 0;
draw.moveTo(x0, y0); draw.moveTo(x0, y0);
@ -362,3 +377,5 @@ setInterval(function() {
} }
tick ++; tick ++;
}, 100); }, 100);
logit("loaded");

Loading…
Cancel
Save