The rule the code follows
JS makes every call that carries product meaning (APIs, entitlement, licence, analytics). Native makes a call only when no page is running yet, or the bytes go straight to the OS (video segments, the OTA shell, a push image while the app is dead). Ktor is the single native HTTP client, enforced by a script gate (Http.kt:26).
Every network path
| Traffic | Made by | Why there | Source |
|---|---|---|---|
| Hoichoi APIs (catalog, auth, user, billing) | JS fetch | Product logic; ships over the air | api/client.ts |
| DRM licence POST | JS fetch | Token + URL are product; see DRM | native-main.ts:161 |
| FairPlay certificate | JS fetch | Same origin as the page | native-main.ts:169 |
| Analytics (PostHog, SigNoz, CleverTap) | JS | The page names every event | host-telemetry.ts |
| Manifests + video segments | Native media engine (Media3 HttpEngine/Cronet, AVPlayer) | The decoder pulls bytes straight into the OS pipeline; routing gigabytes through JS would cost CPU and battery | ExoUtil.kt:180 |
| Offline download bytes | Native Media3 DownloadManager / AVAssetDownloadURLSession | Runs in the background with no page; resumes after process death | DownloadsEngine.kt:479 |
| OTA shell bundle | Native Ktor | The shell is what the page runs in, so it is fetched before any page exists | StartupTasks.kt:43 |
Update policy /.well-known/shell-policy.json | Native Ktor | Decides FORCE before the first load | UpdatePolicy.kt |
| Launch document (stored Home HTML) | Native Ktor | Cold-start speed: paints Home before JS boots | LaunchDocument.kt:212 |
| Push notification image | Native Ktor | Rendered while the app is dead | Push.kt:106 |
| Android TV homefeed catalog | Native Ktor | Hourly WorkManager job with no page | HomeFeed.kt:467 |
| Widevine device provisioning | Native Media3 | One-time OS CDM step to Google, no Hoichoi token | CustomDrmCallback.kt:32 |
| Subtitle file (iOS) | Native URLSession (Swift) | Parsed for the native subtitle layer | Player.swift:36 |
Should it all be JS?
Already JS, keep it
- Every API, entitlement and licence call
- Analytics
- FairPlay certificate
Must stay native
- Video segments and downloads: the OS decoder and background download service need the bytes directly
- OTA shell + update policy: there is no page yet
- Push image while dead: there is no page
- Widevine provisioning: a CDM step
Could move to JS
- TV homefeed catalog: the page could send the rows to publish whenever it runs; the worker would only write channels (also a product rule today, see Gaps)
- iOS subtitles: the page could fetch and pass text, as it does for the certificate
Native but borderline
- Launch document: native fetches the Home HTML to paint before JS. It exists for cold-start speed; it reads cookies and decides freshness natively. Keep only if the measured win holds.
Why one Ktor client
- One client
- Ktor over OkHttp on Android and NSURLSession on iOS (
islands/build.gradle.kts). The KDoc: "Both hosts and their islands use only this (tools/one-http-gate.sh)". - Every caller states its limits
- Timeout, redirect rule (exact-origin callers refuse redirects) and a body cap that refuses rather than truncates.
- Logs nothing
- Callers log the status only, because URLs and bodies carry tokens.
- Not used for
- Media: the engines bring their own HTTP stacks (Media3 HttpEngine/Cronet, AVFoundation).