Skip to content

Commit f0368b4

Browse files
committed
add query response callback option for mdns
1 parent 0bc6950 commit f0368b4

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ var Browser = require('./lib/browser')
66

77
module.exports = Bonjour
88

9-
function Bonjour (opts) {
10-
if (!(this instanceof Bonjour)) return new Bonjour(opts)
11-
this._server = new Server(opts)
9+
function Bonjour (opts, cbQueryRespond) {
10+
if (!(this instanceof Bonjour)) return new Bonjour(opts, cbQueryRespond)
11+
this._server = new Server(opts, cbQueryRespond)
1212
this._registry = new Registry(this._server)
1313
}
1414

lib/mdns-server.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ var deepEqual = require('deep-equal')
77

88
module.exports = Server
99

10-
function Server (opts) {
10+
function Server (opts, cbQueryRespond) {
1111
this.mdns = multicastdns(opts)
1212
this.mdns.setMaxListeners(0)
1313
this.registry = {}
1414
this.mdns.on('query', this._respondToQuery.bind(this))
15+
this.cbQueryRespond = typeof cbQueryRespond == 'function'
16+
? cbQueryRespond
17+
: function(err) { if (err) throw err }
1518
}
1619

1720
Server.prototype.register = function (records) {
@@ -83,9 +86,7 @@ Server.prototype._respondToQuery = function (query) {
8386
})
8487
}
8588

86-
self.mdns.respond({ answers: answers, additionals: additionals }, function (err) {
87-
if (err) throw err // TODO: Handle this (if no callback is given, the error will be ignored)
88-
})
89+
self.mdns.respond({ answers: answers, additionals: additionals }, this.cbQueryRespond)
8990
})
9091
}
9192

0 commit comments

Comments
 (0)