tMerge pull request #1935 from ser/add-ws-host-port - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit a132525a2b73f6f23b2fe6d4105aead6b23c7ad1 DIR parent da544794b7726bd6eeb5e83f7bc5465e507aa492 HTML Author: ThomasV <thomasv@electrum.org> Date: Wed, 21 Sep 2016 14:48:05 +0200 Merge pull request #1935 from ser/add-ws-host-port Adding possibility of websockets configuration Diffstat: M lib/wallet.py | 2 ++ M lib/www/index.html | 33 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 14 deletions(-) --- DIR diff --git a/lib/wallet.py b/lib/wallet.py t@@ -1052,6 +1052,8 @@ class Abstract_Wallet(PrintError): out['request_url'] = os.path.join(baseurl, key) out['URI'] += '&r=' + out['request_url'] 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 def get_request_status(self, key): DIR diff --git a/lib/www/index.html b/lib/www/index.html t@@ -34,11 +34,13 @@ if (id) { $("<p />").text(data.amount/100000000 + "BTC").appendTo($("p#amount")); $("a").attr("href", data.URI); $("<p />").text("Powered by Electrum").appendTo($("p#powered")); + var websocket_server = data.websocket_server; + var websocket_port = data.websocket_port; $(function () { var current; var max = 100; var initial = data.time; - var duration = data.exp; + var duration = data.exp; if(duration){ var current = 100 * (Math.floor(Date.now()/1000) - initial)/duration; $("#progressbar").progressbar({ t@@ -57,6 +59,22 @@ if (id) { var interval = setInterval(update, 1000); } }); + + var wss_address = "wss://" + websocket_server + ":" + websocket_port +"/"); + console.log("Opening WSS: " + wss_address) + var ws = new WebSocket(wss_address); + + 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); + }; + }) .fail(function() { console.log("error fail"); t@@ -64,19 +82,6 @@ if (id) { }); }; -var ws = new WebSocket("wss://" + window.location.hostname + ":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); -}; - - // See http://stackoverflow.com/questions/29186154/chrome-clicking-mailto-links-closes-websocket-connection $(document).on('click', 'a[href^="bitcoin:"]', function (e) { e.preventDefault();