(host, client)
| 28 | static get() @ "xs_net_get"; |
| 29 | |
| 30 | static resolve(host, client) { |
| 31 | if (!host.endsWith(".local")) |
| 32 | return this._resolve(host, client); |
| 33 | |
| 34 | const socket = new Socket({kind: "UDP"}); |
| 35 | socket.host = host; |
| 36 | socket.client = client; |
| 37 | socket.callback = callback; |
| 38 | |
| 39 | host = host.split("."); |
| 40 | if (2 !== host.length) |
| 41 | throw new Error("unrecognized"); |
| 42 | |
| 43 | host[0] = ArrayBuffer.fromString(host[0]); |
| 44 | host[1] = ArrayBuffer.fromString(host[1]); |
| 45 | |
| 46 | const packet = new Uint8Array(12 + host[0].byteLength + host[1].byteLength + 3 + 4); |
| 47 | packet[5] = 1; // 1 question |
| 48 | let position = 12; |
| 49 | packet[position++] = host[0].byteLength; |
| 50 | packet.set(new Uint8Array(host[0]), position); position += host[0].byteLength; |
| 51 | packet[position++] = host[1].byteLength; |
| 52 | packet.set(new Uint8Array(host[1]), position); position += host[1].byteLength; |
| 53 | packet[position + 2] = packet[position + 4] = 1; |
| 54 | packet[position + 3] = 0x80; |
| 55 | |
| 56 | let count = 3; |
| 57 | socket.timer = Timer.repeat(function (id) { |
| 58 | if (0 === count--) { |
| 59 | socket.client(socket.host) |
| 60 | Timer.clear(id); |
| 61 | return socket.close(); |
| 62 | } |
| 63 | trace(`query ${socket.host}\n`); |
| 64 | socket.write("224.0.0.251", 5353, packet.buffer); |
| 65 | }, 1000, 1); |
| 66 | } |
| 67 | static _resolve(host, callback) @ "xs_net_resolve"; |
| 68 | } |
| 69 |
no test coverage detected