-
-
Save nazt/5098382 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*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') | |
| ; | |
| connect.createServer().use(create()).listen(9090); | |
| setInterval(function () {}, 60 * 1000); | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment