1.0.2 • Published 5 years ago

meteor-sync-eventemitter v1.0.2

Weekly downloads
50
License
MIT
Repository
github
Last release
5 years ago

meteor-sync-eventemitter

Allows syncing event emitter events over multiple meteor servers.

Installation

  npm install meteor-sync-eventemitter

Usage

Normal EventEmitters

  import sync from 'meteor-sync-eventemitter';
  import EventEmitter from 'events';

  @sync({
    collectionName: 'syncedeventemitter', // the collection can only be used for one event emitter.
    emitFn: 'emit', // [optional] if the emit function of the event emitter differs from the default one.
    setIndex: true, // [optional] per default, we create a expiring index to delete entries after 60 seconds.
  })
  class SyncedEventEmitter extends EventEmitter {
    // …
  }

  const eventEmitter = new SyncedEventEmitter();
  eventEmitter.emit('hello');
  eventEmitter.on('hello', () => console.log('world')); // would be triggered on all servers

rocketchat:streamer

  import { Meteor } from 'meteor/meteor';
  import sync from 'meteor-sync-eventemitter';

  @sync({ collectionName: 'stream', emitFn: '_emit' })
  class SyncedStream extends Meteor.Streamer {
    constructor() {
      super('streamname');
      this.allowRead( … );
      this.allowWrite( … );
    }
  }

  const stream = new SyncedStream()
  stream.emit( … );
  stream.on( … );

License

Licensed under MIT license. Copyright (c) 2017 Max Nowack

Contributions

Contributions are welcome. Please open issues and/or file Pull Requests.

Maintainers