Blame view
lib/heartbeat-ping.js
780 Bytes
b76b508a9
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
const MODULE_NAME = 'KOMODO-SDK-PUSH-TRX.HEARTBEAT-PING'; const uniqid = require('uniqid'); const config = require('komodo-sdk/config'); const logger = require('tektrans-logger'); /** * @param {WebSocket} ws */ module.exports = (ws) => { const xid = uniqid(); if (ws.isAlive === false) { logger.info(`${MODULE_NAME} D13AAE47: Terminating dead connection`, { apikey: ws.headers.apikey || ws.headers.token, }); ws.terminate(); return; } // eslint-disable-next-line no-param-reassign ws.isAlive = false; logger.debug(`${MODULE_NAME} DBA1B658: Sending ping for heartbeat`, { xid }); ws.ping(JSON.stringify({ rid: xid, senderName: config.handler_name, ts: new Date(), })); }; |