This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
dns.ts
53 lines (47 loc) · 1.53 KB
/
dns.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
let dns: jacdac.RoleManagerClient
function describe(dev: jacdac.Device) {
let name = ""
if (dev == jacdac.selfDevice())
name = "<self>"
else if (dns) {
const bound = dns.remoteRequestedDevices.find(d => d.boundTo == dev)
if (bound) name = "(" + bound.name + ")"
}
return `${dev.shortId} ${name}`
}
function describeRemote(dev: jacdac.RemoteRequestedDevice) {
let bnd = dev.boundTo ? dev.boundTo.shortId : ""
const n = dev.candidates.filter(c => c != dev.boundTo).length
if (n) {
if (bnd) bnd += "+" + n
else bnd = "" + n
}
if (bnd) bnd = "(" + bnd + ")"
return `${dev.name} ${bnd}`
}
function operateDNS(ourDNS: jacdac.Device) {
dns = new jacdac.RoleManagerClient(ourDNS.deviceId);
dns.scan()
menu.show({
title: "Bind function",
update: opts => {
opts.elements = dns.remoteRequestedDevices
.filter(r => r.name && r.name[0] != ".")
.map(r =>
menu.item(describeRemote(r), () => {
const newD = selectDevice(r.name, d => r.isCandidate(d))
r.select(newD)
}))
opts.elements.push(menu.item("Clear all names", () => {
dns.clearNames()
resetAll() // and reset everyone, just in case
}))
}
})
}
function allDNSes() {
return jacdac.devices().filter(hasDNS)
function hasDNS(d: jacdac.Device) {
return d.hasService(jacdac.SRV_ROLE_MANAGER)
}
}