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

ws-emitter

v1.0.1

Published

**`@packages/ws-emitter`** is a lightweight wrapper around native WebSocket that adds event subscription and automatic reconnection functionality out-of-the-box. It also supports MessagePack decoding (via [`msgpackr`](https://github.com/kriszyp/msgpackr))

Downloads

11

Readme

@packages/ws-emitter

@packages/ws-emitter is a lightweight wrapper around native WebSocket that adds event subscription and automatic reconnection functionality out-of-the-box. It also supports MessagePack decoding (via msgpackr) if needed.

npm version License: MIT npm downloads

✨ Features

  • Simple event-based API
  • Auto-reconnect support with customizable delay
  • Optional MessagePack decoding
  • Manual and automatic connection management
  • Lightweight, no external dependencies (except for optional msgpackr)

Installation

npm install @packages/ws-emitter

or

yarn add @packages/ws-emitter

Quick Start

import { WsEmitter } from '@packages/ws-emitter';

const notifier = new WsEmitter('wss://foo.bar');

notifier.on('open', (event) => console.log('WebSocket open', event));
notifier.on('close', (event) => console.log('WebSocket closed', event));
notifier.on('message', (data) => console.log('Received message', data));
notifier.on('error', (event) => console.error('WebSocket error', event));

// Emit a local event
notifier.emit('custom-event', { foo: 'bar' });

API

new WsEmitter(url: string, options?: OptionsType, isMessagePack?: boolean)

Create a new WebSocket connection with event subscription and optional automatic reconnection.

| Parameter | Type | Default | Description | | --------------- | ------------- | -------------------------------------------------------------------- | ------------------------------------ | | url | string | required | WebSocket server URL | | options | OptionsType | { autoConnect: true, autoReconnect: true, reconnectTimeout: 1000 } | Connection options | | isMessagePack | boolean | false | Enable decoding MessagePack messages |

Example

const notifier = new WsEmitter('wss://foo.bar');

const notifier = new WsEmitter('wss://foo.bar', { autoConnect: false, autoReconnect: true });
notifier.connect();

const notifier = new WsEmitter('wss://foo.bar', { autoConnect: false, autoReconnect: false });
notifier.connect();

instance.connect()

Manually initiate a WebSocket connection.

const notifier = new WsEmitter('wss://foo.bar', { autoConnect: false });
notifier.connect();

instance.close(force?: boolean)

Closes the WebSocket connection. If force is true, auto-reconnection will be disabled temporarily for this closure.

| Parameter | Type | Default | Description | | --------- | --------- | ------- | ------------------------------------ | | force | boolean | false | Prevent auto-reconnect after closing |

Example

notifier.close();
notifier.close(true);

instance.on(eventName: string, callback: (payload: any) => void)

Subscribe to WebSocket or custom events.

Built-in WebSocket events:

  • open
  • close
  • error
  • message

Example

notifier.on('message', (data) => {
  console.log('Received data:', data);
});

notifier.on('open', () => {
  console.log('Connection established!');
});

instance.emit(eventName: string, payload: any)

Trigger a local event manually (client-side only).

Example

notifier.emit('custom-event', { hello: 'world' });

notifier.on('custom-event', (data) => {
  console.log('Custom event received:', data);
});

Note: emit does not send data to the server, it triggers client-side handlers only.


Options

You can configure behavior with the following options:

interface OptionsType {
  autoConnect?: boolean;
  autoReconnect?: boolean;
  reconnectTimeout?: number;
}

| Option | Type | Default | Description | | ------------------ | --------- | ------- | --------------------------------------------- | | autoConnect | boolean | true | Automatically connect after instance creation | | autoReconnect | boolean | true | Automatically reconnect after disconnection | | reconnectTimeout | number | 1000 | Delay (ms) before attempting reconnect |


MessagePack Support

To enable MessagePack decoding for binary WebSocket messages, pass true as the third argument:

const notifier = new WsEmitter('wss://foo.bar', undefined, true);

MessagePack messages will be automatically unpacked using msgpackr.


Events

| Event name | Payload Type | Description | | ---------- | ---------------- | ------------------------------ | | open | WebSocketEvent | Connection successfully opened | | close | WebSocketEvent | Connection closed | | error | WebSocketEvent | Connection error | | message | any | Received message |


Example: Reconnect on Close

const notifier = new WsEmitter('wss://foo.bar');

notifier.on('close', () => {
  console.log('Connection closed, trying to reconnect...');
});

📜 License

Distributed under the MIT License. See LICENSE for more information.

📧 Contact

For support or questions, contact us at @arsenicum32

🙏 Credits

Developed by ARS33 Inspired by modern localization needs Built with ❤️ for the open source community