maxsocket is a lightweight (~0.9 kB min+gzip) WebSocket client library offering built-in auto-reconnect, offline message queuing, JSON handling, and event routing. Current stable version is 1.0.2. It provides a functional API with explicit lifecycle handlers (onConnect, onMessage, onClose) instead of generic event listeners, and includes an event routing system for structured server messages. Unlike alternatives like reconnecting-websocket (2.6 kB) and simple-websocket (13.8 kB), maxsocket focuses on small bundle size, simplicity for modern frontends (React, Vue, Svelte, vanilla JS), and built-in features that reduce boilerplate. It is ESM-only and uses the native browser WebSocket API.
npm install maxsocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
This example demonstrates connecting to a WebSocket server, handling connection, receiving messages, and closing the socket.
Use in browser environments only, or use a package like 'ws' directly for Node.js.
Ensure server messages follow the required format, or avoid using event routing and use `onMessage` directly.
Only send objects as data; if you need to send raw strings, consider manual serialization.
No fix needed.
Use in a browser or provide a global WebSocket polyfill (e.g., 'ws' library).
Run `npm install maxsocket` and ensure the import is `import { connect } from 'maxsocket'`.Use `onConnect` to send messages after connection is established.
No dependency data recorded yet.