AeroToss: UDP broadcast discovery + mDNS A record + имена

- Добавлен UDP broadcast discovery (порт 9999) как fallback
- Desktop отправляет broadcast каждые 3 секунды
- Android использует mDNS + UDP broadcast + Wi-Fi Direct
- mDNS: добавлена A-запись для разрешения IP
- Имена: Desktop=user@host, Android=manufacturer model
- TXT record: id, name, port, type для определения устройства
- Автоперерегистрация mDNS каждые 30 секунд
- mDNS: отправка query каждые 5 секунд
This commit is contained in:
2026-08-19 22:56:56 +03:00
parent ab7b917a01
commit 817e8f09aa
3 changed files with 164 additions and 2 deletions
@@ -18,6 +18,8 @@ class CompositeAndroidDiscovery(
private val _devices = MutableStateFlow<List<Device>>(emptyList())
override val devices: Flow<List<Device>> = _devices.asStateFlow()
private val udpDiscovery = UdpBroadcastDiscovery()
@Volatile private var scope: CoroutineScope? = null
@Volatile private var discoveryJob: kotlinx.coroutines.Job? = null
@@ -25,6 +27,7 @@ class CompositeAndroidDiscovery(
if (discoveryJob != null) return
nsdDiscovery.startDiscovery(servicePort)
udpDiscovery.startDiscovery(servicePort)
wifiDirectManager.initialize()
wifiDirectManager.discoverPeers()
@@ -32,10 +35,12 @@ class CompositeAndroidDiscovery(
discoveryJob = scope?.launch {
combine(
nsdDiscovery.devices,
udpDiscovery.devices,
wifiDirectManager.devices
) { nsdDevices, wifiDirectDevices ->
) { nsdDevices, udpDevices, wifiDirectDevices ->
val allDevices = mutableMapOf<String, Device>()
nsdDevices.forEach { allDevices["nsd:${it.id}"] = it }
udpDevices.forEach { allDevices["udp:${it.id}"] = it }
wifiDirectDevices.forEach { allDevices["wifi:${it.id}"] = it }
allDevices.values.toList()
}.collect { devices ->
@@ -48,6 +53,7 @@ class CompositeAndroidDiscovery(
discoveryJob?.cancel()
discoveryJob = null
nsdDiscovery.stopDiscovery()
udpDiscovery.stopDiscovery()
wifiDirectManager.stopDiscovery()
_devices.value = emptyList()
}
@@ -57,6 +63,7 @@ class CompositeAndroidDiscovery(
scope?.cancel()
scope = null
nsdDiscovery.dispose()
udpDiscovery.dispose()
wifiDirectManager.cleanup()
}