add websocket to webpages
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user