| 109 | delete claim.initial; |
| 110 | } |
| 111 | add(service) { |
| 112 | this.services.push(service); |
| 113 | |
| 114 | this.write(this.reply(null, 0x1F | 0x8000, service, true)); // remove before adding to clear stale state in clients |
| 115 | service.timer = Timer.repeat(timer => { |
| 116 | this.write(this.reply(null, 0x1F, service)); |
| 117 | timer.interval *= 2; |
| 118 | if (timer.interval > 16000) { |
| 119 | Timer.clear(timer); |
| 120 | delete service.timer; |
| 121 | } |
| 122 | else |
| 123 | Timer.schedule(timer, timer.interval, timer.interval); |
| 124 | }, 500); |
| 125 | service.timer.interval = 500; |
| 126 | } |
| 127 | update(service) { |
| 128 | const index = this.services.indexOf(service); |
| 129 | if (index < 0) throw new Error("service not found"); |