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

@lunibee/ws

v0.4.0

Published

> Discord Gateway (WebSocket) connection manager for the lunibee ecosystem.

Readme

@lunibee/ws

Discord Gateway (WebSocket) connection manager for the lunibee ecosystem.

Lunibee uses a single-connection Gateway (sharding lives in @lunibee/sharding). It exposes a familiar surface (opcodes, close codes, lifecycle) while keeping Lunibee's canonical names.

bun add @lunibee/ws

Basic use

import { Gateway } from "@lunibee/ws";
import { GatewayIntentBits } from "@lunibee/types";

const gateway = new Gateway({
    token: process.env.TOKEN!,
    intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
});

gateway.on("ready", (data) => console.log("Ready", data));
gateway.on("resumed", () => console.log("Resumed"));
gateway.on("close", (data) => console.log("Closed", data)); // { code, action }
gateway.on("error", (err) => console.error(err));

await gateway.connect(); // resolves once the socket opens

Every dispatch is also emitted under its Discord name (READY, MESSAGE_CREATE, …), plus RAW, open, close, error, stateChange, heartbeatAck, invalidSession and zombie.

Exports

| Export | Kind | Notes | |---|---|---| | Gateway | class | Canonical connection manager. | | GatewayOpcodes | const | Discord opcode names → values. | | GatewayCloseCodes | const | Discord close-code names → values (AuthenticationFailed = 4004, InvalidSeq = 4007, …). | | GatewayState | enum | Lunibee lifecycle states. | | Status | alias | Alias of GatewayState. Values stay Lunibee strings. | | GatewayError | class | Thrown/emitted on gateway failures. | | GatewayOptions | interface | Connection config (compress, shardId/shardCount, reconnect tuning, createSocket). |

Lifecycle behaviour

  • Heartbeats with initial jitter, ACK tracking, and a stale-ACK / zombie close guard.
  • Reconnect with exponential backoff + jitter (reconnectBaseDelay, reconnectMaxDelay, maxReconnectAttempts).
  • Resume vs re-identify is chosen from the close/opcode:
    • INVALID_SESSION with d: true → keeps the session and RESUMEs; d: false → clears it and re-IDENTIFYs against the main Gateway.
    • 4007/4009 → fresh IDENTIFY; 4004/4010–4014 → fatal, stops reconnecting.
  • A successful RESUMED resets the reconnect backoff and emits resumed.
  • Send budget: application sends are capped at 115 per 60 s; heartbeats, IDENTIFY and RESUME always go out.
  • Compression: compress: true decodes Discord's zlib-stream in arrival order.

Internally the gateway is split into transport, heartbeat, session, reconnect, protocol, decoder and send-budget modules.

What's new in 0.2.0

Reconnects that should resume close with 4900 (never 1000/1001), the heartbeat interval starts after the first jittered beat, and a lower sequence can never roll back the resume point.