node-health-agent
Advanced tools
Comparing version 0.3.0 to 0.4.0
11
index.js
@@ -30,4 +30,11 @@ const os = require('os') | ||
ws.on('message', (msg) => { | ||
if (!events[msg]) return console.warn(`Event ${msg} not handled!\nYou can use the addEvent() method to attach an action to a specific event.`) | ||
events[msg](msg, inspector) | ||
let eventName | ||
try { | ||
msg = JSON.parse(msg) | ||
eventName = msg.name | ||
} catch (e) { | ||
eventName = msg | ||
} | ||
if (!events[eventName]) return console.warn(`Event ${eventName} not handled!\nYou can use the addEvent() method to attach an action to a specific event.`) | ||
events[eventName](msg, inspector) | ||
}) | ||
@@ -34,0 +41,0 @@ |
{ | ||
"name": "node-health-agent", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -216,3 +216,30 @@ const WebSocket = require('ws') | ||
}) | ||
it('should handle event as JSON object', (done) => { | ||
wss = new WebSocket.Server({ | ||
port: 3000 | ||
}) | ||
wss.on('listening', () => { | ||
agent = require('../index')({ | ||
appName: 'test', | ||
serverUrl: 'ws://localhost:3000' | ||
}) | ||
agent.addEvent('custom_event_json', (event) => { | ||
expect(event.name).toEqual('custom_event_json') | ||
expect(event.data.key).toEqual('value') | ||
done() | ||
}) | ||
agent.ws.on('open', () => { | ||
expect(typeof agent.addEvent).toEqual('function') | ||
wss.clients.forEach(ws => { | ||
ws.send('{"name":"custom_event_json","data":{"key":"value"}}') | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14858
312
0