lib/serviceDiscovery/engines/mdns/index.js
function MDNSService(name, type, options) {
	var that = this;

	this.name = name;
	this.type = type;
	this.options = options;

	this.advertisement = null;
	this.browser = new mdns.Browser(mdns.makeServiceType(this.name, this.type));

	this.browser.on('serviceUp', function (service) {
		// we know that node, don't re-announce it
		if (services[getUniqueName(service)]) {
			return;
		}

		// this is our representation of a node, it contains the host, ips, port and metadata of a service
		var node = new ServiceNode(normalizeHost(service.host), service.port, service.addresses, service.txtRecord);
		services[getUniqueName(service)] = node;

		that.emit('up', node);
	});

	this.browser.on('serviceDown', function (service) {
		// retrieve the service object
		var node = services[getUniqueName(service)];

		// we never saw that node go up, don't emit a down
		if (!node) {
			return;
		}

		that.emit('down', node);

		// remove the data we knew about it
		delete services[getUniqueName(service)];
	});

	this.browser.on('error', function (error, service) {
		that.emit('error', error, service);
	});
}
function MDNSService(name, type, options) {
	var that = this;

	this.name = name;
	this.type = type;
	this.options = options;

	this.advertisement = null;
	this.browser = new mdns.Browser(mdns.makeServiceType(this.name, this.type));

	this.browser.on('serviceUp', function (service) {
		// we know that node, don't re-announce it
		if (services[getUniqueName(service)]) {
			return;
		}

		// this is our representation of a node, it contains the host, ips, port and metadata of a service
		var node = new ServiceNode(normalizeHost(service.host), service.port, service.addresses, service.txtRecord);
		services[getUniqueName(service)] = node;

		that.emit('up', node);
	});

	this.browser.on('serviceDown', function (service) {
		// retrieve the service object
		var node = services[getUniqueName(service)];

		// we never saw that node go up, don't emit a down
		if (!node) {
			return;
		}

		that.emit('down', node);

		// remove the data we knew about it
		delete services[getUniqueName(service)];
	});

	this.browser.on('error', function (error, service) {
		that.emit('error', error, service);
	});
}
function MDNSService ( name , type , options ) { var that = this ; this . name = name ; this . type = type ; this . options = options ; this . advertisement = null ; this . browser = new mdns . Browser ( mdns . makeServiceType ( this . name , this . type ) ) ; this . browser . on ( 'serviceUp' , function ( service ) { // we know that node, don't re-announce it if ( services [ getUniqueName ( service ) ] ) { return ; } // this is our representation of a node, it contains the host, ips, port and metadata of a service var node = new ServiceNode ( normalizeHost ( service . host ) , service . port , service . addresses , service . txtRecord ) ; services [ getUniqueName ( service ) ] = node ; that . emit ( 'up' , node ) ; } ) ; this . browser . on ( 'serviceDown' , function ( service ) { // retrieve the service object var node = services [ getUniqueName ( service ) ] ; // we never saw that node go up, don't emit a down if ( ! node ) { return ; } that . emit ( 'down' , node ) ; // remove the data we knew about it delete services [ getUniqueName ( service ) ] ; } ) ; this . browser . on ( 'error' , function ( error , service ) { that . emit ( 'error' , error , service ) ; } ) ; }
This is our service object, it starts a browser object so that if can forward up and down events
when nodes appear on the network.

@param {string} name                  The name of the service
@param {string} type                  The protocol used (eg: tcp)
@param {Object} options               Options
@param {string} options.description   Used to override the service name generated by the engine.
It needs to be unique on the network!
@constructor
This is our service object it starts a browser object so that if can forward up and down events when nodes appear on the network .