diff --git a/README.md b/README.md index c35d0f1..241d973 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ All three implement the same protocols and features: |---|---| | **Xiaomi Mi TV `MiTV-AXSO0`** (Android TV 9, PatchWall) | ✅ Tested with the macOS app. The mobile apps use the same protocol and have so far been tested against a mock TV | | **Xiaomi Mi TV `MiTV-MOOR2`** (Android TV 11, no MiLink) | ✅ Tested with the macOS app, through the Android TV remote service ([#4](https://github.com/EndLess728/MiTV-Remote/issues/4)): pairing, navigation, volume, media keys, typing and switching HDMI inputs work. Recent apps isn't available | +| **Xiaomi Mi Box S `MIBOX4`** (Android TV) | ✅ Tested with the macOS app, through MiLink: found on the network and controlled with no pairing | | Other Mi TVs on Android TV with PatchWall | Expected to work, not tested | | Xiaomi TVs on Google TV | Expected to work through the Android TV remote service, not tested | @@ -173,7 +174,7 @@ Implementation notes: - **`downTime` and `eventTime` must be 0.** The TV then stamps the event with its own uptime clock. Sending the device's clock puts events "in the future" on the TV and can stall its input dispatcher until that time arrives. This was the hardest bug to find. - **Holding a key**: the TV releases a key on its own about 175 ms after the last DOWN, so held buttons resend DOWN every 100 ms with an increasing `repeatCount`, then send UP. - **Text**: MiLink has no text packet, so typing maps each character to an Android key code (plus Shift) and sends it as a keystroke. -- **Discovery**: Mi TVs advertise `_googlecast._tcp` with a TXT `md=MiTV-…` model, which the apps browse and resolve to an IPv4 address. +- **Discovery**: Mi TVs advertise `_googlecast._tcp` with a TXT `md=MiTV-…` model (Mi Boxes use `md=MIBOX…`), which the apps browse and resolve to an IPv4 address. ### Android TV Remote diff --git a/apps/macos/Sources/MiRemote/TVDiscovery.swift b/apps/macos/Sources/MiRemote/TVDiscovery.swift index ee6c3d1..ccc6821 100644 --- a/apps/macos/Sources/MiRemote/TVDiscovery.swift +++ b/apps/macos/Sources/MiRemote/TVDiscovery.swift @@ -52,7 +52,12 @@ final class TVDiscovery: ObservableObject { model = txt["md"] ?? "" friendly = txt["fn"] ?? name } - guard model.lowercased().hasPrefix("mitv") || name.lowercased().hasPrefix("mitv") else { continue } + // Mi TVs ("MiTV-…") and Mi Boxes ("MIBOX4"), which run MiLink too. + let isXiaomi = [model, name].contains { id in + let id = id.lowercased() + return id.hasPrefix("mitv") || id.hasPrefix("mibox") + } + guard isXiaomi else { continue } guard resolvers[name] == nil, !tvs.contains(where: { $0.id == name }) else { continue } resolve(result.endpoint, id: name, name: friendly, model: model) } diff --git a/apps/mobile/modules/milink/android/src/main/java/expo/modules/milink/MiLinkModule.kt b/apps/mobile/modules/milink/android/src/main/java/expo/modules/milink/MiLinkModule.kt index 8e8daba..cd05379 100644 --- a/apps/mobile/modules/milink/android/src/main/java/expo/modules/milink/MiLinkModule.kt +++ b/apps/mobile/modules/milink/android/src/main/java/expo/modules/milink/MiLinkModule.kt @@ -274,7 +274,11 @@ class MiLinkModule : Module() { val attrs = info.attributes ?: emptyMap() val model = attrs["md"]?.toString(Charsets.UTF_8) ?: "" val friendly = attrs["fn"]?.toString(Charsets.UTF_8) ?: name - if (!model.lowercase().startsWith("mitv") && !name.lowercase().startsWith("mitv")) return + // Mi TVs ("MiTV-…") and Mi Boxes ("MIBOX4"), which run MiLink too. + val isXiaomi = listOf(model, name).any { id -> + id.lowercase().let { it.startsWith("mitv") || it.startsWith("mibox") } + } + if (!isXiaomi) return // Android 14+ can resolve several addresses; the TV listens on IPv4. val host = if (Build.VERSION.SDK_INT >= 34) { info.hostAddresses.filterIsInstance().firstOrNull() diff --git a/apps/mobile/modules/milink/ios/MiLinkModule.swift b/apps/mobile/modules/milink/ios/MiLinkModule.swift index 44ec4b3..63f6c40 100644 --- a/apps/mobile/modules/milink/ios/MiLinkModule.swift +++ b/apps/mobile/modules/milink/ios/MiLinkModule.swift @@ -244,7 +244,12 @@ public class MiLinkModule: Module { model = txt["md"] ?? "" friendly = txt["fn"] ?? name } - guard model.lowercased().hasPrefix("mitv") || name.lowercased().hasPrefix("mitv") else { continue } + // Mi TVs ("MiTV-…") and Mi Boxes ("MIBOX4"), which run MiLink too. + let isXiaomi = [model, name].contains { id in + let id = id.lowercased() + return id.hasPrefix("mitv") || id.hasPrefix("mibox") + } + guard isXiaomi else { continue } guard resolvers[name] == nil, !reported.contains(name) else { continue } resolve(result.endpoint, id: name, name: friendly, model: model) }