Sockette is a tiny (367 bytes) WebSocket wrapper that automatically reconnects on connection loss. Current stable version is 2.0.7. Released on npm, it provides a minimal API for managing WebSocket connections with configurable timeout and max reconnection attempts. It supports event listeners for open, message, close, reconnect, and maximum attempts reached events. Unlike raw WebSocket, it allows reusing a single instance without redeclaring listeners. It ships TypeScript types and is compatible with both browser and Node.js (with WebSocket polyfill).
npm install sockette-dynamic-urlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creating a Sockette instance with all event handlers, sending text and JSON, and manually reconnecting after 10 seconds.
Set `maxAttempts: Infinity` or omit the option.
Ensure timeout value is in milliseconds (e.g., 5000 for 5 seconds).
Use a WebSocket polyfill like `ws` and assign globally: `global.WebSocket = require('ws');`Use `event.target` to access the WebSocket instance inside event handlers.
Be aware that the counter resets; plan logic accordingly if you need persistent retry tracking.
Install `ws` and assign `global.WebSocket = require('ws');` before using Sockette.Ensure send is called after the `onopen` event has fired, or inside a callback.
Use a valid WebSocket URL with proper scheme, e.g., 'wss://example.com/ws'.
Use `import Sockette from 'sockette'` (default import) or `const Sockette = require('sockette')`.No dependency data recorded yet.