_setupWorker(worker) {
    // chatroom is spawned
    worker.on('online', () => {
      // eslint-disable-next-line max-len
      debug(`# of Workers: ${_.size(cluster.workers)}. Worker id ${worker.id}, ${worker.process.pid} is online.`);
    });

    // chatroom sent us a message
    worker.on('message', (msg) => {
      const util = require('util');
      // eslint-disable-next-line max-len
      debug(`worker ${worker.process.pid} has sent a message to master: ${util.inspect(msg, true, 2)}`);
      switch (msg.type) {
        case 'port':
          const name = this.workers[worker.id].name;
          this.roomPort[name] = msg.port;
          break;

        default:
          ;
      }
    });

    // chatroom exitted for some reason and we need to clean up
    worker.on('exit', (code, signal) => {
      if (signal) {
        console.error(`worker ${worker.id} was killed by signal ${signal}`);
      } else if (code !== 0) {
        console.error(`worker ${worker.id} exited with error code ${code}`);
      } else {
        console.info(`worker ${worker.id} shutdown successfully`);
      }
      this._cleanupWorker(worker);
    });

    worker.on('disconnect', () => {
      console.info(`worker id ${worker.id}, pid ${worker.process.pid} disconnected`);
      this._cleanupWorker(worker);
    });
  }
/** Registers listeners on the chatroom
   *
   * @private
   * @param  {object} worker
   */
Registers listeners on the chatroom
@private
@param  {object} worker
Registers listeners on the chatroom @private @param { object } worker
_setupWorker(worker) {
    worker.on('online', () => {
      debug(`# of Workers: ${_.size(cluster.workers)}. Worker id ${worker.id}, ${worker.process.pid} is online.`);
    });
    worker.on('message', (msg) => {
      const util = require('util');
      debug(`worker ${worker.process.pid} has sent a message to master: ${util.inspect(msg, true, 2)}`);
      switch (msg.type) {
        case 'port':
          const name = this.workers[worker.id].name;
          this.roomPort[name] = msg.port;
          break;
        default:
          ;
      }
    });
    worker.on('exit', (code, signal) => {
      if (signal) {
        console.error(`worker ${worker.id} was killed by signal ${signal}`);
      } else if (code !== 0) {
        console.error(`worker ${worker.id} exited with error code ${code}`);
      } else {
        console.info(`worker ${worker.id} shutdown successfully`);
      }
      this._cleanupWorker(worker);
    });
    worker.on('disconnect', () => {
      console.info(`worker id ${worker.id}, pid ${worker.process.pid} disconnected`);
      this._cleanupWorker(worker);
    });
  }
_setupWorker ( worker ) { worker . on ( 'online' , ( ) => { debug ( ` ${ _ . size ( cluster . workers ) } ${ worker . id } ${ worker . process . pid } ` ) ; } ) ; worker . on ( 'message' , ( msg ) => { const util = require ( 'util' ) ; debug ( ` ${ worker . process . pid } ${ util . inspect ( msg , true , 2 ) } ` ) ; switch ( msg . type ) { case 'port' : const name = this . workers [ worker . id ] . name ; this . roomPort [ name ] = msg . port ; break ; default : ; } } ) ; worker . on ( 'exit' , ( code , signal ) => { if ( signal ) { console . error ( ` ${ worker . id } ${ signal } ` ) ; } else if ( code !== 0 ) { console . error ( ` ${ worker . id } ${ code } ` ) ; } else { console . info ( ` ${ worker . id } ` ) ; } this . _cleanupWorker ( worker ) ; } ) ; worker . on ( 'disconnect' , ( ) => { console . info ( ` ${ worker . id } ${ worker . process . pid } ` ) ; this . _cleanupWorker ( worker ) ; } ) ; }
Registers listeners on the chatroom
 @private
 @param  {object} worker
Registers listeners on the chatroom @private @param { object } worker
// chatroom is spawned // eslint-disable-next-line max-len // chatroom sent us a message // eslint-disable-next-line max-len // chatroom exitted for some reason and we need to clean up