Comparing version 0.2.5 to 0.2.6
@@ -41,7 +41,72 @@ | ||
var data = decoder.decodeMessage(message); | ||
var isNew = false; | ||
function setNew(/*msg*/) { | ||
isNew = true; | ||
debug('new on %s, because %s', | ||
connection.networkInterface, util.format.apply(null, arguments)); | ||
} | ||
function updateValue(src, dst, name) { | ||
if (JSON.stringify(dst[name]) !== JSON.stringify(src)) { | ||
setNew('updated host.%s', name); | ||
dst[name] = src; | ||
} | ||
} | ||
function addValue(src, dst, name) { | ||
if (typeof dst[name] === 'undefined') { | ||
setNew('added host.%s', name); | ||
dst[name] = src; | ||
} | ||
} | ||
if (data) { | ||
data.interfaceIndex = connection.interfaceIndex; | ||
data.networkInterface = connection.networkInterface; | ||
data.addresses.push(remote.address); | ||
if (!connection.services) { | ||
connection.services = {}; | ||
} | ||
if (!connection.addresses) { | ||
connection.addresses = {}; | ||
} | ||
data.type.forEach(function (type) { | ||
var service; | ||
var serviceKey = type.toString(); | ||
if (!connection.services.hasOwnProperty(serviceKey)) { | ||
setNew('new service - %s', serviceKey); | ||
service = connection.services[serviceKey] = {type: type, addresses: []}; | ||
} | ||
else { | ||
service = connection.services[serviceKey]; | ||
} | ||
data.addresses.forEach(function (adr) { | ||
if (service.addresses.indexOf(adr) === -1) { | ||
service.addresses.push(adr); | ||
setNew('new address'); | ||
} | ||
var host; | ||
if (connection.addresses.hasOwnProperty(adr)) { | ||
host = connection.addresses[adr]; | ||
} | ||
else { | ||
host = connection.addresses[adr] = {address: adr}; | ||
setNew('new host'); | ||
} | ||
addValue({}, host, serviceKey); | ||
updateValue(data.port, host[serviceKey], 'port'); | ||
updateValue(data.host, host[serviceKey], 'host'); | ||
updateValue(data.txt, host[serviceKey], 'txt'); | ||
}); | ||
}); | ||
/** | ||
@@ -54,3 +119,6 @@ * Update event | ||
*/ | ||
this.emit('update', data); | ||
debug('isNew', isNew); | ||
if (isNew) { | ||
this.emit('update', data); | ||
} | ||
} | ||
@@ -79,3 +147,4 @@ }; | ||
this._all = new EventEmitter(); | ||
var services = {}; | ||
var addresses = {}; | ||
var connections = []; | ||
@@ -133,3 +202,5 @@ var created = 0; | ||
interfaceIndex: interfaceIndex, | ||
networkInterface: networkInterface | ||
networkInterface: networkInterface, | ||
services: services, | ||
addresses: addresses | ||
}; | ||
@@ -168,2 +239,4 @@ | ||
debug('stopping'); | ||
debug('connection.services', services); | ||
debug('connection.addresses', addresses); | ||
for (var i = 0; i < connections.length; i++) { | ||
@@ -170,0 +243,0 @@ var socket = connections[i].socket; |
{ | ||
"name": "mdns-js", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79741
1811