mdns-discovery
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -181,2 +181,17 @@ "use strict"; | ||
MulticastDNS.prototype.setFilter = function (propName, arr) { | ||
if (typeof propName === 'function') { | ||
this.validFilter = propName.bind(this); | ||
return this; | ||
} | ||
this.validFilter = function(a) { | ||
var bo = arr.find(function(v) { | ||
return v[propName] === a[propName] | ||
}); | ||
return !bo; | ||
}; | ||
return this; | ||
}; | ||
MulticastDNS.prototype.onPacket = function (packets, rinfo) { | ||
@@ -188,2 +203,3 @@ //this.options.find = 'amzn.dmgr:'; | ||
if (a.name.indexOf(this.options.find) === 0) { | ||
if (this.validFilter && !this.validFilter({ ip: rinfo.address })) return; | ||
var found = this.found.find(function(v) { | ||
@@ -193,2 +209,3 @@ return v.ip === rinfo.address; | ||
if (found) return; | ||
this.found.push({ | ||
@@ -213,2 +230,3 @@ ip: rinfo.address, | ||
case 'message': this.__proto__.onMessage = fn; break; | ||
case 'filter': this.validFilter = fn; break; | ||
} | ||
@@ -215,0 +233,0 @@ return this; |
{ | ||
"name": "mdns-discovery", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Multicast DNS", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -1,2 +0,2 @@ | ||
###mnds Multicast DNS | ||
###mdns Multicast DNS | ||
<!-- | ||
@@ -56,1 +56,22 @@ [![Tests](http://img.shields.io/travis/soef/soef/master.svg)](https://travis-ci.org/soef/soef) | ||
``` | ||
Filter: | ||
```js | ||
var mdns = require('mdns-discovery')(); | ||
var mdns = Mdns({ | ||
timeout: 3, | ||
name: '_amzn-wplay._tcp.local', | ||
find: 'amzn.dmgr:' | ||
}); | ||
var allreadyUsed = [ {ip: '192.168.1.94'}, {ip: '192.168.1.91'} ]; | ||
mdns.setFilter('ip', allreadyUsed).run (function(res) { | ||
res.forEach(function(v) { | ||
console.log(v); | ||
}); | ||
}); | ||
``` | ||
12399
232
77