Skip to content

About

@coderbuzz/velox-ws-wire-client

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Velox WireClient: @coderbuzz/velox-ws-wire-client

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.

npm version npm downloads MIT License GitHub Stars CI Codecov

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.


Features

  • 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

Installation

npm install @coderbuzz/velox-ws-wire @coderbuzz/velox-ws-wire-client

@coderbuzz/velox-ws-wire is required as a peer (binary codec).


Quick Start

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();

API

new WireClient(url, options)

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

Methods

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

States

WireClientState: CONNECTING (0) | OPEN (1) | CLOSING (2) | CLOSED (3) | RECONNECTING (4)


License

MIT © 2026 Indra Gunawan

About

@coderbuzz/velox-ws-wire-client

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages