Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ bonjour.find({ type: 'http' }, function (service) {
### Initializing

```js
var bonjour = require('bonjour')([options])
var bonjour = require('bonjour')([options], [error])
```

The `options` are optional and will be used when initializing the
underlying multicast-dns server. For details see [the multicast-dns
documentation](https://github.com/mafintosh/multicast-dns#mdns--multicastdnsoptions).

The `error` is the callback when some error occurs.

### Publishing

#### `var service = bonjour.publish(options)`
Expand Down
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ var Browser = require('./lib/browser')

module.exports = Bonjour

function Bonjour (opts) {
if (!(this instanceof Bonjour)) return new Bonjour(opts)
this._server = new Server(opts)
function Bonjour (opts, error) {
if (!(this instanceof Bonjour)) return new Bonjour(opts, error)

if (typeof opts === 'function') {
error = opts;
opts = undefined;
}

this._server = new Server(opts, error)
this._registry = new Registry(this._server)
}

Expand Down
3 changes: 2 additions & 1 deletion lib/mdns-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ var deepEqual = require('deep-equal')

module.exports = Server

function Server (opts) {
function Server (opts, error) {
this.mdns = multicastdns(opts)
this.mdns.setMaxListeners(0)
this.registry = {}
this.mdns.on('query', this._respondToQuery.bind(this))
this.mdns.on('error', typeof error === 'function' ? error : console.log)
}

Server.prototype.register = function (records) {
Expand Down