| 63 | super.close(); |
| 64 | } |
| 65 | add(service) { |
| 66 | if (!this.hostName) |
| 67 | throw new Error("no hostName"); |
| 68 | |
| 69 | if (this.probing) |
| 70 | throw new Error("not ready"); |
| 71 | |
| 72 | service.txt ??= {}; |
| 73 | this.services.push(service); |
| 74 | |
| 75 | this.write(MDNS.IP, MDNS.PORT, this.reply(null, 0x1F | 0x8000, service, true)); // remove before adding to clear stale state in clients |
| 76 | service.timer = Timer.repeat(timer => { |
| 77 | this.write(MDNS.IP, MDNS.PORT, this.reply(null, 0x1F, service)); |
| 78 | timer.interval *= 2; |
| 79 | if (timer.interval > 16000) { |
| 80 | Timer.clear(timer); |
| 81 | delete service.timer; |
| 82 | } |
| 83 | else |
| 84 | Timer.schedule(timer, timer.interval, timer.interval); |
| 85 | }, 500); |
| 86 | service.timer.interval = 500; |
| 87 | } |
| 88 | update(service) { |
| 89 | const index = this.services.indexOf(service); |
| 90 | if (index < 0) throw new Error("service not found"); |