From b80f0dec53828652b18649abdac91f6d60c0ef67 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sun, 20 Sep 2020 12:24:59 -0400 Subject: [PATCH] socket ping canary --- src/sockets.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sockets.js b/src/sockets.js index 2fd93ecc..6c5b11df 100644 --- a/src/sockets.js +++ b/src/sockets.js @@ -5,6 +5,18 @@ const logger = require('winston') const Encryption = require('../utils/encryptionStore') const LightningServices = require('../utils/lightningServices') +const onPing = (socket, subID) => { + logger.warn('Subscribing to pings socket...' + subID) + + const intervalID = setInterval(() => { + socket.emit('shockping') + }, 3000) + + return () => { + clearInterval(intervalID) + } +} + module.exports = ( /** @type {import('socket.io').Server} */ io @@ -286,10 +298,12 @@ module.exports = ( logger.info('[LND] New LND Socket created:' + isNotifications + subID) const cancelInvoiceStream = onNewInvoice(socket, subID) const cancelTransactionStream = onNewTransaction(socket, subID) + const cancelPingStream = onPing(socket, subID) socket.on('disconnect', () => { logger.info('LND socket disconnected:' + isNotifications + subID) cancelInvoiceStream() cancelTransactionStream() + cancelPingStream() }) return }