UNPKG

922 BJavaScriptView Raw
1'use strict'
2
3var Registry = require('./lib/registry')
4var Server = require('./lib/mdns-server')
5var Browser = require('./lib/browser')
6
7module.exports = Bonjour
8
9function Bonjour (opts) {
10 if (!(this instanceof Bonjour)) return new Bonjour(opts)
11 this._server = new Server(opts)
12 this._registry = new Registry(this._server)
13}
14
15Bonjour.prototype.publish = function (opts) {
16 return this._registry.publish(opts)
17}
18
19Bonjour.prototype.unpublishAll = function (cb) {
20 this._registry.unpublishAll(cb)
21}
22
23Bonjour.prototype.find = function (opts, onup) {
24 return new Browser(this._server.mdns, opts, onup)
25}
26
27Bonjour.prototype.findOne = function (opts, cb) {
28 var browser = new Browser(this._server.mdns, opts)
29 browser.once('up', function (service) {
30 browser.stop()
31 if (cb) cb(service)
32 })
33 return browser
34}
35
36Bonjour.prototype.destroy = function () {
37 this._registry.destroy()
38 this._server.mdns.destroy()
39}