lib/server.js
function Server(universes, port) {
  if (this instanceof Server === false) {
    return new Server(port);
  }
  EventEmitter.call(this);

  if (universes !== undefined && !Array.isArray(universes)) {
    universes = [universes];
  }
  this.universes = universes || [0x01];
  this.port = port || e131.DEFAULT_PORT;
  this._socket = dgram.createSocket('udp4');
  this._lastSequenceNumber = {};

  var self = this;
  this.universes.forEach(function (universe) {
    self._lastSequenceNumber[universe] = 0;
  });
  this._socket.on('error', function onError(err) {
    self.emit('error', err);
  });
  this._socket.on('listening', function onListening() {
    self.emit('listening');
  });
  this._socket.on('close', function onClose() {
    self.emit('close');
  });
  this._socket.on('message', function onMessage(msg) {
    var packet = new e131.Packet(msg);
    var validation = packet.validate();
    if (validation !== packet.ERR_NONE) {
      self.emit('packet-error', packet, validation);
      return;
    }
    if (packet.discard(self._lastSequenceNumber[packet.getUniverse()])) {
      self.emit('packet-out-of-order', packet);
    } else {
      self.emit('packet', packet);
    }
    self._lastSequenceNumber[packet.getUniverse()] = packet.getSequenceNumber();
  });
  this._socket.bind(this.port, function onListening() {
    self.universes.forEach(function (universe) {
      var multicastGroup = e131.getMulticastGroup(universe);
      self._socket.addMembership(multicastGroup);
    });
  });
}
function Server(universes, port) {
  if (this instanceof Server === false) {
    return new Server(port);
  }
  EventEmitter.call(this);

  if (universes !== undefined && !Array.isArray(universes)) {
    universes = [universes];
  }
  this.universes = universes || [0x01];
  this.port = port || e131.DEFAULT_PORT;
  this._socket = dgram.createSocket('udp4');
  this._lastSequenceNumber = {};

  var self = this;
  this.universes.forEach(function (universe) {
    self._lastSequenceNumber[universe] = 0;
  });
  this._socket.on('error', function onError(err) {
    self.emit('error', err);
  });
  this._socket.on('listening', function onListening() {
    self.emit('listening');
  });
  this._socket.on('close', function onClose() {
    self.emit('close');
  });
  this._socket.on('message', function onMessage(msg) {
    var packet = new e131.Packet(msg);
    var validation = packet.validate();
    if (validation !== packet.ERR_NONE) {
      self.emit('packet-error', packet, validation);
      return;
    }
    if (packet.discard(self._lastSequenceNumber[packet.getUniverse()])) {
      self.emit('packet-out-of-order', packet);
    } else {
      self.emit('packet', packet);
    }
    self._lastSequenceNumber[packet.getUniverse()] = packet.getSequenceNumber();
  });
  this._socket.bind(this.port, function onListening() {
    self.universes.forEach(function (universe) {
      var multicastGroup = e131.getMulticastGroup(universe);
      self._socket.addMembership(multicastGroup);
    });
  });
}
function Server ( universes , port ) { if ( this instanceof Server === false ) { return new Server ( port ) ; } EventEmitter . call ( this ) ; if ( universes !== undefined && ! Array . isArray ( universes ) ) { universes = [ universes ] ; } this . universes = universes || [ 0x01 ] ; this . port = port || e131 . DEFAULT_PORT ; this . _socket = dgram . createSocket ( 'udp4' ) ; this . _lastSequenceNumber = { } ; var self = this ; this . universes . forEach ( function ( universe ) { self . _lastSequenceNumber [ universe ] = 0 ; } ) ; this . _socket . on ( 'error' , function onError ( err ) { self . emit ( 'error' , err ) ; } ) ; this . _socket . on ( 'listening' , function onListening ( ) { self . emit ( 'listening' ) ; } ) ; this . _socket . on ( 'close' , function onClose ( ) { self . emit ( 'close' ) ; } ) ; this . _socket . on ( 'message' , function onMessage ( msg ) { var packet = new e131 . Packet ( msg ) ; var validation = packet . validate ( ) ; if ( validation !== packet . ERR_NONE ) { self . emit ( 'packet-error' , packet , validation ) ; return ; } if ( packet . discard ( self . _lastSequenceNumber [ packet . getUniverse ( ) ] ) ) { self . emit ( 'packet-out-of-order' , packet ) ; } else { self . emit ( 'packet' , packet ) ; } self . _lastSequenceNumber [ packet . getUniverse ( ) ] = packet . getSequenceNumber ( ) ; } ) ; this . _socket . bind ( this . port , function onListening ( ) { self . universes . forEach ( function ( universe ) { var multicastGroup = e131 . getMulticastGroup ( universe ) ; self . _socket . addMembership ( multicastGroup ) ; } ) ; } ) ; }
E1.31 server object constructor
E1 . 31 server object constructor