How to use the sharedb.PubSub.call function in sharedb

To help you get started, we’ve selected a few sharedb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github share / sharedb-redis-pubsub / index.js View on Github external
function RedisPubSub(options) {
  if (!(this instanceof RedisPubSub)) return new RedisPubSub(options);
  PubSub.call(this, options);
  options || (options = {});

  this.client = options.client || redis.createClient(options);

  // Redis doesn't allow the same connection to both listen to channels and do
  // operations. Make an extra redis connection for subscribing with the same
  // options if not provided
  this.observer = options.observer || redis.createClient(this.client.options);

  var pubsub = this;
  this.observer.on('message', function(channel, message) {
    var data = JSON.parse(message);
    pubsub._emit(channel, data);
  });
}
module.exports = RedisPubSub;