mirror of
https://github.com/PurpleI2P/i2pd-tools.git
synced 2025-01-22 13:27:17 +01:00
Merge branch 'websocket-ui'
This commit is contained in:
commit
9ab415da9d
|
@ -31,6 +31,10 @@
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="login-wrapper">
|
||||
<input id="ws-url" value="ws://127.0.0.1:7666"></input>
|
||||
<button id="connect-button" onclick="startui()">connect</button>
|
||||
</div>
|
||||
<pre id="log"></pre>
|
||||
<canvas id="main">
|
||||
</canvas>
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
var url = "ws://127.0.0.1:7665";
|
||||
|
||||
var l = document.getElementById("log");
|
||||
var c = document.getElementById("main");
|
||||
var nodes = {
|
||||
|
@ -119,18 +117,16 @@ function tunnelState(tid, state) {
|
|||
tunnelFailed(tid);
|
||||
} else if (state == "6" ) {
|
||||
tunnelExpiring(tid);
|
||||
} else {
|
||||
logit("tunnel "+tid+" state "+state);
|
||||
}
|
||||
}
|
||||
|
||||
function tunnelCreated(tid) {
|
||||
logit("tunnel "+tid+" was created");
|
||||
logit("Tunnel "+tid+" was created");
|
||||
}
|
||||
|
||||
function logit(msg) {
|
||||
console.log(msg);
|
||||
var t = document.createTextNode(leftpad(msg, 25));
|
||||
var t = document.createTextNode(msg);
|
||||
var e = document.createElement("div");
|
||||
e.appendChild(t);
|
||||
l.appendChild(e);
|
||||
|
@ -138,38 +134,66 @@ function logit(msg) {
|
|||
l.removeChild(l.children[0]);
|
||||
}
|
||||
|
||||
var ws = new WebSocket(url);
|
||||
ws.onclose = function (ev) {
|
||||
nodes = { length: 0 };
|
||||
tpeers = { length: 0 };
|
||||
function socketClosed() {
|
||||
var b = document.getElementById("connect-button");
|
||||
b.onclick = startui
|
||||
b.innerHTML = "connect";
|
||||
}
|
||||
ws.onmessage = function(ev) {
|
||||
var j = JSON.parse(ev.data);
|
||||
if (j) {
|
||||
console.log(j);
|
||||
if(j.type == "transport.connected") {
|
||||
nodeConnected(j.ident);
|
||||
} else if (j.type == "transport.disconnected") {
|
||||
nodeDisconnected(j.ident);
|
||||
} else if (j.type == "transport.sendmsg") {
|
||||
nodeSend(j.ident, j.number);
|
||||
} else if (j.type == "transport.recvmsg") {
|
||||
nodeRecv(j.ident, j.number);
|
||||
} else if (j.type == "tunnel.build") {
|
||||
tunnelBuild(j.value, j.tid, j.inbound);
|
||||
} else if (j.type == "tunnel.latency") {
|
||||
tunnelLatency(j.tid, j.value);
|
||||
} else if (j.type == "tunnel.state") {
|
||||
tunnelState(j.tid, j.value);
|
||||
} else if (j.type == "tunnels.created") {
|
||||
tunnelCreated(j.tid);
|
||||
} else if (j.type == "tunnels.expired") {
|
||||
tunnelExpiring(j.tid);
|
||||
} else {
|
||||
logit("message: "+j.type);
|
||||
}
|
||||
|
||||
function startui() {
|
||||
var el = document.getElementById("ws-url");
|
||||
var url;
|
||||
if(el)
|
||||
url = el.value;
|
||||
else
|
||||
url = "ws://127.0.0.1:7666";
|
||||
|
||||
var ws = new WebSocket(url);
|
||||
ws.onclose = function (ev) {
|
||||
if (ev.code == 1000)
|
||||
logit("connection closed");
|
||||
else
|
||||
logit("failed to connect to "+url);
|
||||
nodes = { length: 0 };
|
||||
tpeers = { length: 0 };
|
||||
socketClosed();
|
||||
}
|
||||
};
|
||||
ws.onopen = function(ev) {
|
||||
logit("connected to "+url);
|
||||
var b = document.getElementById("connect-button");
|
||||
b.onclick = function() {
|
||||
ws.close();
|
||||
}
|
||||
b.innerHTML = "disconnect";
|
||||
}
|
||||
ws.onmessage = function(ev) {
|
||||
var j = JSON.parse(ev.data);
|
||||
if (j) {
|
||||
console.log(j);
|
||||
if(j.type == "transport.connected") {
|
||||
nodeConnected(j.ident);
|
||||
} else if (j.type == "transport.disconnected") {
|
||||
nodeDisconnected(j.ident);
|
||||
} else if (j.type == "transport.sendmsg") {
|
||||
nodeSend(j.ident, j.number);
|
||||
} else if (j.type == "transport.recvmsg") {
|
||||
nodeRecv(j.ident, j.number);
|
||||
} else if (j.type == "tunnel.build") {
|
||||
tunnelBuild(j.value, j.tid, j.inbound);
|
||||
} else if (j.type == "tunnel.latency") {
|
||||
tunnelLatency(j.tid, j.value);
|
||||
} else if (j.type == "tunnel.state") {
|
||||
tunnelState(j.tid, j.value);
|
||||
} else if (j.type == "tunnels.created") {
|
||||
tunnelCreated(j.tid);
|
||||
} else if (j.type == "tunnels.expired") {
|
||||
tunnelExpiring(j.tid);
|
||||
} else {
|
||||
logit("message: "+j.type);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getPeer(h, us) {
|
||||
if (tpeers[h]) {
|
||||
|
|
Loading…
Reference in a new issue