From 52b838b421ecc55fc1c778e1d1edbe395d56c854 Mon Sep 17 00:00:00 2001 From: Eric Fernandez Date: Fri, 23 Aug 2019 14:47:23 -0300 Subject: [PATCH] ping pong --- webSocketServer/index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) { -- 1.9.1