@magnaboy/websocket
v0.0.1
Published
Typed reconnecting WebSocket client, plus Node-only connection diagnostics.
Readme
@magnaboy/websocket
Reconnecting WebSocket client with a typed event emitter. The default entry is isomorphic (global WebSocket). TCP failure diagnosis lives on a Node-only subpath.
Install
npm i @magnaboy/websocketRequires Node 25+ (or any runtime with global WebSocket). ESM only.
Usage
import { WebSocketClient } from '@magnaboy/websocket';
const ws = new WebSocketClient({ url: 'wss://example.test/socket' });
ws.events.on('json', ({ parsed }) => {
console.log(parsed);
});
ws.send({ type: 'hello' });Pass createWebSocket if you need a custom constructor. autoStart defaults to true.
Node diagnostics
import { diagnoseWebSocketFailure } from '@magnaboy/websocket/node';
const details = await diagnoseWebSocketFailure(url, error);Entry points
| Import | Contents |
| --- | --- |
| @magnaboy/websocket | WebSocketClient, emitter, serialize/parse, error text (isomorphic) |
| @magnaboy/websocket/node | diagnoseWebSocketFailure() — TCP probe via node:net |
