mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-26 11:56:27 -08:00
Merge driver and feeder bridge
This commit is contained in:
10 files changed
+80
-183
No files matched your search
@@ -26,7 +26,7 @@ suspend fun createUnixDriverSocket(appContext: AppContextProvider) = acceptUnixC
|
||||
}
|
||||
|
||||
suspend fun createUnixFeederSocket(appContext: AppContextProvider) = acceptUnixClients(FEEDER_SOCKET_NAME) { channel ->
|
||||
handleFeederConnection(
|
||||
handleDriverConnection(
|
||||
appContext = appContext,
|
||||
messages = readFramedMessages(channel),
|
||||
send = { bytes -> withContext(Dispatchers.IO) { writeFramed(channel, bytes) } },
|
||||
|
||||
@@ -11,12 +11,9 @@ import dev.slimevr.desktop.platform.Version
|
||||
import dev.slimevr.driver.DriverBridge
|
||||
import dev.slimevr.driver.DriverBridgeInbound
|
||||
import dev.slimevr.driver.DriverBridgeOutbound
|
||||
import dev.slimevr.feeder.FeederBridge
|
||||
import dev.slimevr.feeder.FeederBridgeInbound
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
@@ -25,8 +22,6 @@ import kotlinx.coroutines.withContext
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
const val PROTOCOL_VERSION = 2
|
||||
|
||||
@@ -108,6 +103,9 @@ suspend fun handleDriverConnection(
|
||||
}
|
||||
}
|
||||
}
|
||||
msg.tracker_added?.let { ta ->
|
||||
bridge.inbound.emit(DriverBridgeInbound.TrackerAdded(id = ta.tracker_id, serial = ta.tracker_serial))
|
||||
}
|
||||
msg.position?.let { pos ->
|
||||
bridge.inbound.emit(DriverBridgeInbound.TrackerPosition(trackerId = pos.tracker_id, rotation = Quaternion(w = pos.qw, x = pos.qx, y = pos.qy, z = pos.qz), position = null))
|
||||
}
|
||||
@@ -116,30 +114,3 @@ suspend fun handleDriverConnection(
|
||||
bridge.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun handleFeederConnection(
|
||||
appContext: AppContextProvider,
|
||||
messages: Flow<ByteArray>,
|
||||
send: suspend (ByteArray) -> Unit,
|
||||
) = coroutineScope {
|
||||
val bridge = FeederBridge.create(id = appContext.server.nextHandle(), appContext = appContext, scope = this)
|
||||
|
||||
send(ProtobufMessage.ADAPTER.encode(ProtobufMessage(version = Version(protocol_version = PROTOCOL_VERSION))))
|
||||
|
||||
try {
|
||||
messages.collect { bytes ->
|
||||
val msg = ProtobufMessage.ADAPTER.decode(bytes)
|
||||
msg.version?.let { ver ->
|
||||
bridge.inbound.emit(FeederBridgeInbound.Version(protocolVersion = ver.protocol_version, firmware = ver.toString()))
|
||||
}
|
||||
msg.tracker_added?.let { ta ->
|
||||
bridge.inbound.emit(FeederBridgeInbound.TrackerAdded(serial = ta.tracker_serial))
|
||||
}
|
||||
msg.position?.let { pos ->
|
||||
bridge.inbound.emit(FeederBridgeInbound.TrackerPosition(trackerId = pos.tracker_id, rotation = Quaternion(w = pos.qw, x = pos.qx, y = pos.qy, z = pos.qz), position = null))
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
bridge.disconnect()
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ suspend fun createWindowsDriverPipe(appContext: AppContextProvider) = acceptWind
|
||||
}
|
||||
|
||||
suspend fun createWindowsFeederPipe(appContext: AppContextProvider) = acceptWindowsClients(FEEDER_PIPE) { handle ->
|
||||
handleFeederConnection(
|
||||
handleDriverConnection(
|
||||
appContext = appContext,
|
||||
messages = readFramedMessages(handle),
|
||||
send = { bytes -> withContext(Dispatchers.IO) { writeFramedPipe(handle, bytes) } },
|
||||
|
||||
Reference in new issue
Block a user