Skip to content
Snippets Groups Projects
Commit 3618cc04 authored by Eugen Rochko's avatar Eugen Rochko
Browse files

Add heartbeat to websockets streaming API connections

parent 2d07cb57
Branches
Tags
No related merge requests found
......@@ -215,8 +215,11 @@ const streamHttpEnd = req => (id, listener) => {
// Setup stream output to WebSockets
const streamToWs = (req, ws) => {
const heartbeat = setInterval(() => ws.ping(), 15000)
ws.on('close', () => {
log.verbose(req.requestId, `Ending stream for ${req.accountId}`)
clearInterval(heartbeat)
})
return (event, payload) => {
......@@ -234,6 +237,10 @@ const streamWsEnd = ws => (id, listener) => {
ws.on('close', () => {
unsubscribe(id, listener)
})
ws.on('error', e => {
unsubscribe(id, listener)
})
}
app.use(setRequestId)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment