MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / add

Method add

modules/network/mdns/mdns.js:65–87  ·  view source on GitHub ↗
(service)

Source from the content-addressed store, hash-verified

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");

Callers

nothing calls this directly

Calls 6

replyMethod · 0.95
repeatMethod · 0.80
scheduleMethod · 0.80
writeMethod · 0.65
pushMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected