Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
(function () {
"use strict";
var mdns = require('mdns')
;
function create() {
var browser
, browsers = {}
, stuffs = {}
;
browser = mdns.browseThemAll();
browser.on('serviceUp', function (record) {
var srv = record.type.name
, br
;
if (browsers[srv]) {
return;
}
stuffs[srv] = {};
br = browsers[srv] = mdns.createBrowser(mdns[record.type.protocol](srv));
br.on('serviceUp', function (rec) {
stuffs[srv][rec.name] = rec;
console.log(rec);
});
br.on('serviceDown', function (rec) {
delete stuffs[srv][rec.name];
});
br.start();
console.log(record.interfaceIndex, record.type.protocol, record.type.name);
});
browser.on('serviceDown', function (record) {
var br = stuffs[record.type.name]
;
if (!br) {
return;
}
br.stop();
delete stuffs[record.type.name];
});
browser.start();
function handler(req, res, next) {
//res.json(stuffs);
res.end(JSON.stringify(stuffs, function (keyname, val) {
console.log(arguments);
if (/raw/.exec(keyname)) {
return;
}
return val;
}, ' '));
}
return handler;
}
if (module === require.main) {
var connect = require('connect'),
app = connect()
;
app.use(create());
require('http').createServer(app).listen(9090);
setInterval(function () {}, 60 * 1000);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.