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

@socketrsdk/client

v0.1.0

Published

Browser client SDK for Socketr — real-time WebSocket channels with auto-reconnect

Readme

@socketr/client

Browser client SDK for Socketr — real-time WebSocket channels with public, private, and presence support.

Install

npm install @socketr/client

Quick start

import { SocketrClient } from '@socketr/client'

const client = new SocketrClient('wss://socketr-server.fly.dev/app/pk_...')

client.setAuthProvider(async (channelName, channelData) => {
  const res = await fetch('/api/auth', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ channel_name: channelName, channel_data: channelData }),
  })
  return res.json() // { auth, channel_data? }
})

await client.connect()

Channels

Public

const ch = client.channel('my-channel')
ch.on('my-event', (data) => console.log(data))

Private

const { auth } = await fetchAuth(client.socketId, 'private-room')
const ch = client.channelPrivate('private-room', auth)

Presence

const { auth, channel_data } = await fetchAuth(client.socketId, 'presence-room', userId, userInfo)
const ch = client.channelPresence('presence-room', auth, channel_data)

ch.on('member_added', ({ user_id, user_info }) => console.log('joined:', user_id))
ch.on('member_removed', ({ user_id }) => console.log('left:', user_id))

console.log(ch.members)      // PresenceMember[]
console.log(ch.memberCount)  // number

Broadcasting

client.broadcast('my-channel', 'my-event', { message: 'hello' })

Lifecycle events

client.addEventListener('connected',    (e) => console.log('socket id:', e.detail.socketId))
client.addEventListener('reconnecting', (e) => console.log('attempt', e.detail.attempt, 'in', e.detail.delayMs, 'ms'))
client.addEventListener('reconnected',  (e) => console.log('back online'))
client.addEventListener('disconnected', () => console.log('closed'))

Auto-reconnect

The client reconnects automatically with exponential backoff (1s → 30s max) on any unexpected close. When setAuthProvider is registered, private and presence channels are transparently re-authenticated and re-subscribed after every reconnect — no extra code needed.

API

new SocketrClient(wsUrl)

| Method | Description | |---|---| | connect() | Opens the WS connection. Returns Promise<this>. | | setAuthProvider(fn) | Registers the auth callback for private/presence channels. | | channel(name) | Subscribe to a public channel. | | channelPrivate(name, auth) | Subscribe to a private-* channel. | | channelPresence(name, auth, channelData) | Subscribe to a presence-* channel. | | broadcast(channel, event, data?) | Send an event via the open WS connection. | | unsubscribe(channel) | Unsubscribe from a channel. | | disconnect() | Gracefully close (no auto-reconnect). | | socketId | Current socket ID (available after connect). | | connected | true when the WS is open. |

Channel

| Member | Description | |---|---| | on(event, fn) | Listen for an event. Use "*" to catch all events. | | off(event, fn?) | Remove a listener (or all listeners for the event). | | members | PresenceMember[] — presence channels only. | | memberCount | Number of present members. |