src/Browser.js
function Browser(type, options = {}) {
  if (!(this instanceof Browser)) return new Browser(type, options);
  EventEmitter.call(this);

  // convert argument ServiceType to validate it (might throw)
  const serviceType = (type instanceof ServiceType) ? type : new ServiceType(type);

  // can't search for multiple subtypes at the same time
  if (serviceType.subtypes.length > 1) {
    throw new Error('Too many subtypes. Can only browse one at a time.');
  }

  this._id = serviceType.toString();
  debug(`Creating new browser for "${this._id}"`);

  this._resolvers    = {}; // active service resolvers (when browsing services)
  this._serviceTypes = {}; // active service types (when browsing service types)
  this._protocol     = serviceType.protocol;
  this._serviceName  = serviceType.name;
  this._subtype      = serviceType.subtypes[0];
  this._isWildcard   = serviceType.isEnumerator;
  this._domain       = options.domain || 'local.';
  this._maintain     = ('maintain' in options) ? options.maintain : true;
  this._resolve      = ('resolve' in options) ? options.resolve : true;
  this._interface    = NetworkInterface.get(options.interface);
  this._state        = STATE.STOPPED;

  // emitter used to stop child queries instead of holding onto a reference
  // for each one
  this._offswitch = new EventEmitter();
}
function Browser(type, options = {}) {
  if (!(this instanceof Browser)) return new Browser(type, options);
  EventEmitter.call(this);

  // convert argument ServiceType to validate it (might throw)
  const serviceType = (type instanceof ServiceType) ? type : new ServiceType(type);

  // can't search for multiple subtypes at the same time
  if (serviceType.subtypes.length > 1) {
    throw new Error('Too many subtypes. Can only browse one at a time.');
  }

  this._id = serviceType.toString();
  debug(`Creating new browser for "${this._id}"`);

  this._resolvers    = {}; // active service resolvers (when browsing services)
  this._serviceTypes = {}; // active service types (when browsing service types)
  this._protocol     = serviceType.protocol;
  this._serviceName  = serviceType.name;
  this._subtype      = serviceType.subtypes[0];
  this._isWildcard   = serviceType.isEnumerator;
  this._domain       = options.domain || 'local.';
  this._maintain     = ('maintain' in options) ? options.maintain : true;
  this._resolve      = ('resolve' in options) ? options.resolve : true;
  this._interface    = NetworkInterface.get(options.interface);
  this._state        = STATE.STOPPED;

  // emitter used to stop child queries instead of holding onto a reference
  // for each one
  this._offswitch = new EventEmitter();
}
function Browser ( type , options = { } ) { if ( ! ( this instanceof Browser ) ) return new Browser ( type , options ) ; EventEmitter . call ( this ) ; // convert argument ServiceType to validate it (might throw) const serviceType = ( type instanceof ServiceType ) ? type : new ServiceType ( type ) ; // can't search for multiple subtypes at the same time if ( serviceType . subtypes . length > 1 ) { throw new Error ( 'Too many subtypes. Can only browse one at a time.' ) ; } this . _id = serviceType . toString ( ) ; debug ( ` ${ this . _id } ` ) ; this . _resolvers = { } ; // active service resolvers (when browsing services) this . _serviceTypes = { } ; // active service types (when browsing service types) this . _protocol = serviceType . protocol ; this . _serviceName = serviceType . name ; this . _subtype = serviceType . subtypes [ 0 ] ; this . _isWildcard = serviceType . isEnumerator ; this . _domain = options . domain || 'local.' ; this . _maintain = ( 'maintain' in options ) ? options . maintain : true ; this . _resolve = ( 'resolve' in options ) ? options . resolve : true ; this . _interface = NetworkInterface . get ( options . interface ) ; this . _state = STATE . STOPPED ; // emitter used to stop child queries instead of holding onto a reference // for each one this . _offswitch = new EventEmitter ( ) ; }
Creates a new Browser

@emits 'serviceUp'
@emits 'serviceChanged'
@emits 'serviceDown'
@emits 'error'

@param {ServiceType|Object|String|Array} type - the service to browse
@param {Object} [options]
Creates a new Browser