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

stream-server

v0.5.1

Published

A stream server in the browser

Readme

stream-server

A stream server in the browser

Create streaming servers in your browser. Emulating peer to peer connections through a central proxy server

Example browser server (In a seperate browser)

var StreamServer = require("browser-stream-server")
    , boot = require("boot")
    , mdm = boot("/boot")

// Open a Stream server and listen on a server name
StreamServer(mdm, function (stream) {
    // Called every time a client opens up a stream connection to you
    stream.on("data", function (data) {
        console.log("[SERVER]", data)
    })
    stream.write("from server")
}).listen("SERVER_NAME")

Example browser client (In a seperate browser)

var StreamClient = require("browser-stream-server")
    , boot = require("boot")
    , mdm = boot("/boot")

// Open a connection to a named stream server
var stream = StreamClient(mdm).connect("SERVER_NAME")
stream.on("data", function (data) {
    console.log("[CLIENT]", data)
})
stream.write("from client")

Example proxy server

var boot = require("boot")
    , StreamServerProxy = require("browser-stream-server")
    , StreamRouter = require("stream-router")

// route stream traffic from boot through a stream router
var streamRouter = StreamRouter()
    , sock = boot(streamRouter)

// for every request to /browser-server let the StreamServer proxy handle it
streamRouter.addRoute("/browser-server/*"
    , StreamServerProxy("/browser-server"))

sock.install(someHttpServer, "/boot")

Motivation

This a pre-runner to real P2P experiments that will be done once we can create data channels with WebRTC

This is the smallest piece necessary to spawn arbitary stream servers in browsers.

Documentation

StreamClient(mdm, options).connect(serverName)

To be used in the browser

var StreamClient = require("browser-stream-server")
var stream = StreamClient(mdm).connect("SERVER_NAME")

Returns a stream connection to that server name. It assumes the server is running somewhere else. If it's not then the stream is closed.

The mdm value is a MuxDemux stream. This can be got from mux-demux, mux-demux-shoe or boot.

options include a prefix option which allows you to set a custom prefix if the StreamServerProxy uses a custom prefix.

StreamServer(mdm, options, callback).listen(serverName)

To be used in the browser

var StreamServer = require("browser-stream-server")
var server = StreamServer(mdm, options, function (stream) {
    // handle stream
}).listen("SERVER_NAME")

Creates a server stream connection. It assumes that named server is not already running somewhere else. If it is then the stream is closed.

The mdm value is a MuxDemux stream. This can be got from mux-demux, mux-demux-shoe or boot.

options are optional, you can pass a callback as the second parameter. The callback get's called every time someone else calls .connect(serverName) and you get passed a stream connection to them

options include a prefix option which allows you to set a custom prefix if the StreamServerProxy uses a custom prefix.

To close the server just .end() the returned server

StreamServerProxy(prefix)

To be used in the server

var StreamServerProxy = require("browser-stream-server")
    , proxy = StreamServerProxy("/somePrefix")
// for every request to /browser-server let the StreamServer proxy handle it
streamRouter.addRoute("/somePrefix/*", proxy)

Set up a steam route handler to allow the stream servers and clients to be proxied through your central server.

Optionally pass in a prefix which defaults to "/browser-server". If you pass in a different prefix make sure that your browser code matches the prefix.

proxy events

The returned proxy object emits server-created and server-destroyed events when a server stream connects and claims to own the SERVER_NAME

proxy.on("server.created", function (serverName) {
    createSomeSpecialResources(serverName)
})

proxy.on("server.destroyed", function (serverName) {
    destroySpecialResources(serverName)
})

proxy.connect("serverName")

var stream = proxy.connect(serverName)

You can manually connect directly to a stream server. This runs similar logic to StreamClient(...).connect(serverName)

How it works

When you call StreamServer(...).listen(SERVER_NAME) you open a server stream to the StreamServerProxy and tell the server "redirect all connect SERVER_NAME traffic to me"

When you call StreamClient(...).connect(SERVER_NAME) you open a client stream to the StreamServerProxy saying "connect me to SERVER_NAME". The StreamProxyServer then sends a message to StreamServer identified by SERVER_NAME. The message contains a unique identifier, UNIQUE_ID for this client stream. The proxy server stores this client stream in memory.

The StreamServer receives this message and opens another connection to the StreamServerProxy saying "hi I'm server SERVER_NAME and want to connect to client UNIQUE_ID". The StreamServerProxy then gets the client stream out of memory and connects it to the new server connection which allows the client to talk to the server

Installation

npm install browser-stream-server

Contributors

  • Raynos

MIT Licenced