@collight/dns-sd
Version:
A DNS Service Discovery implementation in modern TypeScript
3 lines (2 loc) • 922 B
JavaScript
import"./utils/debug.js";import{MDNSServer as m}from"./utils/MDNSServer.js";import{Browser as o}from"./browser/Browser.js";import{Registry as u}from"./registry/Registry.js";import"./registry/Service.js";class l{constructor(r={}){this.server=new m(r),this.registry=new u(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 o(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 o(this.server.mdns,r);t.start();let i=setTimeout(()=>{t.stop(),e(null)},s);t.once("up",n=>{i!==void 0&&(clearTimeout(i),i=void 0),t.stop(),e(n)})})}async destroy(){return new Promise(r=>{this.registry.destroy(),this.server.mdns.destroy(r)})}}export{l as DNSSD};
//# sourceMappingURL=DNSSD.js.map