mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add meshtastic service type to mDNS service discovery (#1401)
This commit is contained in:
parent
d324f77d63
commit
a6e7a0ef4f
2 changed files with 11 additions and 2 deletions
|
|
@ -16,11 +16,11 @@ class NetworkRepository @Inject constructor(
|
|||
val networkAvailable get() = connectivityManager.get().networkAvailable()
|
||||
|
||||
val resolvedList
|
||||
get() = nsdManagerLazy.get()?.serviceList(SERVICE_TYPE, SERVICE_NAME) ?: flowOf(emptyList())
|
||||
get() = nsdManagerLazy.get()?.serviceList(SERVICE_TYPES, SERVICE_NAME) ?: flowOf(emptyList())
|
||||
|
||||
companion object {
|
||||
// To find all available services use SERVICE_TYPE = "_services._dns-sd._udp"
|
||||
internal const val SERVICE_NAME = "Meshtastic"
|
||||
internal const val SERVICE_TYPE = "_https._tcp."
|
||||
internal val SERVICE_TYPES = listOf("_http._tcp.", "_meshtastic._tcp.")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,20 @@ import kotlinx.coroutines.cancel
|
|||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import java.util.concurrent.CopyOnWriteArrayList
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
internal fun NsdManager.serviceList(
|
||||
serviceTypes: List<String>,
|
||||
serviceName: String,
|
||||
): Flow<List<NsdServiceInfo>> {
|
||||
val flows = serviceTypes.map { serviceType -> serviceList(serviceType, serviceName) }
|
||||
return combine(flows) { lists -> lists.flatMap { it }.distinctBy { it.serviceName } }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
internal fun NsdManager.serviceList(
|
||||
serviceType: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue