Fault-tolerant WebSocket client with binary Wire Protocol. Auto-reconnect, heartbeat, pub/sub, request-response correlation. AI agents: see AI_KNOWLEDGE.md for expert context.
WireClient is a standalone WebSocket client using the compact Wire binary framing protocol. It handles reconnection, heartbeats, message correlation, auth, and pub/sub. You just handle messages.
Compatible with @coderbuzz/velox-ws-wire-server: connect to any Velox-based server using the Wire Protocol, or implement your own server using @coderbuzz/velox-ws-wire codec.
- Binary protocol: 80-93% bandwidth reduction vs JSON
- Auto-reconnect: exponential backoff, configurable max retries
- Heartbeat: configurable ping/pong interval
- Request-response:
sendWait()with correlation ID and timeout - Pub/Sub: topic-based subscribe/publish/unsubscribe
- Auth: token-based, sent as first message or query param
- Zero dependencies beyond
@coderbuzz/velox-ws-wire
npm install @coderbuzz/velox-ws-wire @coderbuzz/velox-ws-wire-client@coderbuzz/velox-ws-wire is required as a peer (binary codec).
import { WireClient } from "@coderbuzz/velox-ws-wire-client";
const client = new WireClient("wss://api.example.com/ws", {
token: "my-auth-token",
heartbeatInterval: 30_000,
});
await client.connect();
// Fire-and-forget
client.send("hello");
// Request-response
const result = await client.sendWait({ type: "getData" }, 10_000);
// Pub/sub
client.subscribe("events", (data) => console.log("Event:", data));
client.publish("events", { action: "click" });
await client.close();| Option | Type | Default | Description |
|---|---|---|---|
url |
string |
required | WebSocket URL |
token? |
string |
none | Auth token |
authMode? |
'message' | 'query' |
'message' |
Auth delivery method |
authTimeout? |
number |
10_000 |
Auth timeout ms |
maxRetries? |
number |
Infinity |
Max reconnect attempts |
backoffBase? |
number |
500 |
Initial backoff ms |
backoffMax? |
number |
30_000 |
Max backoff ms |
backoffFactor? |
number |
2 |
Backoff multiplier |
heartbeatInterval? |
number |
30_000 |
Ping interval ms |
requestTimeout? |
number |
10_000 |
sendWait timeout ms |
onConnect? |
() => void |
none | Connected callback |
onDisconnect? |
(code, reason) => void |
none | Disconnected callback |
onReconnectAttempt? |
(attempt, delay) => void |
none | Reconnect attempt callback |
onData? |
(data: string | ArrayBuffer) => void |
none | Every incoming message, raw |
onFrame? |
(frame: DecodedFrame) => void |
none | Every decoded binary frame |
| Method | Description |
|---|---|
client.connect() |
Connect to server, resolves after AUTH_OK when a token is sent as a message |
client.close(code?, reason?) |
Disconnect without reconnecting, resolves when the socket closes |
client.send(data) |
Fire-and-forget raw send (no Wire framing), returns false if not open |
client.sendWait(payload, timeout?) |
Send + wait for response |
client.subscribe(topic, cb) |
Subscribe to topic |
client.publish(topic, data) |
Publish to topic, returns false if not open |
client.unsubscribe(topic) |
Unsubscribe from topic |
client.state |
Current WireClientState value |
WireClientState: CONNECTING (0) | OPEN (1) | CLOSING (2) | CLOSED (3) | RECONNECTING (4)
MIT © 2026 Indra Gunawan