npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@celerity-sdk/ws-client

v0.3.1

Published

TypeScript WebSocket client SDK for the Celerity Runtime Protocol

Downloads

44

Readme

Celerity WebSocket Client

Coverage Security Rating Maintainability Rating

TypeScript WebSocket client SDK for the Celerity Runtime Protocol. Works in both Node.js and the browser. Zero bundled dependencies for browser clients; Node.js requires the ws peer dependency.

Features

  • Full implementation of the Celerity Runtime Protocol (capabilities negotiation, authentication, heartbeat, acks, deduplication)
  • Automatic reconnection with exponential backoff and jitter
  • Binary and JSON message support
  • Dual ESM/CJS output with separate browser and Node.js entry points
  • JSON property-based message routing with wildcard ("*") support
  • Zero runtime dependencies for browser clients, ws is an optional peer dependency for Node.js.

Installation

npm install @celerity-sdk/ws-client

# Node.js also requires the ws library
npm install ws

Quick Start

Browser

import { createWsClient } from "@celerity-sdk/ws-client";

const client = await createWsClient({ url: "wss://example.com/ws" });

client.on("connected", () => {
  console.log("Connected!");
  client.send("greet", { message: "Hello" });
});

client.on("greeting", (data) => {
  console.log("Received:", data);
});

await client.connect();

Node.js

import { createWsClient } from "@celerity-sdk/ws-client";

const client = await createWsClient({ url: "wss://example.com/ws" });

client.on("connected", () => {
  client.send("greet", { message: "Hello from Node" });
});

await client.connect();

Authentication

The client supports two authentication strategies:

Auth Message (works with all servers)

const client = await createWsClient({
  url: "wss://example.com/ws",
  auth: {
    strategy: "authMessage",
    token: "your-token",
  },
});

Connect (requires server support for custom close codes)

const client = await createWsClient({
  url: "wss://example.com/ws",
  auth: {
    strategy: "connect",
    token: "your-token",
    headerName: "Authorization", // default
    headerPrefix: "Bearer", // default
  },
});

Both strategies accept a token string or an async function that resolves to a token.

Sending Messages

// Fire-and-forget
client.send("chat.message", { text: "Hello" });

// With acknowledgement
const ack = await client.sendWithAck("chat.message", { text: "Hello" });
console.log("Acknowledged at:", ack.timestamp);

// Binary messages (requires server capability)
client.sendBinary("audio.chunk", audioBuffer);
const ack = await client.sendBinaryWithAck("audio.chunk", audioBuffer);

Listening for Events

// Lifecycle events
client.on("connected", () => {
  /* ... */
});
client.on("disconnected", ({ code, reason, willReconnect }) => {
  /* ... */
});
client.on("reconnecting", ({ attempt, delay }) => {
  /* ... */
});
client.on("authenticated", (userInfo) => {
  /* ... */
});
client.on("error", (err) => {
  /* ... */
});

// Custom message routes
client.on("chat.message", (data) => {
  /* ... */
});

// Wildcard route — receive all application messages regardless of route.
// Wildcard handlers fire alongside route-specific handlers, not instead of them.
client.on("*", (data, metadata) => {
  console.log(`Received message on route "${metadata.route}":`, data);
});

// Binary messages support the same wildcard pattern
client.onBinary("*", (payload, metadata) => {
  /* receives all binary messages */
});

// Binary message routes
client.onBinary("audio.chunk", (payload) => {
  /* ... */
});

// All handlers return an unsubscribe function
const unsub = client.on("chat.message", handler);
unsub(); // stop listening

Configuration

const client = await createWsClient({
  url: "wss://example.com/ws", // Required
  auth: {
    /* ... */
  }, // Optional authentication
  routeKey: "event", // Message route field (default: "event")
  protocols: [], // WebSocket sub-protocols
  headers: {}, // Custom upgrade headers (Node.js only)
  handshakeTimeout: 2000, // Capabilities handshake timeout in ms
  messageId: "uuid", // "uuid" or custom generator function
  heartbeat: {
    interval: 10_000, // Ping interval in ms
    timeout: 5_000, // Pong timeout in ms
  },
  reconnect: {
    enabled: true,
    maxRetries: 100,
    baseDelay: 1_000, // Initial backoff delay in ms
    backoffFactor: 1.5,
    maxDelay: 30_000, // Maximum backoff delay in ms
    maxElapsedTime: 300_000, // Give up after 5 minutes (0 = unlimited)
  },
  ack: {
    timeout: 10_000, // Ack wait timeout in ms
    maxRetries: 3,
  },
  deduplication: {
    enabled: true,
    ttl: 300_000, // Dedup window in ms
    maxEntries: 10_000,
  },
});

Contributing

See CONTRIBUTING.md for development setup, commands, and commit conventions.

License

Apache-2.0