diff --git a/index.js b/index.js index a3ee703..fc83107 100644 --- a/index.js +++ b/index.js @@ -42,16 +42,24 @@ function startPingInterval () { } function waitForInvoicePaid (room, nick, invoice, retries=0) { + let timeout = 3000; + if (retries >= 300) { console.log(`Invoice not paid after 15 minutes: ${invoice.payment_hash}`); - return false; + let timeout = 5000; + if (retries >= 500) { + // TODO ask user to request voice again to create a new invoice + return false; + } } + lndhub.getInvoice(invoice.payment_hash).then(async data => { if (data.is_paid) { console.log(`Invoice paid: ${invoice.payment_hash}`); await grantVoice(room, nick); } else { setTimeout(waitForInvoicePaid, 3000, room, nick, invoice, retries++); + setTimeout(waitForInvoicePaid, timeout, room, nick, invoice, retries++); } }); }