diff --git a/src/services/lnd/swaps/reverseSwaps.ts b/src/services/lnd/swaps/reverseSwaps.ts index a8bd6ade..14dc4d44 100644 --- a/src/services/lnd/swaps/reverseSwaps.ts +++ b/src/services/lnd/swaps/reverseSwaps.ts @@ -121,9 +121,13 @@ export class ReverseSwaps { webSocket.on('open', () => { webSocket.send(JSON.stringify(subReq)) }) + const interval = setInterval(() => { + webSocket.ping() + }, 30 * 1000) let txId = "", isDone = false const done = (failureReason?: string) => { isDone = true + clearInterval(interval) webSocket.close() if (failureReason) { swapDone({ ok: false, error: failureReason }) @@ -131,6 +135,9 @@ export class ReverseSwaps { swapDone({ ok: true, txId }) } } + webSocket.on('pong', () => { + this.log('WebSocket transaction swap pong received') + }) webSocket.on('error', (err) => { this.log(ERROR, 'Error in WebSocket', err.message) }) diff --git a/src/services/lnd/swaps/submarineSwaps.ts b/src/services/lnd/swaps/submarineSwaps.ts index 56ce40e3..32ed1fac 100644 --- a/src/services/lnd/swaps/submarineSwaps.ts +++ b/src/services/lnd/swaps/submarineSwaps.ts @@ -376,9 +376,13 @@ export class SubmarineSwaps { webSocket.on('open', () => { webSocket.send(JSON.stringify(subReq)) }) + const interval = setInterval(() => { + webSocket.ping() + }, 30 * 1000) let isDone = false const done = (failureReason?: string) => { isDone = true + clearInterval(interval) webSocket.close() if (failureReason) { swapDone({ ok: false, error: failureReason }) @@ -386,6 +390,9 @@ export class SubmarineSwaps { swapDone({ ok: true }) } } + webSocket.on('pong', () => { + this.log('WebSocket invoice swap pong received') + }) webSocket.on('error', (err) => { this.log(ERROR, 'Error in WebSocket', err.message) })