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

@synet/realtime

v0.1.0

Published

Realtime Communication server/client implementations

Readme

@synet/realtime

Real-time communication implementations of @synet/patterns interfaces for seamless client-server communication across different transport protocols.

This package offers concrete implementations of the abstract real-time communication patterns defined in @synthetism/patterns, allowing you to build robust real-time applications with minimal boilerplate.

Available Implementations

Client

  • NATS - High-performance message broker implementation with reliable delivery and persistence
  • WebSocket - Standard WebSocket implementation for broad compatibility and easy browser integration
  • GUN - Decentralized peer-to-peer database implementation for offline-first applications

Server

  • NATS - Server-side implementation with topic-based routing and client tracking
  • WebSocket - Standard WebSocket server with subscriptions and broadcast capabilities
  • GUN - Peer-to-peer node implementation that acts as both a server and sync point

Quick Start

Setting up a client

import { createNatsClient } from "@synet/realtime";
import { GatewayRealtimeClient } from "./infrastructure/services/gateway-realtime-client";

// Configure connection
const natsUrl = process.env.NATS_URL || "nats://localhost:4222";
const provider = createNatsClient(
  natsUrl,
  {
    reconnect: {
      enabled: true,
      maxAttempts: 5,
    },
    transportOptions: {
      user: process.env.NATS_USER,
      password: process.env.NATS_PASSWORD,
      debug: true,
    },
  }
);

// Create and export client
export const client = new GatewayRealtimeClient(provider);

Subscribing to events

Method 1: Using Channel API

// Subscribe to a topic
const channel = client.subscribe("users");

// Listen for specific event types
channel.on<GatewayEvent>("users.created", (event: GatewayEvent) => {
  console.log("Event received on users.created channel:", event);
  analyticsService.update(event);
});

Method 2: Using EventEmitter API

// Direct subscription to event emitter
client.getEventEmitter().subscribe("users.updated", {
  update: (event) => {
    console.log("Direct EventEmitter subscription fired:", event);
    analyticsService.update(event);
  }
});

// Subscribe to multiple events
client.getEventEmitter().subscribe("notifications.notification", {
  update: (event) => {
    console.log("Notification received:", event);
  }
});

Setting up a server

import { WebSocketRealtimeServer } from "@synet/realtime";

// Create server instance
const server = new WebSocketRealtimeServer({
  transportOptions: {
    port: 3030,
    host: "0.0.0.0"
  }
});

// Start the server
await server.start();

// Listen for client connections
server.on("client.connected", (data) => {
  console.log("Client connected:", data);
});

// Broadcast events to subscribed clients
server.broadcast("users", {
  id: crypto.randomUUID(),
  type: "users.created",
  source: "server",
  timestamp: new Date(),
  data: { 
    id: "user-123", 
    name: "Jane Doe",
    email: "[email protected]"
  }
});

Development Status

These implementations are functional and provide working client-server communication capabilities. All client types can communicate with their corresponding server types successfully. However, the library is still in an early stage of development and the APIs may evolve as we refine patterns and add new features.

License

MIT