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

@seamos/websocket

v0.1.1

Published

Simple WebSocket utilities for SeamOS (JavaScript only)

Readme

@seamos/websocket

Small, dependency-free helpers that wrap the browser WebSocket with auto reconnect, dynamic port selection (manual or CCU-provided), and JSON-friendly utilities. Ships as both ESM and CommonJS bundles for seamless use in modern build pipelines.

Features

  • Create resilient sockets that retry after unexpected disconnects
  • Resolve ports manually or by querying a CCU endpoint with automatic fallback
  • Hook into all native WebSocket events without re-writing boilerplate
  • Send JSON payloads safely and close sockets defensively
  • Written in plain JavaScript so it runs anywhere a browser-like WebSocket exists

Installation

npm install @seamos/websocket

Quick Start

Manual Port Connection

import { createWebSocketClient, sendJson, closeWebSocketSafe } from "@seamos/websocket";

const client = createWebSocketClient("ws://192.168.0.10/socket", {
  useCCUPort: false,
  manualPort: 8080,
  autoReconnect: true,
  reconnectInterval: 3000,
  events: {
    open: () => console.log("connected"),
    message: (event) => console.log("message", event.data),
    close: () => console.log("socket closed"),
  },
});

sendJson(client.socket, { type: "ping" });
closeWebSocketSafe(client.socket, 1000, "done");

CCU-Based Port Resolution

const client = createWebSocketClient("ws://192.168.0.10/ws", {
  useCCUPort: true,
  defaultPort: 1456,
  ccuPortEndpoint: "get_assigned_ports",
  autoReconnect: true,
});

The CCU endpoint should respond with a JSON object mapping the defaultPort to the assigned port, for example { "1456": 9000 }. The client automatically falls back to defaultPort when the lookup fails.

API

createWebSocketClient(baseUrl, options)

Creates and immediately connects a WebSocket using the provided base URL (host + path without port). Returns an object with two properties:

  • socket: the latest WebSocket instance (or null until connected)
  • close(code?, reason?): manually closes the socket and stops auto reconnect

options (all optional):

  • protocols: string or string[] passed to the native constructor
  • events: { open, message, close, error } listeners invoked when events fire
  • autoReconnect: true to retry after unexpected closures (default false)
  • reconnectInterval: delay in ms between retries (default 3000)
  • useCCUPort: true to fetch the port from a CCU endpoint
  • defaultPort: base/fallback port and lookup key (default 1456)
  • ccuPortEndpoint: URL used when resolving the CCU port (default "get_assigned_ports")
  • manualPort: number to use when useCCUPort is false (required in that case)

Errors early when neither useCCUPort nor manualPort provide a valid port configuration.

sendJson(socket, payload)

Serializes the payload and sends it through an open socket. Throws if the socket is null or not in the OPEN state.

closeWebSocketSafe(socket, code?, reason?)

Closes the socket only when it exists and is not already closing/closed.

isProperJson(payload)

Returns true if the input is already an object or a JSON string that can be parsed into an object. Useful for quick payload guards.

License

MIT