lib/pubsub.js
function PubSub(stats) {

  // ref to statistics so they can be updated
  // as subscriptions change
  this._stats = stats;

  // normal channels
  this._channels = {};

  // pattern channels
  this._patterns = {};

  this._count = {
    channels: {
      total: 0,       // total number of channels
      subscribers: 0, // total subscribers across all channels
    },
    patterns: {
      total: 0,       // total number of patterns
      subscribers: 0, // total subscribers across all patterns
    }
  }
}
function PubSub(stats) {

  // ref to statistics so they can be updated
  // as subscriptions change
  this._stats = stats;

  // normal channels
  this._channels = {};

  // pattern channels
  this._patterns = {};

  this._count = {
    channels: {
      total: 0,       // total number of channels
      subscribers: 0, // total subscribers across all channels
    },
    patterns: {
      total: 0,       // total number of patterns
      subscribers: 0, // total subscribers across all patterns
    }
  }
}
function PubSub ( stats ) { // ref to statistics so they can be updated // as subscriptions change this . _stats = stats ; // normal channels this . _channels = { } ; // pattern channels this . _patterns = { } ; this . _count = { channels : { total : 0 , // total number of channels subscribers : 0 , // total subscribers across all channels } , patterns : { total : 0 , // total number of patterns subscribers : 0 , // total subscribers across all patterns } } }
Encapsulates the pubsub system.

Maps channel identifiers to arrays of client identifiers subscribed
to the given channel.

Clients are given a reference to the channels they are subscribed to,
this global subsystem is responsible for managing the client pubsub
references as well as the global references.

The global instance maps channels as keys on the objects which are arrays
of client identifiers, when a pubsub instance is assigned to a client the
channels and patterns are arrays of the client subscriptions.
Encapsulates the pubsub system .