| 649 | */ |
| 650 | |
| 651 | class Advertise { |
| 652 | #service; |
| 653 | #list; |
| 654 | |
| 655 | constructor(options, list) { |
| 656 | const lastIndexOf = options.serviceType.lastIndexOf("._"); |
| 657 | if (lastIndexOf < 0) |
| 658 | throw new Error("invalid serviceType"); |
| 659 | |
| 660 | const {txt, name, serviceType} = options; |
| 661 | this.#service = { |
| 662 | name: serviceType.slice(1, lastIndexOf), |
| 663 | protocol: serviceType.slice(lastIndexOf + 2), |
| 664 | host: options.host, |
| 665 | port: options.port |
| 666 | }; |
| 667 | if (txt) |
| 668 | this.#service.txt = txt; |
| 669 | if (name) |
| 670 | this.#service.instanceName = name; |
| 671 | dnssd.add(this.#service); |
| 672 | |
| 673 | this.#list = list; |
| 674 | list.push(this); |
| 675 | } |
| 676 | close() { |
| 677 | if (!this.#service) return |
| 678 | dnssd.remove(this.#service); |
| 679 | this.#service = undefined; |
| 680 | this.#list.splice(this.#list.indexOf(this), 1); |
| 681 | } |
| 682 | updateTXT(txt) { |
| 683 | if (txt) |
| 684 | this.#service.txt = txt; |
| 685 | else |
| 686 | delete this.#service.txt; |
| 687 | dnssd.update(this.#service); |
| 688 | } |
| 689 | |
| 690 | static { |
| 691 | this.prototype[Symbol.dispose] = this.prototype.close; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | class Discover { |
| 696 | #serviceType; |
nothing calls this directly
no outgoing calls
no test coverage detected