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 🙏

© 2024 – Pkg Stats / Ryan Hefner

matchmaker-redis

v1.1.1

Published

A module that helps users join some kind of social event such as a multiplayer game.

Downloads

12

Readme

A Node.js module that helps users create, find, and join "events" such as a multiplayer game. You may think of this as a matchmaking lobby backend.

Concepts

  • Events are created by users.
  • Users join events.
  • Events have a required capacity.
    • Events start when the event is at capacity.
  • Events have a whitelist and a blacklist of users.
    • If there's a whitelist, only users on the whitelist may join the event.
    • If there's a blacklist, any user on the blacklist may not join the event.
  • No user may join an event after the event has started.
  • A user may fetch events with which they are somehow involved (created, whitelisted, joined)
  • The creator of an event may cancel a pending event.
    • Active/started events may not be canceled.
  • The system auto-cancels or expires events that fail to start after some time.
    • The larger the capacity, the more time the event has to start before auto-cancellation.
  • A user may autojoin a compatible, pending event.
    • Same desired capacity and event parameters
  • An event's params is encoded as a string and can contain anything.
    • This might encode a desired rules-of-play for a game for instance.

Runtime Dependencies

A running Redis instance.

Installation

npm i --save matchmaker-redis

Usage

const Redis = require('ioredis')
const redis = new Redis(process.env.REDIS_URL)
const matchmaker = require('matchmaker-redis')(redis)
matchmaker.createEvent(...)

API

An event looks like this:

event = {
  id: string,
  capacity: int,
  params: string,
  userIds: [string],
  userAliases: [string],
  startedAt: int
}

Create an event and wait for others to join it.

createEvent({
  userId: string,
  userAlias: string,
  capacity: int,
  params: string,
  perUserTimeoutSec: int,
  whitelist: [string],
  blacklist: [string],
}) -> Promise(event)

Find a pending event with the given params and user count and join it.

autojoinEvent({
  userId: string,
  userAlias: string,
  capacity: int,
  params: string,
}) -> Promise(event)

The creator may cancel an event before it auto-expires.

cancelEvent(userId, eventId) -> Promise(true)

Get the pending and active events the user has created, joined, or been whitelisted on.

getEventsFor(userId) -> Promise({
  active: [event],
  pending: [event]
})

Join a specific event. Usually in response to a user seeing that they are on a whitelist.

joinEvent(userId, userAlias, eventId) -> Promise(event)

PUBSUB Side Effects

When a user joins an event, a JSON message is published to channel events/${event.id}.

{ "type": "join",
  "userId": string,
  "userAlias": string }

When an event is canceled, a message is published to channel events/${event.id}.

{ "type": "cancel" }

Notes

Uses Redis for event coordination and storage but is not associated with any particular transport (HTTP, WebSockets, etc).

Running Tests

Note that the TEST_DB_NO (default: 1) database will be cleared/flushed.

$ git clone ...

$ npm i

$ redis-server &

$ REDIS_URL=redis://127.0.0.1:6379 \
  TEST_DB_NO=1 \
  DEBUG=tests npm test