Comparing version 0.0.1 to 0.0.2
@@ -0,0 +0,0 @@ var BufferWriter = module.exports = function (opt_size) { |
@@ -157,3 +157,47 @@ var debug = require('debug')('mdns:mdns'); | ||
/** | ||
* Sorts the passed list of string IPs in-place. | ||
* @private | ||
*/ | ||
Mdns._sortIps = function(arg) { | ||
arg.sort(Mdns._sortIps.sort); | ||
return arg; | ||
}; | ||
Mdns._sortIps.sort = function(l, r) { | ||
// TODO: support v6. | ||
var lp = l.split('.').map(Mdns._sortIps._toInt); | ||
var rp = r.split('.').map(Mdns._sortIps._toInt); | ||
for (var i = 0; i < Math.min(lp.length, rp.length); ++i) { | ||
if (lp[i] < rp[i]) { | ||
return -1; | ||
} else if (lp[i] > rp[i]) { | ||
return +1; | ||
} | ||
} | ||
return 0; | ||
}; | ||
Mdns._sortIps._toInt = function(i) { | ||
return +i; | ||
}; | ||
/** | ||
* Returns the IPs found by this, optionally filtered by service. | ||
*/ | ||
Mdns.prototype.ips = function(opt_service) { | ||
var k = Object.keys(opt_service ? this._byService[opt_service] : this._byIP); | ||
return Mdns._sortIps(k); | ||
}; | ||
/** | ||
* Returns the services found by this ServiceFinder, optionally filtered by IP. | ||
*/ | ||
Mdns.prototype.services = function(opt_ip) { | ||
var k = Object.keys(opt_ip ? this._byIP[opt_ip] : this._byService); | ||
k.sort(); | ||
return k; | ||
}; | ||
Mdns.prototype.discover = function () { | ||
@@ -160,0 +204,0 @@ process.nextTick(function () { |
{ | ||
"name": "mdns-js", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"repository": { | ||
@@ -25,3 +25,3 @@ "type": "git", | ||
"test": "mocha", | ||
"lint": "jshint lib test index.js" | ||
"lint": "jshint lib test examples index.js" | ||
}, | ||
@@ -28,0 +28,0 @@ "author": { |
@@ -6,2 +6,4 @@ mDNS-js | ||
A lot of the functionality is copied from https://github.com/GoogleChrome/chrome-app-samples/tree/master/mdns-browser | ||
but adapted for node. | ||
@@ -13,1 +15,18 @@ Install by | ||
example | ||
------- | ||
```javascript | ||
var Mdns = require('mdns-js'); | ||
var mdns = new Mdns(); | ||
mdns.on('ready', function () { | ||
mdns.discover(); | ||
}); | ||
mdns.on('update', function () { | ||
console.log('ips with _workstation._tcp service', mdns.ips('_workstation._tcp')); | ||
console.log('services on host 10.100.0.61', mdns.services('10.100.0.61')); | ||
}); | ||
``` |
@@ -31,3 +31,10 @@ /*global describe: true, it: true, before: true, after: true */ | ||
mdns._byService.should.have.property('_workstation._tcp'); | ||
console.log('services', mdns._byService); | ||
var hosts = mdns.ips('_workstation._tcp'); | ||
hosts.should.be.instanceof(Array); | ||
hosts.length.should.be.above(0); | ||
var services = mdns.services(); | ||
services.should.be.instanceof(Array); | ||
services.length.should.be.above(0); | ||
done(); | ||
@@ -34,0 +41,0 @@ }); |
30
29665
15
459