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

socketly

v1.1.0

Published

A tiny, lightweight WebSocket library with reconnect and event-driven handling.

Downloads

3

Readme

Socketly

Socketly is a tiny, lightweight WebSocket library for TypeScript with built-in reconnect functionality and an event-driven API.

Features

  • 🔄 Automatic reconnection with configurable retries and exponential backoff
  • 🎭 Event-driven API (open, close, message, error, reconnect)
  • 🚀 Minimal and powerful
  • 💪 TypeScript support
  • 🔒 Secure connection handling
  • 📊 Message queueing for offline scenarios
  • 🔍 Detailed logging options

Installation

npm install socketly

Usage

Basic Usage

import { Socketly } from 'socketly'

const ws = new Socketly('wss://echo.websocket.org')

ws.on('open', () => {
  console.log('Connected to WebSocket')
  ws.send({ type: 'greeting', content: 'Hello, WebSocket!' })
})

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

ws.on('close', () => {
  console.log('WebSocket connection closed')
})

ws.on('error', (error) => {
  console.error('WebSocket error:', error)
})

Advanced Usage

import { Socketly } from 'socketly'

const ws = new Socketly('wss://echo.websocket.org', {
  reconnectInterval: 5000,
  maxRetries: 5,
  logger: console.log,
  protocols: ['protocol1', 'protocol2'],
})

ws.on('open', () => {
  console.log('Connected to WebSocket')
  ws.send({ type: 'greeting', content: 'Hello, WebSocket!' })
})

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

ws.on('close', () => {
  console.log('WebSocket connection closed')
})

ws.on('error', (error) => {
  console.error('WebSocket error:', error)
})

ws.on('reconnect', ({ attempt, delay }) => {
  console.log(`Reconnecting... Attempt ${attempt}, Delay: ${delay}ms`)
})

// Using the messages generator
;(async () => {
  for await (const message of ws.messages()) {
    console.log('Received message (via generator):', message)
  }
})()

// Check connection state
console.log('Is connected:', ws.isConnected())
console.log('Connection state:', ws.getState())

// Close the connection after 1 minute
setTimeout(() => {
  ws.close().then(() => console.log('WebSocket closed'))
}, 60000)

API

Socketly

Constructor

new Socketly(url: string, options?: WebSocketOptions)
  • url: The WebSocket server URL to connect to.
  • options: (Optional) Configuration options for the WebSocket connection.
WebSocketOptions
  • reconnectInterval: Time (in ms) between reconnection attempts (default: 3000).
  • maxRetries: Maximum number of reconnection attempts (default: Infinity).
  • logger: Custom logging function (default: console.log).
  • signal: AbortSignal to control the connection externally.
  • protocols: WebSocket sub-protocols to use.

Methods

  • on(event: WebSocketEvent, callback: EventCallback): void: Add an event listener.
  • off(event: WebSocketEvent, callback: EventCallback): void: Remove an event listener.
  • send(data: any): void: Send data to the WebSocket server.
  • close(): Promise<void>: Close the WebSocket connection.
  • messages(): AsyncIterable<any>: Get an async iterator for incoming messages.
  • getState(): number: Get the current WebSocket connection state.
  • isConnected(): boolean: Check if the WebSocket is currently connected.

Events

  • 'open': Fired when the connection is established.
  • 'close': Fired when the connection is closed.
  • 'message': Fired when a message is received.
  • 'error': Fired when an error occurs.
  • 'reconnect': Fired when attempting to reconnect.
  • '*': Fired for all events.