discoverBridgesMdns static method
Searches the network for bridges using mDNS.
Implementation
static Future<List<String>> discoverBridgesMdns() async {
List<String> bridges = [];
final Set<String> discoveredPtr = {};
final Set<SrvResourceRecord> discoveredSvr = {};
final Set<IPAddressResourceRecord> discoveredIp = {};
final MDnsClient client = MDnsClient();
await client.start();
await for (final PtrResourceRecord ptr in client.lookup<PtrResourceRecord>(
ResourceRecordQuery.serverPointer("_hue._tcp.local"))) {
if (!discoveredPtr.add(ptr.domainName)) continue;
await for (final SrvResourceRecord srv
in client.lookup<SrvResourceRecord>(
ResourceRecordQuery.service(ptr.domainName))) {
if (!discoveredSvr.add(srv)) continue;
await for (final IPAddressResourceRecord ip
in client.lookup<IPAddressResourceRecord>(
ResourceRecordQuery.addressIPv4(srv.target))) {
if (!discoveredIp.add(ip)) continue;
bridges.add(ip.address.address);
}
}
}
client.stop();
return bridges;
}