1
0

add websocket to webpages

This commit is contained in:
ThomasV
2015-07-24 11:39:12 +02:00
parent 41d9c94821
commit 18d145cced
3 changed files with 161 additions and 3 deletions

View File

@@ -26,7 +26,7 @@ var id = getUrlParameter('id');
if (id) {
var jqxhr = $.getJSON(id + ".json", function() {
console.log( "success" );
console.log("getJSON:success");
})
.done( function(data) {
new QRCode(document.getElementById("qrcode"), data.URI);
@@ -50,17 +50,30 @@ if (id) {
value: current
});
if (current >= max) {
$("#container").html("This payment request has expired");
$("#container").html("This invoice has expired");
}
};
var interval = setInterval(update, 1000);
});
})
.fail(function() {
console.log( "error fail" );
console.log("error fail");
$("<p />").text("error").appendTo($("p#error"));
});
};
var ws = new WebSocket("wss://electrum.org:9999/");
ws.onopen = function() {
ws.send('id:' + id);
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
if(received_msg == 'paid'){
$("#container").html("This invoice has been paid.");
}
else alert("Message is received:"+ received_msg);
};
</script>
</head>
<body>