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

effect-websocket

v1.0.1

Published

Runtime-agnostic WebSocket library for Effect-TS with client/server support, automatic reconnection, and cross-platform compatibility (Node.js, Bun, Browser)

Downloads

10

Readme

Effect WebSocket Core

CI npm version License: MIT Node.js Version Bun Version

Runtime-agnostic WebSocket library for Effect-TS with client/server support, automatic reconnection, and cross-platform compatibility (Node.js, Bun, Browser).

Overview

The core package provides TypeScript interfaces, types, and runtime-agnostic implementations for WebSocket functionality. It defines the contracts that platform-specific implementations must fulfill.

Features

  • Runtime Agnostic: Pure TypeScript interfaces and types
  • WebSocket Client: Full-featured client with automatic reconnection
  • WebSocket Server: Server interface for handling connections
  • Effect Integration: Built on Effect-TS for functional error handling
  • Streaming: Message and event streams using Effect's Stream API
  • Type Safety: Full TypeScript support with comprehensive type definitions

Installation

bun add effect-websocket effect @effect/platform

Quick Start

Client Usage

import { Effect, Stream } from "effect"
import { WebSocketClient } from "effect-websocket"
// Import platform-specific implementation
import { makeWebSocketClient } from "effect-websocket-node" // or "effect-websocket-bun"

const program = Effect.scoped(
  WebSocketClient.withClient("ws://localhost:8080", (client) =>
    Effect.gen(function* () {
      // Send a message
      yield* client.send("Hello!")

      // Listen for messages
      yield* Stream.runForEach(client.messages, (message) => {
        console.log("Received:", message)
        return Effect.succeed(undefined)
      })

      yield* Effect.never
    })
  )
)

Effect.runPromise(program)

Server Usage

import { Effect, Stream } from "effect"
import { WebSocketServer } from "effect-websocket"
// Import platform-specific implementation
import { makeWebSocketServer } from "effect-websocket-node" // or "effect-websocket-bun"

const program = Effect.scoped(
  makeWebSocketServer({ port: 8080 }, (server) =>
    Effect.gen(function* () {
      console.log("WebSocket server started on port 8080")

      // Handle new connections
      yield* Stream.runForEach(server.connections, (connection) => {
        console.log("New connection:", connection.id)

        // Handle messages from this connection
        return Stream.runForEach(connection.messages, (message) => {
          console.log(`Message from ${connection.id}:`, message)

          // Echo the message back
          return connection.send(`Echo: ${message}`)
        })
      })

      yield* Effect.never
    })
  )
)

Effect.runPromise(program)

API Overview

WebSocketClient

Static Methods:

  • WebSocketClient.make(url, protocols?, reconnectionOptions?): Create a WebSocket client
  • WebSocketClient.withClient(url, protocols?, f, reconnectionOptions?): Create and use a WebSocket client with automatic cleanup

Instance Methods:

  • send(message): Send a message (string or binary)
  • messages: Stream of incoming messages
  • events: Stream of WebSocket events (open, close, error, message, reconnecting, reconnect_failed)
  • close(): Close the connection
  • readyState: Current connection state
  • isReconnecting: Check if currently attempting reconnection
  • reconnectAttempts: Get number of reconnection attempts made

WebSocketServer

Static Methods:

  • WebSocketServer.make(options): Create a WebSocket server
  • WebSocketServer.withServer(options, f): Create and use a WebSocket server with automatic cleanup

Instance Methods:

  • connections: Stream of new connections
  • messages: Stream of messages from all connections (with connectionId)
  • close(): Close the server

Platform Implementations

Choose the appropriate platform implementation:

  • Node.js: effect-websocket-node - Uses the ws library
  • Bun: effect-websocket-bun - Uses Bun's native WebSocket API
  • Browser: Use client-only functionality with browser WebSocket API

Examples

See the examples/ directory for complete working examples:

  • client.ts: Basic client usage
  • server.ts: Basic server usage
  • advanced-client.ts: Client with reconnection and error handling
  • binary-data.ts: Handling binary messages

Documentation

License

MIT