How to use the eventemitter3.EventEmitter function in eventemitter3

To help you get started, we’ve selected a few eventemitter3 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 maxpert / raspchat / src / chat-user.js View on Github external
constructor(id, ws, nick, options) {
        this.events = new E3.EventEmitter();
        this.id = id;
        this.nick = nick;
        this.options = Object.assign({}, DefaultOptions, options);
        this.lastSeen = new Date().getTime();

        this._ws = ws;
        this._joined = new Map();

        debug('User connected with', this.id, this.nick, this.lastSeen);
        this._ws.on('message', message => {
            // Message from user
            this.events.emit(
                'message',
                this.options.parser.fromSerialized(message),
                this);
        });
github video-dev / hls.js / src / demux / transmuxer-worker.ts View on Github external
export default function TransmuxerWorker (self) {
  const observer = new EventEmitter() as any;
  observer.trigger = (event, data) => {
    observer.emit(event, event, ...data);
  };

  observer.off = (event, ...data) => {
    observer.removeListener(event, ...data);
  };

  const forwardMessage = (ev, data) => {
    self.postMessage({ event: ev, data: data });
  };

  // forward events to main thread
  observer.on(Event.FRAG_DECRYPTED, forwardMessage);
  observer.on(Event.ERROR, forwardMessage);
github oasislabs / oasis.js / packages / gateway / src / index.ts View on Github external
public subscribe(request: SubscribeRequest): any {
    const events = new EventEmitter();
    this.session
      .request(SubscribeApi.method, SubscribeApi.url, {
        events: ['logs'],
        filter: urlEncodeFilter(request.filter!),
      })
      .then(response => {
        if (response.id === undefined || response.id === null) {
          throw new Error(`subscription failed: ${response}`);
        }
        // Store the event -> queueId mapping so that we can unsubscribe later.
        this.subscriptions.set(request.event, response.id);
        PollingService.instance({
          url: this.url,
          session: this.session,
          queueId: response.id,
        }).subscribe(response.id, (event: any) => {
github RocketChat / Rocket.Chat / packages / rocketchat-notifications / server / lib / streamer / stream.js View on Github external
constructor(n) {
		super();
		if (Streamer[n]) {
			throw 'the stream already exists';
		}
		Streamer[n] = this;
		this.name = n;
		this.subscriptionName = `stream-${ STREAM_NAMES[this.name] }`;
		this.internals = new EventEmitter;

		this[prepareSubscription]();
		this[prepareMethod]();

		this[authorizaton] = {
			read: {},
			write: {},
		};


	}
github ioxe / graphql-aws-iot-client / dist / client.js View on Github external
this.sigv4utils = new sig4utils_1.SigV4Utils();
        }
        this.connectionParams = connectionParams;
        this.connectionCallback = connectionCallback;
        this.iotEndpoint = iotEndpoint;
        this.region = options.region;
        this.operations = {};
        this.nextOperationId = 0;
        this.timeout = timeout;
        this.unsentMessagesQueue = [];
        this.reconnect = reconnect;
        this.reconnecting = false;
        this.reconnectionAttempts = reconnectionAttempts;
        this.closedByUser = false;
        this.backoff = new Backoff({ jitter: 0.5 });
        this.eventEmitter = new eventemitter3_1.EventEmitter();
        this.middlewares = [];
        this.client = null;
        this.maxConnectTimeGenerator = this.createMaxConnectTimeGenerator();
        this.request = this.request.bind(this);
        this.debug = options.debug;
        this.connect();
    }
    SubscriptionClient.prototype.close = function (isForced, closedByUser) {
github http-party / node-http-proxy / lib / http-proxy / index.js View on Github external
EE3.call(this);

  this.web     = createRightProxy('web')(options);
  this.ws      = createRightProxy('ws')(options);
  this.options = options;

  this.webPasses = Object.keys(web).map(function(pass) {
    return web[pass];
  });

  this.wsPasses = Object.keys(ws).map(function(pass) {
    return ws[pass];
  });
}

require('util').inherits(ProxyServer, EE3);

ProxyServer.prototype.listen = function(port) {
  var self    = this,
      closure = function(req, res) { self.web(req, res); };
      
  this._server  = this.options.ssl ? 
    https.createServer(this.options.ssl, closure) : 
    http.createServer(closure);

  if(this.options.ws) {
    this._server.on('upgrade', function(req, socket, head) { self.ws(req, socket, head); });
  }

  this._server.listen(port);

  return this;
github oasislabs / oasis.js / packages / gateway / src / polling.ts View on Github external
private constructor(
    private session: Http,
    private queueId?: number,
    responseWindow?: Window,
    interval?: number
  ) {
    this.responseWindow = responseWindow ? responseWindow : new Window();
    this.interval = interval ? interval : 1000;
    this.responses = new EventEmitter();
    this.lastResponseTs = Date.now();
  }

eventemitter3

EventEmitter3 focuses on performance while maintaining a Node.js AND browser compatible interface.

MIT
Latest version published 2 years ago

Package Health Score

79 / 100
Full package analysis