Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-health-agent

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-health-agent - npm Package Compare versions

Comparing version 0.1.0 to 0.3.0

jest.config.js

69

index.js

@@ -5,3 +5,3 @@ const os = require('os')

const heartbeat = (ws) => {
const heartbeat = (ws, delay) => {
clearTimeout(ws.pingTimeout)

@@ -15,14 +15,16 @@

ws.terminate()
}, 30000 + 1000)
}, delay)
}
const connectToWSS = async (config, inspector) => {
const ws = new WebSocket(`${config.serverUrl}/${os.hostname()}/${config.appName}`)
const connectToWSS = (config, inspector, destroyed) => {
const WSSConfig = {}
const delay = config.heartbeatDelay || 31000
const autoReconnectDelay = config.autoReconnectDelay || 1000
if (config.token) WSSConfig.headers = { token: config.token }
let ws = new WebSocket(`${config.serverUrl}/${os.hostname()}/${config.appName}`, WSSConfig)
ws.on('ping', () => { heartbeat(ws) })
const ping = () => { heartbeat(ws, delay) }
ws.on('open', () => {
console.info('Connected to WS server.')
heartbeat(ws)
})
ws.on('ping', ping)
.on('open', ping)

@@ -34,11 +36,34 @@ ws.on('message', (msg) => {

ws.on('close', async () => {
ws.on('close', () => {
ws.terminate()
await connectToWSS(config, inspector)
clearTimeout(ws.pingTimeout)
if (!destroyed) {
setTimeout(() => {
ws.removeAllListeners()
ws = (connectToWSS(config, inspector, destroyed)).ws
}, autoReconnectDelay)
}
})
ws.on('error', async (err) => {
ws.on('error', (err) => {
if (err.code === 'ECONNREFUSED') {
ws.removeAllListeners()
ws = (connectToWSS(config, inspector, destroyed)).ws
}
ws.terminate()
})
return {
destroy: async () => {
destroyed = true
if (inspector) await inspector.destroy()
clearTimeout(ws.pingTimeout)
ws.terminate()
},
ws: ws,
addEvent: (event, fn) => {
events[event] = fn
}
}
}

@@ -59,11 +84,15 @@

if (!config.appName) {
console.error('Can\'t start node health agent, no app name provided!')
return
const msg = 'Can\'t start node health agent, no app name provided!'
console.error(msg)
return new Error(msg)
}
if (!config.serverUrl) {
console.error('Can\'t start node health agent, no server url!')
return
const msg = 'Can\'t start node health agent, no server url!'
console.error(msg)
return new Error(msg)
}
const destroyed = false
let inspector
if (config.inspector) {

@@ -74,9 +103,3 @@ inspector = new Inspector(config.inspector)

connectToWSS(config, inspector)
return {
addEvent: (event, fn) => {
events[event] = fn
}
}
return connectToWSS(config, inspector, destroyed)
}
{
"name": "node-health-agent",
"version": "0.1.0",
"version": "0.3.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/jest",
"lint": "./node_modules/.bin/eslint ./"

@@ -25,4 +26,5 @@ },

"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1"
"eslint-plugin-standard": "^4.0.1",
"jest": "^24.9.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc