socket ping pong
This commit is contained in:
parent
3a6b22cff8
commit
81f7400748
2 changed files with 14 additions and 0 deletions
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue