mirror of
https://github.com/PurpleI2P/i2pd-tools.git
synced 2025-03-22 00:59:09 +01:00
add connector dialog for websocket ui
This commit is contained in:
parent
58d94f2549
commit
0105ad59d8
2 changed files with 60 additions and 33 deletions
|
@ -31,6 +31,10 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
<pre id="log"></pre>
|
||||||
<canvas id="main">
|
<canvas id="main">
|
||||||
</canvas>
|
</canvas>
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
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");
|
||||||
var nodes = {
|
var nodes = {
|
||||||
|
@ -130,7 +128,7 @@ function tunnelCreated(tid) {
|
||||||
|
|
||||||
function logit(msg) {
|
function logit(msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
var t = document.createTextNode(leftpad(msg, 25));
|
var t = document.createTextNode(msg);
|
||||||
var e = document.createElement("div");
|
var e = document.createElement("div");
|
||||||
e.appendChild(t);
|
e.appendChild(t);
|
||||||
l.appendChild(e);
|
l.appendChild(e);
|
||||||
|
@ -138,10 +136,29 @@ function logit(msg) {
|
||||||
l.removeChild(l.children[0]);
|
l.removeChild(l.children[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function socketClosed() {
|
||||||
|
var b = document.getElementById("connect-button");
|
||||||
|
b.onclick = startui
|
||||||
|
b.value = "connect";
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
var ws = new WebSocket(url);
|
||||||
ws.onclose = function (ev) {
|
ws.onclose = function (ev) {
|
||||||
|
logit("failed to connect to "+url);
|
||||||
nodes = { length: 0 };
|
nodes = { length: 0 };
|
||||||
tpeers = { length: 0 };
|
tpeers = { length: 0 };
|
||||||
|
socketClosed();
|
||||||
|
}
|
||||||
|
ws.onopen = function(ev) {
|
||||||
|
logit("connected to "+url);
|
||||||
}
|
}
|
||||||
ws.onmessage = function(ev) {
|
ws.onmessage = function(ev) {
|
||||||
var j = JSON.parse(ev.data);
|
var j = JSON.parse(ev.data);
|
||||||
|
@ -170,6 +187,12 @@ ws.onmessage = function(ev) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var b = document.getElementById("connect-button");
|
||||||
|
b.onclick = function() {
|
||||||
|
ws.close();
|
||||||
|
}
|
||||||
|
b.value = "disconnect";
|
||||||
|
}
|
||||||
|
|
||||||
function getPeer(h, us) {
|
function getPeer(h, us) {
|
||||||
if (tpeers[h]) {
|
if (tpeers[h]) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue