UNPKG

moleculer-web-uws

Version:

The `moleculer-web-uws` is a fast API gateway service for Moleculer based on µWebSockets.js server. Use it to publish your services over HTTP and WebSockets.

22 lines (16 loc) 613 B
const handleDisconnect = require('./handleDisconnect'); function keepAlive(connectionContext, options) { connectionContext.isAlive = true; connectionContext.cancelKeepAlive && clearInterval(connectionContext.cancelKeepAlive); connectionContext.cancelKeepAlive = setInterval(() => { if (connectionContext.isAlive === false) { handleDisconnect(connectionContext) } else { connectionContext.isAlive = false } const { socket } = connectionContext; if (!socket.done) socket.send(options.ping); }, options.interval); } module.exports = keepAlive;