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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@eleven-am/pondsocket-express

v0.0.38

Published

PondSocket is a fast simple socket server

Downloads

217

Readme

PondSocket Express Integration

This package provides seamless integration of PondSocket with Express, allowing you to add high-performance, bidirectional WebSocket endpoints to your Express applications with minimal effort.

Installation

Install the Express adapter alongside PondSocket:

npm install @eleven-am/pondsocket @eleven-am/pondsocket-express

Overview

This package exposes a function that takes your Express app and PondSocket options, and returns the app with additional methods for real-time socket communication:

  • createEndpoint(path, handler): Define a WebSocket endpoint on your Express app.
  • listen(...): Start the HTTP server and WebSocket server together.

Server-side Usage

import express from "express";
import pondSocket from "@eleven-am/pondsocket-express";

const app = express();

const pondApp = pondSocket(app, {
  // PondSocket options (except 'server')
});

// Create a WebSocket endpoint
const endpoint = pondApp.createEndpoint('/api/socket', (ctx, next) => {
  const token = ctx.request.query.token;
  if (isValidToken(token)) {
    ctx.accept({ role: getRoleFromToken(token) });
  } else {
    ctx.reject('Invalid token', 401);
  }
});

// Create a channel
const channel = endpoint.createChannel('/channel/:id', (ctx, next) => {
  const { role } = ctx.user.assigns;
  const { username } = ctx.joinParams;
  if (role === 'admin') {
    ctx.accept({ username }).trackPresence({
      username,
      role,
      status: 'online',
      onlineSince: Date.now(),
    });
  } else {
    ctx.decline('Insufficient permissions', 403);
  }
});

// Start the server
pondApp.listen(3000);

Client-side Usage

The client API is unchanged—use @eleven-am/pondsocket-client as described in the main PondSocket documentation.

import PondClient from "@eleven-am/pondsocket-client";

const socket = new PondClient('ws://your-server/api/socket', {
  token: 'your-auth-token'
});
socket.connect();

const channel = socket.createChannel('/channel/123', { username: 'user123' });
channel.join();
channel.broadcast('message', { text: 'Hello, PondSocket!' });

Key Features

  • Express Integration: Add real-time endpoints to your existing Express app.
  • Simple and Efficient API: Easy-to-use, type-safe API for WebSocket communication.
  • Organized Channels: Group users and manage communication efficiently.
  • Assigns: Store private information for users and channels.
  • Presence: Track and broadcast user state changes.
  • Broadcasting: Send messages to all or specific users.
  • Middleware Support: Extensible request processing.
  • Distributed Support: Built-in distributed deployment with state sync.

Advanced Features

Presence Management

// Server-side
channel.onEvent('presence', (ctx, next) => {
  ctx.trackPresence({
    username: ctx.user.assigns.username,
    status: 'online',
    lastSeen: Date.now()
  });
});

// Client-side
channel.onPresence((presences) => {
  console.log('Current users:', presences);
});

User Assigns

// Server-side
channel.onEvent('update-profile', (ctx, next) => {
  ctx.assign({
    ...ctx.user.assigns,
    profile: ctx.event.payload
  });
});

// Client-side
channel.onAssigns((assigns) => {
  console.log('User data updated:', assigns);
});

Error Handling

// Server-side
channel.onEvent('message', (ctx, next) => {
  try {
    ctx.accept();
  } catch (error) {
    ctx.decline(error.message, 400);
  }
});

// Client-side
channel.onError((error) => {
  console.error('Channel error:', error);
});

Distributed Deployment

PondSocket supports distributed deployment through its distributed backend system. This allows you to scale your application across multiple nodes while maintaining state synchronization.

import express from "express";
import pondSocket from "@eleven-am/pondsocket-express";
import { RedisBackend } from "@eleven-am/pondsocket";

const app = express();

const pondApp = pondSocket(app, {
  backend: new RedisBackend({
    host: 'localhost',
    port: 6379
  }),
  // ...other PondSocket options
});

// Now use pondApp.createEndpoint(...) as usual

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.