diff --git a/webSocketServer/index.js b/webSocketServer/index.js index 0cc7ee1..5e5890b 100644 --- a/webSocketServer/index.js +++ b/webSocketServer/index.js @@ -9,9 +9,17 @@ module.exports = function() { port: config.port }); + function noop() {} + + function heartbeat() { + this.isAlive = true; + } + objWs.wsServer.on('connection', function connection(ws) { console.log('open socket server'); + ws.isAlive = true; + ws.on('pong', heartbeat); ws.on('message', function incoming(message) { @@ -27,6 +35,15 @@ module.exports = function() { }); }); + const interval = setInterval(function ping() { + objWs.wsServer.clients.forEach(function each(ws) { + if (ws.isAlive === false) return ws.terminate(); + + ws.isAlive = false; + ws.ping(noop); + }); + }, 10000); + objWs.getEntidad = function(gln, tableName, where, queryString) { return new Promise(function(resolve, reject) {