mdns-discovery
Advanced tools
Comparing version 0.1.11 to 0.1.12
@@ -24,5 +24,6 @@ "use strict"; | ||
multicastTTL: 64, | ||
ttl: 64 | ||
ttl: 64, | ||
noQuestions: true | ||
//returnOnFirstFound: false, | ||
//find: 'string' | ||
//find: 'string' | ||
}; | ||
@@ -100,2 +101,3 @@ | ||
// }] | ||
//, type: 'query' | ||
}); | ||
@@ -124,3 +126,3 @@ return message; | ||
client.setBroadcast(this.options.broadcast !== false); | ||
if (this.options.multicast !== false) { | ||
@@ -163,3 +165,3 @@ if (this.options.addMembership !== false) { | ||
readyCallback = timeout; | ||
timeout = undefined; | ||
timeout = undefined; | ||
} | ||
@@ -176,3 +178,3 @@ if (timeout === undefined) timeout = this.options.timeout; | ||
this.found.forEach(function(info) { | ||
debug("found: %s - %s", info.ip, info.name); | ||
debug("found: %s - %s", info.ip, info.name); | ||
}); | ||
@@ -209,24 +211,35 @@ } | ||
MulticastDNS.prototype.onPacket = function (packets, rinfo) { | ||
//this.options.find = 'amzn.dmgr:'; | ||
if (!this.options.find || !packets.answers) return; | ||
if (this.options.find === undefined || !packets.answers) return; | ||
var self = this; | ||
packets.answers.forEach(function(a) { | ||
if (a.name.indexOf(this.options.find) === 0) { | ||
if (this.validFilter && !this.validFilter({ ip: rinfo.address })) return; | ||
var found = this.found.find(function(v) { | ||
return v.ip === rinfo.address; | ||
}); | ||
if (found) return; | ||
this.found.push({ | ||
ip: rinfo.address, | ||
//name: a.name | ||
name: packets.answers[0].name ? packets.answers[0].name : a.name | ||
}); | ||
if (this.options.returnOnFirstFound) { | ||
this.close(); | ||
this.readyCallback(this.found); | ||
function doIt(qa, type) { | ||
if (qa) qa.forEach (function (a) { | ||
if (self.options.find === '*' || a.name.indexOf (self.options.find) === 0) { | ||
if (self.validFilter && !self.validFilter ({ip: rinfo.address})) return; | ||
var alreadyFound = self.found.find (function (v) { | ||
return v.ip === rinfo.address; | ||
}); | ||
if (alreadyFound) return; | ||
var entry = { | ||
ip: rinfo.address, | ||
type: type, | ||
//name: a.name | ||
name: qa[0].name ? qa[0].name : a.name | ||
}; | ||
if (self.onEntry) { | ||
self.onEntry (entry); | ||
} else { | ||
self.found.push (entry); | ||
} | ||
if (self.options.returnOnFirstFound) { | ||
self.close (); | ||
self.readyCallback (self.found); | ||
} | ||
} | ||
} | ||
}.bind(this)); | ||
}); | ||
} | ||
doIt(packets.answers, 'answer'); | ||
if (!this.noQuestions && packets.questions) doIt(packets.questions, 'query'); | ||
return this; | ||
@@ -241,2 +254,3 @@ }; | ||
case 'filter': this.validFilter = fn; break; | ||
case 'entry': this.onEntry = fn.bind(this); break; | ||
} | ||
@@ -243,0 +257,0 @@ return this; |
{ | ||
"name": "mdns-discovery", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "Multicast DNS", | ||
@@ -5,0 +5,0 @@ "author": { |
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
160075
6
252