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

longhouse

v4.4.0

Published

A service for establishing and sharing user presence

Readme

Longhouse Circle CI

A user presence service.

Deploy

Prerequisites

  • nvm
  • Redis v3.0.2

Install

# Assumes Redis is already running locally on port 6379
git clone [email protected]:usecanvas/longhouse.git
cd longhouse
nvm install
nvm use
npm run bootstrap
npm run dev

Use

Longhouse tracks user presence as soon as they connect. To connect to space in Longhouse, open a WebSocket connection to a URL like:

wss://longhouse.example.com/[email protected]

After joining, the client will quickly receive a message with the current clients connected to the space:

{
  "id": "123",
  "clients": [
    { "id": "123", "identity": "[email protected]", "spaceID": "space_uuid", "joinedAt": "2015-06-05T21:09:26.480Z" },
    { "id": "456", "identity": "[email protected]", "spaceID": "space_uuid", "joinedAt": "2015-06-05T21:09:28.493Z" }
  ]
}

Reconnecting

In the event of a disconnection by Longhouse, a client can attempt to reconnect with a former "id". This ensures that as long as their old presence lease has not expired, they will not appear to have left and re-joined the room.

This is useful in handling sudden process restarts.

wss://longhouse.example.com/[email protected]&id=123

Actions

ping

Sending this action will renew the client's presence lease.

This is currently the only action that should be sent to Longhouse. It needs to be sent less frequently than the value of $PRESENCE_TTL (in milliseconds).

{"action": "ping"}

Remote Events

When relevant events happen on remote clients, Longhouse will send a message to each client connected to the space where the event occurred.

remote join

A client has joined the space.

{
  "event": "remote join",
  "client": { "id": "456", "identity": "[email protected]", "spaceID": "space_uuid", "joinedAt": "2015-06-05T21:09:28.493Z" }
}

remote leave

A client has left the space (either by expiration or closing their connection).

{
  "event": "remote leave",
  "client": { "id": "456", "identity": "[email protected]", "spaceID": "space_uuid", "joinedAt": "2015-06-05T21:09:28.493Z" }
}

Configuration (environvment variables)

  • $PRESENCE_TTL The time (in ms) after which client presence will automatically expire
  • $REDIS_URL The URL to a Redis server that supports keyspace notifications
  • $REDISCLOUD_URL A URL pointing to a RedisCloud server that will override $REDIS_URL if it exists

Errors

When an error occurs that is relevant to the client, an error message will be sent in this format:

{ "error": "Error message" }

An error may or may not result in Longhouse terminating the socket connection.

How does it work?

Longhouse is extremely simple. When a user joins, it sets a key in Redis with the format longhouse/spaces/${spaceID}/${clientUUID}/${userIdentity}/${joinedAt} with a value of the user identity.

These keys have a default expire time of 60 seconds.

In order to determine who is present in a given space, Longhouse just gets every key that matches the pattern longhouse/spaces/${spaceID}.*. The user identity for each present user is in the key itself, and the values are only used for testing purposes.

Testing

The unit tests can be run with npm test. A Redis server must be running, but be aware that the tests will call FLUSHDB after every test.

Another useful tool for testing is wscat:

npm i -g wscat

Then, one can connect to Longhouse using wscat once they've started the server:

# Terminal 1
wscat -c ws://localhost:5000/[email protected]
>
  < {"clients": [
      { "id": "123", "identity": "[email protected]", "spaceID": "space-id", "joinedAt": "2015-06-05T21:09:26.480Z" }
    ]

# Terminal 2
wscat -c ws://localhost:5000/[email protected]
>
  < {"clients": [
      { "id": "123", "identity": "[email protected]", "spaceID": "space-id", "joinedAt": "2015-06-05T21:09:26.480Z" },
      { "id": "456", "identity": "[email protected]", "spaceID": "space-id", "joinedAt": "2015-06-05T21:09:28.493Z" }
    ]