mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-21 17:41:28 -08:00
Lock provisioning trackers to only UDP trackers
This commit is contained in:
1 parent
9d541a3c09
commit
e2bdc27c99
2 files changed
+18
-18
No files matched your search
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import solarxr_protocol.datatypes.DeviceOrigin
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
|
||||
fun isOnlineStatus(status: TrackerStatus): Boolean = when (status) {
|
||||
@@ -27,7 +28,7 @@ private fun deviceStatusFlow(
|
||||
) = server.context.state.flatMapLatest { state ->
|
||||
val device = state.devices.values.find { device ->
|
||||
val deviceState = device.context.state.value
|
||||
matches(deviceState.id, deviceState.macAddress)
|
||||
deviceState.origin == DeviceOrigin.UDP && matches(deviceState.id, deviceState.macAddress)
|
||||
}
|
||||
device?.context?.state?.map { it.status } ?: flowOf(TrackerStatus.DISCONNECTED)
|
||||
}
|
||||
@@ -37,25 +38,22 @@ private fun deviceAndConnectionStateFlow(
|
||||
server: VRServer,
|
||||
mac: String,
|
||||
) = server.context.state.flatMapLatest { serverState ->
|
||||
val device = serverState.devices.values.filter { d ->
|
||||
d.context.state.value.macAddress?.uppercase() == mac
|
||||
}.lastOrNull()
|
||||
if (device == null) {
|
||||
flowOf(Pair(TrackerStatus.DISCONNECTED, null))
|
||||
} else {
|
||||
device.appContext.udpServer.context.state.flatMapLatest { udpState ->
|
||||
val conn = udpState.connections.values.find { c ->
|
||||
c.context.state.value.deviceId == device.context.state.value.id
|
||||
}
|
||||
if (conn == null) {
|
||||
device.context.state.map { dState -> Pair(dState.status, null) }
|
||||
} else {
|
||||
combine(device.context.state, conn.context.state) { dState, cState ->
|
||||
Pair(dState.status, cState)
|
||||
}
|
||||
val device = serverState.devices.values.lastOrNull { d ->
|
||||
val dState = d.context.state.value
|
||||
dState.origin == DeviceOrigin.UDP && dState.macAddress?.uppercase() == mac
|
||||
}
|
||||
device?.appContext?.udpServer?.context?.state?.flatMapLatest { udpState ->
|
||||
val conn = udpState.connections.values.find { c ->
|
||||
c.context.state.value.deviceId == device.context.state.value.id
|
||||
}
|
||||
if (conn == null) {
|
||||
device.context.state.map { dState -> Pair(dState.status, null) }
|
||||
} else {
|
||||
combine(device.context.state, conn.context.state) { dState, cState ->
|
||||
Pair(dState.status, cState)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: flowOf(Pair(TrackerStatus.DISCONNECTED, null))
|
||||
}
|
||||
|
||||
suspend fun waitForConnected(
|
||||
|
||||
@@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import solarxr_protocol.datatypes.DeviceOrigin
|
||||
import solarxr_protocol.rpc.StartWifiProvisioningRequest
|
||||
import solarxr_protocol.rpc.StartWifiScanRequest
|
||||
import solarxr_protocol.rpc.StopWifiProvisioningRequest
|
||||
@@ -77,6 +78,7 @@ private fun buildUnifiedTrackerList(
|
||||
val onlineMacs = devices.values.mapNotNull { device ->
|
||||
val state = device.context.state.value
|
||||
val mac = state.macAddress?.uppercase() ?: return@mapNotNull null
|
||||
if (state.origin != DeviceOrigin.UDP) return@mapNotNull null
|
||||
if (!isOnlineStatus(state.status)) return@mapNotNull null
|
||||
mac
|
||||
}.toSet()
|
||||
|
||||
Reference in new issue
Block a user