Skip to content

Latest commit

 

History

History
193 lines (151 loc) · 17 KB

PORTING.md

File metadata and controls

193 lines (151 loc) · 17 KB

Porting to TVs

How WittyMediaClient reaches Apple TV, Android TV, Plasma Bigscreen and FreeBSD, what is done, and what is left. The aim is that a TV port is a matter of building and testing, not a redesign. PLATFORMS.md says how far each claim has been checked; this page says what the plan is.

Where this stands: Android TV has run on an emulator with arrow keys and OK, against a real server, and nothing has yet run on a real TV or remote: PLATFORMS.md has the details. The Apple apps compile with Xcode 27, CI builds them on every pull request, and Apple TV and iPhone have run in their simulators; nothing has run on a real Apple TV.

The decision

tvOS has no web view. Apple doesn't offer WebKit to tvOS apps at all, so nothing based on the server's web interface can run on an Apple TV. Whatever else is shared, the screens on an Apple TV have to be native.

So each family gets a native app, and what they share is data and rules rather than code:

Apple TV, iPhone, iPad, Mac Android TV, Google TV, Fire TV, phones, tablets
Screens SwiftUI Jetpack Compose
Player AVPlayer, with the system's controls on Apple TV Media3 (ExoPlayer), with our controls
API, identity, discovery apple/WittyKit android/.../net
Shared between the two shared/data: themes, wording, test cases, button meanings. shared/fixtures: real server answers the same

The server decides everything two clients would have to agree on: docs/CLIENT-API.md in its repository. A rule written in only one client is a bug waiting to happen, so rules that must live in a client (retries, the playback clock) are written the same way in both, with the same names and the same tests: PlaybackRules.swift and PlaybackRules.kt.

Kotlin Multiplatform and a shared UI toolkit were looked at and turned down: see DESIGN.md.

The list

Area Apple TV Android TV
Starts from the launcher System LEANBACK_LAUNCHER and a banner in the manifest. One APK for phones and TVs, with nothing required of the device
Moving focus The focus engine: the Siri Remote's clickpad and swipe drive it, with no code of ours. Rows and pads are focusSection()s. Nothing uses onTapGesture or hover Compose's D-pad focus. FocusBox is the one focusable surface, and remoteRow keeps left and right within a row. Nothing depends on touch or hover
Seeing focus .card buttons lift, as the system does it A 3dp ring and 5% larger, with no animation. Not on a touch screen
First focus prefersDefaultFocus in a focusScope requestFocus on the likeliest control
Focus after Back Explicit on Home. Elsewhere the system's, unverified Remembered per screen by focusKey, and restored. Seen working on an emulator
Disabled controls Never .disabled, which loses focus Keep focus and do nothing, and a screen reader is told
Back and Menu onExitCommand steps back through sign-in. Whether Back leaves AVPlayerViewController inside a stack needs checking Back goes up one level; only Home leaves the app. Search and Profile go to Home
Ten-foot sizes Tokens.swift: gutter 90, edge 60, targets 48, system text styles TvMetrics in Theme.kt: gutter 58, edge 27, targets 48, text a quarter larger. All from the server's design tokens
Typing TextField opens the system keyboard Moving down to a text box opens the system's TV keyboard, which takes the arrows. Back shuts it, and then up and down leave the box. Seen on an emulator's keyboard, and a real TV's may differ
Signing in from a phone Code on the TV, approved on a phone, with a QR code The same, and six digits typed with arrows and OK
Finding a server NWBrowser NsdManager
Playback AVPlayer. No MKV, so the server remuxes it, nearly for free Media3. MKV plays directly
Asking the device what it plays availableHDRModes, VTIsHardwareDecodeSupported, output channels MediaCodecList, the display's HDR types, AudioCapabilities
HDR appliesPreferredDisplayCriteriaAutomatically SurfaceView and the display's reported types. dv5 only with a Dolby Vision decoder
Frame rate The same setting Media3's default, which only switches when it's seamless. Turning on full switching is an experiment for a real TV
Audio passthrough Left to AVPlayer Media3 passes through what AudioCapabilities reports over HDMI
Remote commands, now playing externalMetadata and the system player MediaSession: while a film is open, and for as long as there's a queue for sound, in a MediaSessionService
Top shelf or channels Top Shelf extension, reading a file the app writes. No network or token in it The app's own channel and Watch Next entries, with sdui-topshelf. Never seen on a home screen: PLATFORMS.md
Live TV Its own guide and channel screens The server's guide page
Screen readers VoiceOver labels and groups TalkBack labels, roles, states and live regions

Android TV, step by step

  1. Build it. Done. gradle assembleSideload in android/, in WSL, with ~/android-sdk.
  2. Run it on an emulator. Done. With system-images;android-36;android-tv;x86_64, under WSL's /dev/kvm. Start a new image with -wipe-data the first time: without it the data partition comes out empty and the emulator hangs at boot.
  3. Check with a D-pad. Done on the emulator: starting up, finding a server, the number pad, Home, rows, Back returning focus, the seek bar, the track lists and Back from the player. What that found is in the changelog.
  4. Then a cheap TV stick, which is the device this app is judged on.
  5. Channels. Built, never seen. The Watch Next row and a channel of our own (androidx.tvprovider), from the server's GET /sdui/topshelf. The launcher can't send a sign-in, so the pictures are fetched into the app's cache and lent to it, as the Top Shelf does. Compiled only: not once seen on a home screen (PLATFORMS.md).
  6. Google Play's TV checks want a banner (done), no required touch screen (done), and a D-pad path to everything.

Apple TV, step by step

  1. Build it. Done. xcodegen generate in apple/, then Xcode 27. CI does it on every pull request.
  2. Run it in the simulator. Done against a real server: PLATFORMS.md.
  3. Choose a team for WittyMedia-tvOS and WittyMedia-TopShelf, and tick the App Group on both. Without it the Top Shelf is simply empty.
  4. Work through the Apple TV list in OWNER-STEPS.md.

Games on a PC: with no web view, an Apple TV can only start the game on the PC and say what to do next. No Moonlight client on Apple devices has a URL scheme, and its GPL-3.0 code can't go inside this app. A separate Apple TV app under the GPL, published on its own terms, is the only way to do better, and that's the owner's call.

What the API gives a TV

  • /capabilities says which apps work with this server: see "Which app works with which server" in the API guide.
  • Stream tokens let a player with no way to set headers open media. AVPlayer is that player, so every media route a TV needs has to accept one. Live channels didn't, and now do: GET /tv/{key}/tune?streamToken=1.
  • /playback takes the device's real abilities and answers with the decision, and explain in plain words.

FreeBSD

Electron has no official FreeBSD builds, and electron-builder can't make a FreeBSD package without them. FreeBSD's ports tree builds Electron itself instead. As of November 2026 the tree has devel/electron41 to electron44, and electron42 is the one seen with a package, for amd64 on FreeBSD 14 and 15. So:

  • The package holds only the app: app.asar, a launcher, an uninstaller, the desktop entry and an icon, under 100 KB in all. It depends on one Electron port, and on the DejaVu fonts as Electron brings none. One codebase, and Electron's security updates come through pkg upgrade. A native shell around a system web view, the other way to get here, would have meant a second window and security layer to keep right.
  • npm run package:freebsd runs on FreeBSD, finds the newest Electron with a package, and builds with pkg create. CI does this free of charge in a virtual machine on GitHub's Linux runners, with vmactions/freebsd-vm, from the quarterly packages a FreeBSD release uses. The latest packages, which that virtual machine comes set to, can go weeks with no Electron for amd64 while a new one builds: in November 2026 they had none. A package depending on an Electron that people's systems don't have couldn't be installed.
  • The launcher, desktop/build/freebsd/wittymediaclient.sh, sorts out what the app can't:
    • Sound. This Electron plays through a sound server, and a video it can't open sound for never starts its clock. FreeBSD runs none by default, so the launcher starts sndiod for as long as the app is open if nothing is running. With no sound card, it asks Chromium for no sound, and the picture plays.
    • Settings. It clears ELECTRON_RUN_AS_NODE and NODE_OPTIONS, which the fuses switch off in the other builds.
  • app.isPackaged is false there, as a shared Electron starts the app from the outside. The app looks at whether it's in an archive instead, to keep developer tools off.
  • Moonlight is found on PATH, as on Linux.

Removing it asks in plain words, removes only what's the app's, and says what's left, as on the other systems: INSTALLING.md. scripts/test/installers-freebsd.sh proves that in a throwaway virtual machine.

To put it in the ports tree, it would need a multimedia/wittymediaclient port. That's a small one, as package.mjs already does what it needs, and it's for the owner to submit.

Plasma Bigscreen

KDE's TV shell, released with Plasma, for HTPCs and small boards. Packaged for Fedora, Arch, Debian's next release and others. What it does, read from its source (invent.kde.org/plasma/plasma-bigscreen) and then checked by running 6.8.2:

Question Answer
How does the launcher choose apps? applicationlistmodel.cpp lists every application that isn't hidden, isn't run in a terminal, and isn't on its blocklist. No special key or category. Categories=Game puts it in a row for games
Wayland? Yes. It's a Wayland session, plasma-bigscreen-wayland, with XWayland beside it. Electron 45 picks Wayland by itself there
Flatpak? Optional. Its site suggests Flathub as one source of apps, and nothing needs it
How can an app tell? The session sets PLASMA_PLATFORM=mediacenter and PLASMA_DEFAULT_SHELL=org.kde.plasma.bigscreen, and the app reads them
Full screen? KWin maximises every window with no border anyway. The app asks for the whole screen
Text input plasma-keyboard, which takes arrows and Enter. Chromium only talks to it with --enable-wayland-ime, which the app asks for
Keyring Using it opens the wallet's set-up wizard over the app. A TV doesn't use it. Chromium reaches it two ways, so both are shut

How input reaches an app. plasma-bigscreen-inputhandler turns remotes and controllers into ordinary key presses:

Source Button The page sees
HDMI-CEC Up, Down, Left, Right, Select Arrows, Enter
HDMI-CEC Back, Exit Escape, which KDE says many TVs keep for themselves
HDMI-CEC Home, Clear Goes to the shell, and the app isn't told
Controller D-pad, left stick, A Arrows, Enter
Controller B Escape
Controller Select BrowserBack
Controller Guide The shell's home overlay

A controller goes to the page, not through this. The handler stops translating when another program opens the device, and Chromium does for the Gamepad API, so the page's own controller code in web/src/tv.ts takes over. That was seen happening, and it's why presses aren't handled twice.

Back is the one the app had to add. The server's page goes back a page on BrowserBack and GoBack, and on Escape it only closes what's open. A CEC remote's Back is Escape. So in TV mode, desktop/preload.js waits until the page's own listeners have run, and if nothing used the Escape and nothing is open, the app goes back a page. At the top of the app it opens the menu instead. The list of what counts as open is copied from web/src/tv.ts, so if that changes, this has to as well.

The interface is the server's own TV mode (it was its big screen mode until WittyMediaServer #297). The app adds ?tv=1 to the address, which is the same mode a TV browser gets. There's no second interface to keep up. What comes next for Bigscreen, a native Kirigami app included, and how to build and test it: PLASMA-BIGSCREEN.md.

Packages: .deb, .rpm and .pacman add the entry a launcher needs, and CI checks it on every build (scripts/test/bigscreen-entry.sh): a visible application that doesn't run in a terminal, in the video categories and not in Game, with no --tv in it, since the session decides. An AppImage adds no entry. There's a Flatpak and a Snap from 0.5.0, made by electron-builder from the same configuration (npm run package:flatpak, package:snap). The Flatpak is a bundle on the release, not a Flathub listing; its sandbox has --device=all, for controllers. Neither has been run, in Bigscreen or anywhere. Bigscreen's own distributions use their package managers, so those packages stay the ones to use.

For Bigscreen's packagers: on Fedora 44, plasma-bigscreen alone stops at an error screen, as the launcher needs plasma-nm, and displays need kscreen.

To try it in a virtual machine: Fedora's cloud image, then dnf install plasma-bigscreen plasma-nm kscreen sddm, with Session=plasma-bigscreen-wayland in SDDM's autologin, and -device virtio-vga,xres=1920,yres=1080 in QEMU. Its kernel leaves out sound, so add kernel-modules.

Android's processors

There's an APK for each of armeabi-v7a, arm64-v8a, x86 and x86_64, and a universal one with all four, split in android/app/build.gradle.kts. libwebrtc's library is 7 to 16 MB a processor, so a device need only carry its own. A dependency that brings in a library missing for one of them, or a processor's APK that carries another's, fails android/scripts/check-abis.sh in CI. PLATFORMS.md has what was checked.

What a TV app doesn't have of its own

Android TV shows the server's own page for everything but video, and that's where disc menus, books, music with its queue, games and the guide come from. Apple TV has no web view, so it has screens of its own for music, photos and channels, and says plainly what it can't show. What's left to build there, from the server's docs/CLIENT-API.md, "What a TV app must build itself": disc menus, a reader, radio, games, and music beyond albums and tracks. Features has where each stands.

What a TV offers: the server's TV levels

Every screen has a TV level in the server's table (its docs/TV-MODE.md, sent in the SDUI catalogue as tvLevels): full, view or desktopOnly. A TV app follows it, so the server's own TV mode and every TV app make the same choices.

  • desktopOnly: in place of the editor, a card with the screen's name, the table's note ("To change this, use the WittyMediaClient app on a Windows or Mac computer, or a web browser."), the page's address, a QR code of it, and a few lines of what is set now from GET /sdui/tv-summary/{summary}. Back has focus. When the server's address is one only the TV can reach, the QR code uses the first of the summary's addresses (the server on the home network).
  • view: the values shown, nothing changed. On Android TV the server's own page does this (?tv=1).
  • full: as now. Console and gaming screens (controllers, mapping, game settings, cores) are always a TV's own.

A server older than tvLevels sends no table: a TV app then keeps its old behaviour (every server page a QR card on Android TV). The desktop app on a Windows or Mac computer keeps every screen out of TV mode. In TV mode it is the server's page, which follows the table by itself; the app says what it is in the address: client=tv on a Plasma Bigscreen session (a TV device: the address and a QR code), client=desktop when started with --tv anywhere else (a computer: "Leave TV mode to change this." and a Leave TV mode button). Android TV's pageAddress adds client=tv.

Android TV: net/TvLevels.kt (the rules, tested in TvLevelsTest), Nav.serverPage() (a server page opens unless it is desktopOnly), OnPhoneScreen (the card), and the app's own layout and name-and-logo editors, which are desktopOnly parts (app.layout-editor, app.brand-editor). Apple TV and Plasma Bigscreen: see MAC-FOLLOW-UPS.md and below.