You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
922 B

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