UNPKG

@collight/dns-sd

Version:

A DNS Service Discovery implementation in modern TypeScript

3 lines (2 loc) 1.01 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./utils/debug.cjs");const u=require("./utils/MDNSServer.cjs"),n=require("./browser/Browser.cjs"),a=require("./registry/Registry.cjs");require("./registry/Service.cjs");class c{constructor(r={}){this.server=new u.MDNSServer(r),this.registry=new a.Registry(this.server)}makeService(r){return this.registry.makeService(r)}async publish(r){return this.registry.publish(r)}async unpublishAll(){await this.registry.unpublishAll()}makeBrowser(r){return new n.Browser(this.server.mdns,r)}startBrowser(r,s){const e=this.makeBrowser(r);return s&&e.on("up",s),e.start(),e}async findOne(r,s=1e4){return new Promise(e=>{const t=new n.Browser(this.server.mdns,r);t.start();let i=setTimeout(()=>{t.stop(),e(null)},s);t.once("up",o=>{i!==void 0&&(clearTimeout(i),i=void 0),t.stop(),e(o)})})}async destroy(){return new Promise(r=>{this.registry.destroy(),this.server.mdns.destroy(r)})}}exports.DNSSD=c; //# sourceMappingURL=DNSSD.cjs.map