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

@mavisakalyan/ws-relay-client

v0.1.2

Published

WebSocket relay client with chat, users, and reconnect.

Readme

@mavisakalyan/ws-relay-client

WebSocket relay client with chat, users, and automatic reconnection. Works in any JavaScript environment.

Install

npm install @mavisakalyan/ws-relay-client

This automatically installs @mavisakalyan/ws-relay-protocol (types + codec).

Quick start

import { createRelayClient, getChatMessages, subscribeChatMessages } from "@mavisakalyan/ws-relay-client";

// 1. Create a client
const client = createRelayClient({
  url: "wss://your-relay.example.com/ws",
  roomId: "lobby",
  username: "Alice",
});

// 2. Connect
client.connect();

// 3. Listen for messages
subscribeChatMessages(() => {
  const messages = getChatMessages();
  console.log("Messages:", messages);
});

// 4. Send a message
client.sendChat("Hello everyone!");

// 5. Send a reply
client.sendChat("I agree!", {
  id: "original-msg-id",
  text: "The original message text",
  username: "Bob",
});

// 6. Disconnect when done
client.disconnect();

What you get

RelayClient

The main class. Handles WebSocket connection, reconnection with exponential backoff, ping/pong keepalive, and announce messages.

import { createRelayClient } from "@mavisakalyan/ws-relay-client";

const client = createRelayClient({
  url: "wss://relay.example.com/ws",  // Your relay server
  roomId: "my-room",                   // Room to join
  username: "Alice",                    // Display name
});

client.connect();

// Properties
client.status;       // "disconnected" | "connecting" | "connected"
client.playerId;     // Server-assigned ID (string | null)
client.currentRttMs; // Latest round-trip time (number | null)

// Listen for connection changes
const unsub = client.subscribeConnection((status, rttMs) => {
  console.log(`Status: ${status}, RTT: ${rttMs}ms`);
});

// Send chat
client.sendChat("Hello!");

// Disconnect
client.disconnect();

Chat store

Module-level store for chat messages. Uses immutable snapshots — designed for useSyncExternalStore in React, but works anywhere.

import {
  getChatMessages,
  subscribeChatMessages,
  addSystemMessage,
  clearChatMessages,
  findMessageById,
} from "@mavisakalyan/ws-relay-client";

// Subscribe to changes
const unsub = subscribeChatMessages(() => {
  const messages = getChatMessages();
  // messages: ChatMessage[]
  // Each message has: id, from, text, username, timestamp, isLocal, replyTo?, isSystem?
});

// Add a system message (join/leave notifications, etc.)
addSystemMessage("Alice joined the room");

// Find a specific message (for building reply previews)
const original = findMessageById("msg_1_1234567890");

Users store

Tracks who's online. Updated automatically by the client when peers announce themselves.

import { getUsers, subscribeUsers } from "@mavisakalyan/ws-relay-client";

const unsub = subscribeUsers(() => {
  const users = getUsers();
  // users: OnlineUser[]
  // Each user has: playerId, username, isLocal
  console.log(`${users.length} users online`);
});

Types

import type {
  ChatMessage,        // { id, from, text, username, timestamp, isLocal, replyTo?, isSystem? }
  ChatReplyTo,        // { id, text, username }
  AddChatMessageInput,// Input for addChatMessage()
  OnlineUser,         // { playerId, username, isLocal }
  ConnectionStatus,   // "disconnected" | "connecting" | "connected"
  RelayClientOptions, // { url, roomId, username }
} from "@mavisakalyan/ws-relay-client";

You need a server

This is a client-side package. It connects to a WebSocket relay server:

Or any server that relays msgpack messages in { type: "relay", from, data } format.

Using with React?

Install @mavisakalyan/ws-relay-react instead — it wraps this package with hooks:

import { useChat, useUsers, useConnection } from "@mavisakalyan/ws-relay-react";

const messages = useChat();       // auto-subscribes to chat store
const users = useUsers();         // auto-subscribes to users store
const { client, status } = useConnection({ url, roomId, username });

License

GPL-3.0-only