Hoichoi client platform · networking

Where networking happens

Both. The page's fetch makes every API, auth and licence call. Native has two network paths: the media engines (manifests and video segments) and one Ktor client for a short list of things that must run before or without the page.

Mapped by Claude (agent) from source at a950df76e · kwry 29b36e1Public · every page in this group shares one access rule

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

TrafficMade byWhy thereSource
Hoichoi APIs (catalog, auth, user, billing)JS fetchProduct logic; ships over the airapi/client.ts
DRM licence POSTJS fetchToken + URL are product; see DRMnative-main.ts:161
FairPlay certificateJS fetchSame origin as the pagenative-main.ts:169
Analytics (PostHog, SigNoz, CleverTap)JSThe page names every eventhost-telemetry.ts
Manifests + video segmentsNative media engine (Media3 HttpEngine/Cronet, AVPlayer)The decoder pulls bytes straight into the OS pipeline; routing gigabytes through JS would cost CPU and batteryExoUtil.kt:180
Offline download bytesNative Media3 DownloadManager / AVAssetDownloadURLSessionRuns in the background with no page; resumes after process deathDownloadsEngine.kt:479
OTA shell bundleNative KtorThe shell is what the page runs in, so it is fetched before any page existsStartupTasks.kt:43
Update policy /.well-known/shell-policy.jsonNative KtorDecides FORCE before the first loadUpdatePolicy.kt
Launch document (stored Home HTML)Native KtorCold-start speed: paints Home before JS bootsLaunchDocument.kt:212
Push notification imageNative KtorRendered while the app is deadPush.kt:106
Android TV homefeed catalogNative KtorHourly WorkManager job with no pageHomeFeed.kt:467
Widevine device provisioningNative Media3One-time OS CDM step to Google, no Hoichoi tokenCustomDrmCallback.kt:32
Subtitle file (iOS)Native URLSession (Swift)Parsed for the native subtitle layerPlayer.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).