Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion apps/macos/Sources/MiRemote/TVDiscovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Inet4Address>().firstOrNull()
Expand Down
7 changes: 6 additions & 1 deletion apps/mobile/modules/milink/ios/MiLinkModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down