Registry / messaging / extra-native-websocket

extra-native-websocket

JSON →
library0.5.2jsnpmunverified

extra-native-websocket (v0.5.2) is a lightweight, TypeScript-first library that wraps native WebSocket with a promise-based API, typed error handling, reconnection strategies, and state management. It extends an emitter pattern from @blackglory/structures, offering autoReconnect and exponential backoff without external dependencies. Requires Node >=22 and ESM-only. Differentiates from ws or isomorphic-ws by focusing on native WebSocket and providing extra utilities like autoReconnect and WebSocketError.

messaging
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ESM-only since v0.1.0; CommonJS require will fail.

import { ExtraNativeWebSocket } from 'extra-native-websocket'

Available as named export since v0.3.0.

import { autoReconnect } from 'extra-native-websocket'

WebSocketError is re-exported from this package; do not import from extra-error directly.

import { WebSocketError } from 'extra-native-websocket'

TypeScript enum; use as type for setBinaryType.

import { BinaryType } from 'extra-native-websocket'

TypeScript enum; returned by getState().

import { State } from 'extra-native-websocket'

Creates an ExtraNativeWebSocket with reconnection, connects, sends and receives a message.

import { ExtraNativeWebSocket, autoReconnect } from 'extra-native-websocket'; const ws = new ExtraNativeWebSocket(() => new WebSocket('wss://echo.websocket.org')); const cleanup = autoReconnect(ws, 2000); // reconnect every 2 seconds ws.on('open', () => { console.log('connected'); ws.send('Hello'); }); ws.on('message', (event) => { console.log('Received:', event.data); cleanup(); // stop reconnecting after first message }); ws.connect().then(() => { console.log('Connection established'); }).catch((err) => { console.error('Connection failed:', err); });
Debug
Known footguns
breakingConstructor expects a factory function, not a URL: new ExtraNativeWebSocket(() => new WebSocket(url))
gotchaconnect() returns Promise<void> but does not handle signal cancellation properly on React Native or non-standard environments
deprecatedautoReonnectWithExponentialBackOff is misspelled (double 'n'), consider removing or deprecating in future
gotchaRequires Node >=22; will throw SyntaxError on older versions due to ESM features
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
23 hits · last 30 days
bytedance
4
gptbot
3
amazonbot
3
ahrefsbot
1
Resources