How to use event-emitter - 10 common examples

To help you get started, we’ve selected a few event-emitter 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 madebywild / konterball / src / javascripts / app.js View on Github external
constructor() {
    this.emitter = EventEmitter({});
    this.communication = new Communication(this.emitter);
    this.scene = new Scene(this.emitter, this.communication);
    this.setupDOMHandlers();
    this.setupCustomEventHandlers();
    this.introBallTween = null;
    this.activeScreen = '.intro-screen';
    this.mobileDetect = new MobileDetect(window.navigator.userAgent);

    if (Util.isMobile() && 'orientation' in window) {
      this.checkPhoneOrientation();
    } else {
      this.startLoading();
    }
    this.iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
    if (this.iOS) {
      // cant reliably go fullscreen in ios so just hide the button
github konforti / GSVPano / src / Pano.js View on Github external
Pano.prototype.composeFromTile = function(x, y, texture) {
  // Complete this section of the frame
  this._ctx.drawImage(texture, x * 512, y * 512);
  this._count++;

  var p = Math.round(this._count * 100 / this._total);
  this.emit('progress', p);

  // If finished
  if (this._count === this._total) {
    // Done loading
    this._loaded = true;
    // Trigger complete event
    this.emit('complete', this);
    // Remove all events
    eventEmitter.alloff(this);
  }
};
github ringcentral / ringcentral-js-widgets / src / lib / rc-module.js View on Github external
constructor({
    promiseForStore,
    getState = defaultGetState,
    prefix,
    actions,
  }) {
    // Extending EventEmitter breaks some mechanic, so we wire emitter up like this instead.
    this[symbols.emitter] = new EventEmitter();
    this[symbols.getState] = getState;
    this[symbols.prefix] = prefix;
    this[symbols.actions] = actions && prefixActions(actions, prefix);
    promiseForStore.then((store) => {
      this[symbols.store] = store;
    });
  }
github Alfresco / alfresco-js-api / src / oauth2Auth.js View on Github external
this.basePath = this.config.oauth2.host; //Auth Call

            this.authentications = {
                'basicAuth': {type: 'oauth2', accessToken: ''}
            };

            this.host = this.config.oauth2.host;

            this.initOauth();// jshint ignore:line

            if (this.config.accessToken) {
                this.setTicket(this.config.accessToken);
            }
        }

        Emitter.call(this);
    }
github lorengreenfield / halfcab / eventEmitter / index.js View on Github external
import ee from 'event-emitter'
var events = ee({})

function eventEmitter(){

    var noop = () => {}

    if(typeof window !== 'undefined'){
        function broadcast(eventName, eventObject){

            //Set a break point on the following line to monitor all events being broadcast
            console.log('Event broadcast: '+ eventName)
            events.emit(eventName, eventObject)
        }

        function on(eventName, cb){

            //Set a break point on the following line to monitor all events being listened to
github bytedance / xgplayer / packages / xgplayer-mp4 / src / media / mse.js View on Github external
constructor (codecs = 'video/mp4; codecs="avc1.64001E, mp4a.40.5"') {
    let self = this
    EventEmitter(this)
    this.codecs = codecs
    this.mediaSource = new window.MediaSource()
    this.url = window.URL.createObjectURL(this.mediaSource)
    this.queue = []
    this.updating = false
    this.mediaSource.addEventListener('sourceopen', function () {
      self.sourceBuffer = self.mediaSource.addSourceBuffer(self.codecs)
      self.sourceBuffer.addEventListener('error', function (e) {
        self.emit('error', new Errors('mse', '', {line: 16, handle: '[MSE] constructor sourceopen', msg: e.message}))
      })
      self.sourceBuffer.addEventListener('updateend', function (e) {
        self.emit('updateend')
        let buffer = self.queue.shift()
        if (buffer) {
          self.sourceBuffer.appendBuffer(buffer)
        }
github DaoCasino / BankRollerApp / src / model / rtc.js View on Github external
constructor(user_id=false, room=false) {
		room = room || _config.rtc_room
		
		const EC = function(){}
		EE(EC.prototype)
		this.Event = new EC()

		if (!room) {
			console.error('empty room name')
			return
		}

		this.user_id = user_id || Utils.makeSeed()
		this.room_id = ''+room
		this.channel = false
		this.connect(room)

		this.clearOldSeeds()
	}
github bytedance / xgplayer / packages / xgplayer-m4a / src / mp4.js View on Github external
constructor (url, chunkSize = 1024) {
    EventEmitter(this)
    this.url = url
    this.CHUNK_SIZE = chunkSize
    this.reqTimeLength = 5
    this.init(url)
    this.once('mdatReady', this.moovParse.bind(this))
    this.cache = new Buffer()
    this.bufferCache = new Set()
    this.mdatCache = []
    this.timeRage = []
    this.canDownload = true
    this.cut = false
  }
github cdapio / cdap / cdap-ui / app / cdap / components / EntityListView / NoEntitiesMessage / index.js View on Github external
export default function NoEntitiesMessage({
  searchText,
  filtersAreApplied,
  clearSearchAndFilters,
}) {
  let eventEmitter = ee(ee);

  const openAddEntityModal = () => {
    PlusButtonStore.dispatch({
      type: 'TOGGLE_PLUSBUTTON_MODAL',
      payload: {
        modalState: true,
      },
    });
  };

  const openCaskMarket = () => {
    eventEmitter.emit(globalEvents.OPENMARKET);
  };

  let namespace = NamespaceStore.getState().selectedNamespace;
  let emptyMessage = T.translate('features.EntityListView.emptyMessage.default', { namespace });
github yusukeshibata / react-pullrefresh / src / pullhelper / index.js View on Github external
constructor(scrollElement) {
    this.scrollElement = scrollElement
    this._emitter = new EventEmitter()
    this._emitter.on('pull', defaultHandler.pull)
    this._emitter.on('stepback', defaultHandler.stepback)
    this._y = 0
    this._cnt = 0
    this._step = 0
    this._touch = false
    this._lock = false
    this._paused = false
    this._loop = this._loop.bind(this)
    this.onTouchStart = this.onTouchStart.bind(this)
    this.onTouchEnd = this.onTouchEnd.bind(this)
    this.onTouchMove = this.onTouchMove.bind(this)
    this.onScroll = this.onScroll.bind(this)
  }
  set scrollElement(scrollElement) {