
Security News
NIST Officially Stops Enriching Most CVEs as Vulnerability Volume Skyrockets
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.
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
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.