Merge pull request #875 from shocknet/socket-ping-pong
socket ping pong
This commit is contained in:
commit
ecf7c43416
2 changed files with 14 additions and 0 deletions
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue