
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ws-events-handler
Advanced tools
The WebSocketEventsHandler class is a comprehensive JavaScript handler for managing WebSocket connections, including automatic reconnection, heartbeat management, event handling, and offline event storage. This class provides robust support for WebSocket
The WebSocketEventsHandler class is a comprehensive JavaScript handler for managing WebSocket connections, including automatic reconnection, heartbeat management, event handling, and offline event storage. This class provides robust support for WebSocket applications, ensuring seamless communication even in unstable network environments.
Install this module via npm:
npm install ws-events-handler
import WebSocketEventsHandler from './WebSocketEventsHandler';
const wsHandler = new WebSocketEventsHandler('ws://your-websocket-url', {
heartbeat: {
interval: 15000,
message: 'ping',
expectedResponse: 'pong',
timeout: 10000
},
connection: {
maxRetries: 5,
retryDelay: 1000
},
debug: true
});
heartbeat (object):
interval: Interval between heartbeats in milliseconds.message: Message sent as heartbeat.expectedResponse: Expected response from server.timeout: Time to wait for a response before reconnecting.connection (object):
maxRetries: Maximum number of reconnection attempts.retryDelay: Delay between reconnection attempts.fallback.localEvents: Enable storing events locally when offline.debug (boolean): Enable verbose logging.
Register an event handler for a specific event:
wsHandler.on('eventName', (data) => {
console.log('Event received:', data);
});
Register an event handler for a specific event in cycles.
wsEvents.on('eventName', {
cycle: {
every: 3,
exclusive: true,
once: true,
callback: (data) => {
console.log(data);
}
},
callback: (data) => {
console.log("this won't fire as cycle is configured to be exclusive.")
}
})
This configuration will fire callback once 3 messages for 'eventName' have arrived.
every: Cycle will be executed every N messages.exclusive: Cycle will only execute it's internal callback and not the root callback defined in the handler configuration. If false, root callback will be called every time a message arrives to 'eventName'.rounds: Cycle will run N times and then it will self-destruct.once: Cycle will run only once. (similar to setting rounds = 1)Unregister an event:
wsHandler.off('eventName');
To send an event with optional payload:
wsHandler.send('eventName', { key: 'value' });
To clean up resources and close the WebSocket connection:
wsHandler.destroy('Reason for destruction');
on(eventName, config): Registers an event handler.off(eventName): Unregisters an event handler.send(eventName, payload): Sends an event with an optional payload.destroy(reason): Destroys the WebSocket connection and cleans up resources.This project is licensed under the MIT License.
FAQs
The WebSocketEventsHandler class is a comprehensive JavaScript handler for managing WebSocket connections, including automatic reconnection, heartbeat management, event handling, and offline event storage. This class provides robust support for WebSocket
We found that ws-events-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.