Browse Source

Merge pull request #1935 from ser/add-ws-host-port

Adding possibility of websockets configuration
283
ThomasV 9 years ago
committed by GitHub
parent
commit
a132525a2b
  1. 2
      lib/wallet.py
  2. 27
      lib/www/index.html

2
lib/wallet.py

@ -1052,6 +1052,8 @@ class Abstract_Wallet(PrintError):
out['request_url'] = os.path.join(baseurl, key) out['request_url'] = os.path.join(baseurl, key)
out['URI'] += '&r=' + out['request_url'] out['URI'] += '&r=' + out['request_url']
out['index_url'] = os.path.join(baseurl, 'index.html') + '?id=' + key out['index_url'] = os.path.join(baseurl, 'index.html') + '?id=' + key
out['websocket_server'] = config.get('websocket_server', 'localhost')
out['websocket_port'] = config.get('websocket_port', 9999)
return out return out
def get_request_status(self, key): def get_request_status(self, key):

27
lib/www/index.html

@ -34,6 +34,8 @@ if (id) {
$("<p />").text(data.amount/100000000 + "BTC").appendTo($("p#amount")); $("<p />").text(data.amount/100000000 + "BTC").appendTo($("p#amount"));
$("a").attr("href", data.URI); $("a").attr("href", data.URI);
$("<p />").text("Powered by Electrum").appendTo($("p#powered")); $("<p />").text("Powered by Electrum").appendTo($("p#powered"));
var websocket_server = data.websocket_server;
var websocket_port = data.websocket_port;
$(function () { $(function () {
var current; var current;
var max = 100; var max = 100;
@ -57,25 +59,28 @@ if (id) {
var interval = setInterval(update, 1000); var interval = setInterval(update, 1000);
} }
}); });
})
.fail(function() {
console.log("error fail");
$("<p />").text("error").appendTo($("p#error"));
});
};
var ws = new WebSocket("wss://" + window.location.hostname + ":9999/"); var wss_address = "wss://" + websocket_server + ":" + websocket_port +"/");
ws.onopen = function() { console.log("Opening WSS: " + wss_address)
var ws = new WebSocket(wss_address);
ws.onopen = function() {
ws.send('id:' + id); ws.send('id:' + id);
}; };
ws.onmessage = function (evt) { ws.onmessage = function (evt) {
var received_msg = evt.data; var received_msg = evt.data;
if(received_msg == 'paid'){ if(received_msg == 'paid'){
$("#container").html("This invoice has been paid."); $("#container").html("This invoice has been paid.");
} }
else alert("Message is received:"+ received_msg); else alert("Message is received:"+ received_msg);
}; };
})
.fail(function() {
console.log("error fail");
$("<p />").text("error").appendTo($("p#error"));
});
};
// See http://stackoverflow.com/questions/29186154/chrome-clicking-mailto-links-closes-websocket-connection // See http://stackoverflow.com/questions/29186154/chrome-clicking-mailto-links-closes-websocket-connection
$(document).on('click', 'a[href^="bitcoin:"]', function (e) { $(document).on('click', 'a[href^="bitcoin:"]', function (e) {

Loading…
Cancel
Save