fixed issue with browsers which don't support EventSource

This commit is contained in:
michael1011 2018-03-29 14:12:14 +02:00
parent d473e7819e
commit 08057fcb04
No known key found for this signature in database
GPG Key ID: 84D249BA71685D46
2 changed files with 7 additions and 4 deletions

View File

@ -126,7 +126,6 @@
height: 12px;
display: inline-block;
vertical-align: center;
border: 3px solid #F5F5F5;
border-top: 3px solid #212121;

View File

@ -9,7 +9,6 @@ var qrCode;
var defaultGetInvoice;
// TODO: show error when invoice expires
// TODO: maybe don't show full invoice
// TODO: show price in dollar?
function getInvoice() {
@ -110,11 +109,13 @@ function getInvoice() {
}
function listenInvoiceSettled(hash) {
if (EventSource !== undefined) {
try {
var eventSrc = new EventSource(requestUrl + "eventsource");
eventSrc.onmessage = function (event) {
if (event.data === hash) {
console.log("Invoice settled");
eventSrc.close();
showThankYouScreen();
@ -122,7 +123,8 @@ function listenInvoiceSettled(hash) {
};
} else {
} catch (e) {
console.info(e);
console.warn("Your browser does not support EventSource. Sending a request to the server every two second to check if the invoice is settled");
var interval = setInterval(function () {
@ -133,6 +135,8 @@ function listenInvoiceSettled(hash) {
var json = JSON.parse(request.responseText);
if (json.Settled) {
console.log("Invoice settled");
clearInterval(interval);
showThankYouScreen();