lib/browser.js
function Browser (mdns, opts, onup) {
  if (typeof opts === 'function') return new Browser(mdns, null, opts)

  EventEmitter.call(this)

  this._mdns = mdns
  this._onresponse = null
  this._serviceMap = {}
  this._txt = dnsTxt(opts.txt)

  if (!opts || !opts.type) {
    this._name = WILDCARD
    this._wildcard = true
  } else {
    this._name = serviceName.stringify(opts.type, opts.protocol || 'tcp') + TLD
    if (opts.name) this._name = opts.name + '.' + this._name
    this._wildcard = false
  }

  this.services = []

  if (onup) this.on('up', onup)

  this.start()
}
function Browser (mdns, opts, onup) {
  if (typeof opts === 'function') return new Browser(mdns, null, opts)

  EventEmitter.call(this)

  this._mdns = mdns
  this._onresponse = null
  this._serviceMap = {}
  this._txt = dnsTxt(opts.txt)

  if (!opts || !opts.type) {
    this._name = WILDCARD
    this._wildcard = true
  } else {
    this._name = serviceName.stringify(opts.type, opts.protocol || 'tcp') + TLD
    if (opts.name) this._name = opts.name + '.' + this._name
    this._wildcard = false
  }

  this.services = []

  if (onup) this.on('up', onup)

  this.start()
}
function Browser ( mdns , opts , onup ) { if ( typeof opts === 'function' ) return new Browser ( mdns , null , opts ) EventEmitter . call ( this ) this . _mdns = mdns this . _onresponse = null this . _serviceMap = { } this . _txt = dnsTxt ( opts . txt ) if ( ! opts || ! opts . type ) { this . _name = WILDCARD this . _wildcard = true } else { this . _name = serviceName . stringify ( opts . type , opts . protocol || 'tcp' ) + TLD if ( opts . name ) this . _name = opts . name + '.' + this . _name this . _wildcard = false } this . services = [ ] if ( onup ) this . on ( 'up' , onup ) this . start ( ) }
Start a browser

The browser listens for services by querying for PTR records of a given
type, protocol and domain, e.g. _http._tcp.local.

If no type is given, a wild card search is performed.

An internal list of online services is kept which starts out empty. When
ever a new service is discovered, it's added to the list and an "up" event
is emitted with that service. When it's discovered that the service is no
longer available, it is removed from the list and a "down" event is emitted
with that service.
Start a browser