demo · v144 · Isolated Web Apps
IoT Discovery (mDNS)
The motivating use case: discover printers, casting receivers, and smart-home devices via mDNS / SSDP. Multicast UDP on 224.0.0.251:5353 (Bonjour) or 239.255.255.250:1900 (SSDP). Direct Sockets in Chrome 144 finally lets web apps participate.
Isolated Web App only
This API is restricted to Isolated Web Apps. Out in regular tabs the constructor throws — you'll see the error caught and shown below.
UDPSocket: checking…
click join to begin…
the API
const sock = new UDPSocket({
localAddress: "0.0.0.0",
localPort: 5353,
multicastInterface: "0.0.0.0",
multicastTtl: 1,
multicastLoopback: true,
});
await sock.opened;
await sock.joined("224.0.0.251"); // mDNS group
for await (const { data, remoteAddress } of sock.readable) {
console.log("from", remoteAddress, new TextDecoder().decode(data));
}