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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ribcage/websocket

v1.0.0

Published

Unified WebSocket client for Ribcage applications

Downloads

6

Readme

@ribcage/websocket

Typed WebSocket client package for Ribcage applications, providing clean APIs for mobile and dashboard clients with full type safety.

Features

  • Type Safety: Full TypeScript support with Zod schema validation
  • Clean APIs: Separate optimized clients for mobile and dashboard use cases
  • Connection Management: Automatic reconnection, health monitoring, and message queuing
  • Client Management: Track connected clients and manage multiple connections
  • Message Validation: Automatic payload parsing and validation

Installation

bun add @ribcage/websocket

Usage

Mobile Client

Simple API for mobile apps that broadcast to all dashboards:

import { MobileWebSocketClient } from "@ribcage/websocket";

const mobileClient = new MobileWebSocketClient({
  host: "localhost",
  port: 8080,
  clientId: "mobile-device-1",
  onMessageReceived: (payload) => {
    console.log("Received:", payload);
  }
});

await mobileClient.connect();

// Send typed messages
await mobileClient.sendMessage("MEMORY_UPDATE", {
  ramUsageInMB: 512,
  deviceId: "phone-1"
});

// Or use convenience methods
await mobileClient.sendMemoryUpdate(512, "phone-1");
await mobileClient.sendCpuUpdate(45.2, "phone-1");
await mobileClient.sendFpsUiUpdate(60, "phone-1");

Dashboard Client

Multi-source client for dashboards that can send to specific targets:

import { DashboardWebSocketClient } from "@ribcage/websocket";

const dashboardClient = new DashboardWebSocketClient({
  host: "localhost", 
  port: 8080,
  clientId: "dashboard-1",
  onMessageReceived: (from, payload) => {
    console.log(`Message from ${from}:`, payload);
  },
  onClientConnected: (client) => {
    console.log("Client connected:", client);
  }
});

await dashboardClient.connect();

// Send to specific mobile client
await dashboardClient.sendToClient("mobile-device-1", "CPU_UPDATE", {
  cpuUsage: 25.5
});

// Broadcast to all mobile clients
await dashboardClient.broadcastToMobileClients("MEMORY_UPDATE", {
  ramUsageInMB: 1024
});

// Get connected clients
const clients = dashboardClient.getClients();
const mobileClients = dashboardClient.getClientsByType("mobile");

Configuration

interface WebSocketConfig {
  host: string;                    // WebSocket server host
  port: number;                    // WebSocket server port
  reconnectInterval: number;       // Reconnection attempt interval (ms)
  pingInterval: number;            // Ping interval for health checks (ms)
  pongTimeout: number;             // Pong timeout (ms)
}

const config: Partial<WebSocketConfig> = {
  host: 'localhost',
  port: 9001,
  reconnectInterval: 5000,
  pingInterval: 30000,
  pongTimeout: 5000,
};

API Reference

WebSocketDashboardClient

  • initialize(): Initialize the client and start WebSocket server (Tauri)
  • disconnect(): Disconnect from the server
  • sendToClient(clientId, payload): Send message to specific client
  • broadcast(payload): Broadcast message to all connected clients
  • getConnectedClients(): Get list of connected clients
  • getConnectionState(): Get current connection state
  • subscribe(callback): Subscribe to connection state changes

WebSocketMobileClient

  • connect(): Connect to the WebSocket server
  • disconnect(): Disconnect from the server
  • sendMessage(payload): Send a message
  • sendEvent(eventType, data): Send a typed event
  • sendToClient(clientId, payload): Send message to specific client
  • broadcast(payload): Broadcast message to all clients
  • getConnectionState(): Get current connection state

React Hooks

  • useWebSocket(options): Dashboard WebSocket hook
  • useMobileWebSocket(options): Mobile WebSocket hook
  • useWebSocketMessages(): Message management hook
  • useConnectedClients(): Connected clients management hook

Architecture

The package is organized into several layers:

  • Core: Base WebSocket functionality (connection, health monitoring, message handling)
  • Clients: Platform-specific implementations (Dashboard, Mobile)
  • Hooks: React integration layer

This architecture ensures code reuse while allowing for platform-specific optimizations and features.

License

MIT