forked from fedi/mastodon
Add heartbeat to websockets streaming API connections
This commit is contained in:
parent
2d07cb5771
commit
3618cc04ff
|
@ -215,8 +215,11 @@ const streamHttpEnd = req => (id, listener) => {
|
||||||
|
|
||||||
// Setup stream output to WebSockets
|
// Setup stream output to WebSockets
|
||||||
const streamToWs = (req, ws) => {
|
const streamToWs = (req, ws) => {
|
||||||
|
const heartbeat = setInterval(() => ws.ping(), 15000)
|
||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
log.verbose(req.requestId, `Ending stream for ${req.accountId}`)
|
log.verbose(req.requestId, `Ending stream for ${req.accountId}`)
|
||||||
|
clearInterval(heartbeat)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (event, payload) => {
|
return (event, payload) => {
|
||||||
|
@ -234,6 +237,10 @@ const streamWsEnd = ws => (id, listener) => {
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
unsubscribe(id, listener)
|
unsubscribe(id, listener)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ws.on('error', e => {
|
||||||
|
unsubscribe(id, listener)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(setRequestId)
|
app.use(setRequestId)
|
||||||
|
|
Loading…
Reference in a new issue