Fix VRCOSC on windows: new mdns discovery and advertise; proper handling of vrc output port; change to keep advertise of the server receiver even when manual mode is used

This commit is contained in:
lucas lelievre committed 2026-10-27 02:20:42 +01:00
1 parent fe788ed3a7
commit f84ce0831e
20 files changed
+901 -277

No files matched your search

@@ -13,8 +13,6 @@ import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import com.appstractive.dnssd.createNetService
import com.appstractive.dnssd.discoverServices
import dev.slimevr.AppContext
import dev.slimevr.FeatureFlags
import dev.slimevr.Phase1Context
@@ -25,6 +23,7 @@ import dev.slimevr.android.buildinfo.SENTRY_RELEASE
import dev.slimevr.android.config.AndroidConfigStorage
import dev.slimevr.android.hid.createAndroidHIDManager
import dev.slimevr.android.ipc.createAndroidSolarXRWebsocketServer
import dev.slimevr.android.multicast.bindAndroidMulticast
import dev.slimevr.android.serial.AndroidFirmwareFlasher
import dev.slimevr.android.serial.createAndroidSerialServer
import dev.slimevr.android.timing.createAndroidWaiter
@@ -36,6 +35,7 @@ import dev.slimevr.firmware.FirmwareManager
import dev.slimevr.heightcalibration.HeightCalibrationManager
import dev.slimevr.keybind.KeybindManager
import dev.slimevr.logging.ServerLogSource
import dev.slimevr.mdns.createMdns
import dev.slimevr.networkprofile.NetworkProfileManager
import dev.slimevr.provisioning.ProvisioningManager
import dev.slimevr.resets.ResetsManager
@@ -180,11 +180,13 @@ class ForegroundService : Service() {
val boneRouting = BoneRoutingManager.create(scope = scope)
val bvhManager = BVHManager.create(skeleton = skeleton, storage = storage, scope = scope)
val vmcManager = VMCManager.create(scope = scope)
val oscQueryAddress = resolveAndroidLocalIpAddress()
val mdns = createMdns(scope = scope, address = oscQueryAddress, bind = ::bindAndroidMulticast)
val vrcOscManager = VRCOSCManager.create(
scope = scope,
oscQueryAddress = resolveAndroidLocalIpAddress(),
discoverServicesFlow = ::discoverServices,
serviceFactory = ::createNetService,
oscQueryAddress = oscQueryAddress,
browse = mdns.browse,
advertise = mdns.advertise,
)
val stepMountingManager = StepMountingManager.create(ctx = phase1, scope = scope)
val resetsManager = ResetsManager.create(ctx = phase1, skeleton = skeleton, stepMountingManager = stepMountingManager, scope = scope)
@@ -0,0 +1,48 @@
package dev.slimevr.android.multicast
import dev.slimevr.multicast.MulticastSocket
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.net.InetAddress
import java.net.InetSocketAddress
import java.net.NetworkInterface
import java.net.StandardProtocolFamily
import java.net.StandardSocketOptions
import java.nio.ByteBuffer
import java.nio.channels.ClosedChannelException
import java.nio.channels.DatagramChannel
private const val MAX_DATAGRAM_SIZE = 65_536
private class AndroidMulticastSocket(private val channel: DatagramChannel, private val group: InetSocketAddress) : MulticastSocket {
override suspend fun listen(onPacket: (ByteArray) -> Unit) = withContext(Dispatchers.IO) {
val buffer = ByteBuffer.allocate(MAX_DATAGRAM_SIZE)
while (true) {
buffer.clear()
try {
channel.receive(buffer)
} catch (_: ClosedChannelException) {
return@withContext
}
onPacket(buffer.array().copyOf(buffer.position()))
}
}
override suspend fun send(payload: ByteArray) {
withContext(Dispatchers.IO) { channel.send(ByteBuffer.wrap(payload), group) }
}
override suspend fun close() = withContext(Dispatchers.IO) { channel.close() }
}
suspend fun bindAndroidMulticast(group: ByteArray, port: Int, interfaceAddress: String): MulticastSocket = withContext(Dispatchers.IO) {
val groupAddress = InetAddress.getByAddress(group)
val iface = requireNotNull(NetworkInterface.getByInetAddress(InetAddress.getByName(interfaceAddress))) { "No network interface for $interfaceAddress" }
val channel = DatagramChannel.open(StandardProtocolFamily.INET)
.setOption(StandardSocketOptions.SO_REUSEADDR, true)
.setOption(StandardSocketOptions.IP_MULTICAST_IF, iface)
.setOption(StandardSocketOptions.IP_MULTICAST_LOOP, true)
.bind(InetSocketAddress(port))
channel.join(groupAddress, iface)
AndroidMulticastSocket(channel, InetSocketAddress(groupAddress, port))
}