npm.io
1.1.3 • Published 2 years ago

wandering-willow-websocket

Licence
MIT
Version
1.1.3
Deps
5
Size
4 kB
Vulns
1
Weekly
0

Wandering Willow WebSocket

A lightweight wrapper around WebSockets for easy real-time communication in JavaScript, "wandering-willow-websocket" aims to simplify the process of establishing, managing, and closing WebSocket connections.

Features

  • Easy WebSocket connection management
  • Automatic reconnection support
  • Event-based interface for open, message, close, and error events
  • Unique ID generation for clients

Installation

npm install wandering-willow-websocket

Usage

const WanderingWillowWebSocket = require('wandering-willow-websocket');

const ws = new WanderingWillowWebSocket('ws://example.com');

ws.on('open', () => {
console.log('Connection opened');
ws.send('Hello, world!');
});

ws.on('message', (message) => {
console.log('Received:', message);
});

ws.on('close', () => {
console.log('Connection closed');
});

ws.on('error', (error) => {
console.error('Error:', error);
});

API

  • send(data): Send data through the WebSocket connection.
  • close(): Close the WebSocket connection.
  • static generateId(): Generate a unique ID.

License

MIT

Keywords