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

@sejatordev/ws-client-node

v1.0.0

Published

WebSocket client khusus **Node.js (server-to-server)** dengan konsep **channel-based** (mirip Pusher), dirancang untuk:

Readme

@sejator/ws-client-node

WebSocket client khusus Node.js (server-to-server) dengan konsep channel-based (mirip Pusher), dirancang untuk:

  • Worker / background service
  • Backend service listener
  • Microservice real-time
  • Bot / automation
  • Internal event consumer

🔒 Tidak untuk browser
Package ini hanya berjalan di Node.js runtime.


✨ Fitur

  • 🔌 Auto connect & auto reconnect
  • 🔁 Manual reconnect
  • ❤️ Heartbeat + pong timeout
  • 📡 Channel & event system
  • 🔄 Auto re-subscribe saat reconnect
  • 🔐 Private & presence channel (HMAC server-side)
  • 🧠 Fully typed (TypeScript)
  • 🌐 URL auto normalize (http → ws, /ws)

🔗 SDK Resmi untuk @sejator/ws-server

@sejator/ws-client-node adalah SDK resmi backend untuk:

Kompatibel penuh dengan:

  • Channel protocol
  • Event format
  • Private channel auth (APP_KEY:signature)
  • Heartbeat & reconnect strategy

Tidak ditujukan untuk WebSocket server lain


🏗️ Arsitektur

Backend Service / Worker
        │
        │  @sejator/ws-client-node
        ▼
WebSocket Protocol (Channel-based)
        │
        │  @sejator/ws-server
        ▼
Main Application / API

📦 Instalasi

git clone https://github.com/sejator/ws-client-node.git
cd ws-client-node
npm install
npm run build

⚙️ Environment Variable

WS_APP_KEY=your_app_key
WS_APP_SECRET=your_app_secret
WS_APP_URL=http://localhost:3000

🚀 Penggunaan Dasar

import "dotenv/config";
import { WSClient } from "@sejator/ws-client-node";

const client = new WSClient(process.env.WS_APP_URL!, {
  key: process.env.WS_APP_KEY!,
  secret: process.env.WS_APP_SECRET!,
  logger: true,
});

client.on("connect_success", ({ socket_id }) => {
  console.log("Connected:", socket_id);
});

const channel = client.subscribe("orders");

channel.bind("order.created", (payload) => {
  console.log("Order created:", payload);
});

🔐 Private Channel (Server Auth Otomatis)

Tidak perlu authEndpoint atau HTTP request.

SDK akan menghasilkan HMAC signature secara lokal.

const privateChannel = client.subscribe("private-orders");

privateChannel.bind("order.updated", (data) => {
  console.log("Order updated:", data);
});

Cara Kerja Signature

Signature dibuat dengan format:

HMAC_SHA256(APP_SECRET, `${socketId}:${channel}`)

Lalu dikirim ke server sebagai:

APP_KEY:signature_hash

🧩 Custom Signature Utility (Opsional)

Jika ingin kontrol manual:

import { generateAuthString } from "./utils/signature";

auth: async ({ socketId, channel }) => {
  return {
    auth: generateAuthString(socketId, channel, process.env.WS_APP_KEY!, process.env.WS_APP_SECRET!),
  };
};

🔌 Client Options

interface WSClientNodeOptions {
  key: string; // APP_KEY (required)
  secret: string; // APP_SECRET (required)

  logger?: boolean;
  reconnect?: boolean;
  maxReconnectDelay?: number;
}

📌 Tidak tersedia di versi Node

  • ❌ Cookie
  • ❌ CSRF
  • ❌ authEndpoint
  • ❌ Browser headers

📡 Event Client

| Event | Payload | Deskripsi | | --------------- | --------------------------------- | ------------------ | | connect_success | { socket_id, activity_timeout } | Koneksi berhasil | | disconnected | void | Koneksi terputus | | reconnecting | { manual: boolean } | Reconnect dimulai | | auth_failed | string | Auth channel gagal | | state_change | { previous, current } | State transition | | error | unknown | Error WebSocket |


🔁 Manual Reconnect

client.reconnect();

❤️ Heartbeat & Pong Timeout

  • Client mengirim ping
  • Server membalas pong
  • Timeout → reconnect otomatis

🌐 URL Normalization

Input:

new WSClient('http://localhost:3000', {...})

Akan menjadi:

ws://localhost:3000/ws

Didukung:

  • http / https
  • ws / wss
  • tanpa protocol

🔐 Kapan Menggunakan ws-client vs ws-client-node?

| Use Case | Package | | ------------------------ | ------------------------- | | Browser / Frontend | @sejator/ws-client | | Next.js Client Component | @sejator/ws-client | | Backend / Worker / Bot | @sejator/ws-client-node | | Server-to-server | @sejator/ws-client-node |


⚠️ Security Notes

  • JANGAN gunakan ws-client-node di browser
  • APP_SECRET hanya untuk server
  • Pastikan channel private divalidasi di server

Kontak & Dukungan

Maintainer: @sejator
Email: [email protected]
Donasi: https://saweria.co/sejator