Merge pull request #875 from shocknet/socket-ping-pong

socket ping pong
This commit is contained in:
Justin (shocknet) 2026-02-05 15:09:56 -05:00 committed by GitHub
commit ecf7c43416
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View file

@ -121,9 +121,13 @@ export class ReverseSwaps {
webSocket.on('open', () => { webSocket.on('open', () => {
webSocket.send(JSON.stringify(subReq)) webSocket.send(JSON.stringify(subReq))
}) })
const interval = setInterval(() => {
webSocket.ping()
}, 30 * 1000)
let txId = "", isDone = false let txId = "", isDone = false
const done = (failureReason?: string) => { const done = (failureReason?: string) => {
isDone = true isDone = true
clearInterval(interval)
webSocket.close() webSocket.close()
if (failureReason) { if (failureReason) {
swapDone({ ok: false, error: failureReason }) swapDone({ ok: false, error: failureReason })
@ -131,6 +135,9 @@ export class ReverseSwaps {
swapDone({ ok: true, txId }) swapDone({ ok: true, txId })
} }
} }
webSocket.on('pong', () => {
this.log('WebSocket transaction swap pong received')
})
webSocket.on('error', (err) => { webSocket.on('error', (err) => {
this.log(ERROR, 'Error in WebSocket', err.message) this.log(ERROR, 'Error in WebSocket', err.message)
}) })

View file

@ -376,9 +376,13 @@ export class SubmarineSwaps {
webSocket.on('open', () => { webSocket.on('open', () => {
webSocket.send(JSON.stringify(subReq)) webSocket.send(JSON.stringify(subReq))
}) })
const interval = setInterval(() => {
webSocket.ping()
}, 30 * 1000)
let isDone = false let isDone = false
const done = (failureReason?: string) => { const done = (failureReason?: string) => {
isDone = true isDone = true
clearInterval(interval)
webSocket.close() webSocket.close()
if (failureReason) { if (failureReason) {
swapDone({ ok: false, error: failureReason }) swapDone({ ok: false, error: failureReason })
@ -386,6 +390,9 @@ export class SubmarineSwaps {
swapDone({ ok: true }) swapDone({ ok: true })
} }
} }
webSocket.on('pong', () => {
this.log('WebSocket invoice swap pong received')
})
webSocket.on('error', (err) => { webSocket.on('error', (err) => {
this.log(ERROR, 'Error in WebSocket', err.message) this.log(ERROR, 'Error in WebSocket', err.message)
}) })