Skip to content

Commit

Permalink
Merge pull request #293 from FlowFuse/ws-heartbeat
Browse files Browse the repository at this point in the history
Add heartbeat to Editor WebSocket Tunnel
  • Loading branch information
knolleary authored Jul 17, 2024
2 parents b09bbae + d206b2a commit 96a9001
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/editor/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ class EditorTunnel {
})
}
})
clearInterval(this.pingInterval)
this.pingInterval = setInterval(() => {
debug('Sending WS editor tunnel ping')
try {
socket.ping()
} catch (err) { }
}, 40000)
}
socket.on('close', async (code, reason) => {
if (Buffer.isBuffer(reason)) {
Expand All @@ -257,6 +264,7 @@ class EditorTunnel {
info(`Editor tunnel closed code=${code} reason=${reason}`)
socket.removeAllListeners()
this.socket = null
clearInterval(this.pingInterval)
clearTimeout(this.reconnectTimeout)
// Pre 1.12, FF returned '1008/No Tunnel' - but 1008 was also used
// for other scenarios, so we have to check both code and reason text.
Expand Down Expand Up @@ -310,6 +318,7 @@ class EditorTunnel {
// ensure any active timers are stopped
clearInterval(this.connectionReadyInterval)
clearTimeout(this.reconnectTimeout)
clearInterval(this.pingInterval)
}

async waitForConnection () {
Expand Down

0 comments on commit 96a9001

Please sign in to comment.