lib/elements-event-handler.js
function ElementsEventHandler(socket) {
  var _this = this;
  //Call EventEmmiter _contructor_
  events.EventEmitter.call(this);
  this.socket = socket;

  // On every message event received by socket we get
  // an message event object like {event:, data:} 
  // we emit  a local event through an EventEmitter interface
  // with .event as event type and .data as
  // event data;
  this.socket.on('message', function(message, callback) {
    debug("Forwarding frontend message '%s', with data %j", message.event, message.data);
    if (message.event !== undefined) {
      _this.emit(message.event, message.data);
      if (typeof callback === 'function') {
        callback();
      }
    }
    if (message.event === "userinput" && message.scope !== undefined) {
      debug("userinput received: %s", JSON.stringify(message));
      _this.emit(message.scope, message.data);
    }
  });
  this.socket.on("disconnect", function() {
    delete(this.socket);
    _this.emit("disconnect");
  });
}
function ElementsEventHandler(socket) {
  var _this = this;
  //Call EventEmmiter _contructor_
  events.EventEmitter.call(this);
  this.socket = socket;

  // On every message event received by socket we get
  // an message event object like {event:, data:} 
  // we emit  a local event through an EventEmitter interface
  // with .event as event type and .data as
  // event data;
  this.socket.on('message', function(message, callback) {
    debug("Forwarding frontend message '%s', with data %j", message.event, message.data);
    if (message.event !== undefined) {
      _this.emit(message.event, message.data);
      if (typeof callback === 'function') {
        callback();
      }
    }
    if (message.event === "userinput" && message.scope !== undefined) {
      debug("userinput received: %s", JSON.stringify(message));
      _this.emit(message.scope, message.data);
    }
  });
  this.socket.on("disconnect", function() {
    delete(this.socket);
    _this.emit("disconnect");
  });
}
function ElementsEventHandler ( socket ) { var _this = this ; //Call EventEmmiter _contructor_ events . EventEmitter . call ( this ) ; this . socket = socket ; // On every message event received by socket we get // an message event object like {event:, data:}  // we emit  a local event through an EventEmitter interface // with .event as event type and .data as // event data; this . socket . on ( 'message' , function ( message , callback ) { debug ( "Forwarding frontend message '%s', with data %j" , message . event , message . data ) ; if ( message . event !== undefined ) { _this . emit ( message . event , message . data ) ; if ( typeof callback === 'function' ) { callback ( ) ; } } if ( message . event === "userinput" && message . scope !== undefined ) { debug ( "userinput received: %s" , JSON . stringify ( message ) ) ; _this . emit ( message . scope , message . data ) ; } } ) ; this . socket . on ( "disconnect" , function ( ) { delete ( this . socket ) ; _this . emit ( "disconnect" ) ; } ) ; }
Creates an event emitter and forwards every event triggered to client
@param {io.Client} socket A socket.io client instance on which to send messages.
Creates an event emitter and forwards every event triggered to client