Concepts
Server profile — A named backend endpoint with atype of either lan (local network) or wan (internet). Profiles are stored as a JSON array in the registry under the serverProfiles key.
Probe list — The ordered sequence of URLs that GTV_FindActiveServer tests one by one until one responds successfully.
Active server — The first server from the probe list that passes a health-check ping. Its URL is written to m.global.activeServer by the calling task and persisted to the registry via GTV_RegSaveLastServer.
Default profiles
| id | name | baseUrl | type |
|---|---|---|---|
local_default | Local | http://172.17.11.2:3333 | lan |
public_default | Publico | https://admin.globaltv.lat | wan |
Profile management
GTV_LoadServerProfiles
REG_KEY_SERVER_PROFILES, sanitises the result, and falls back to GTV_DefaultServerProfiles() if the registry is empty or invalid.
Return value — A clean array of server profile objects.
GTV_SaveServerProfiles
profiles and writes the resulting array as JSON to REG_KEY_SERVER_PROFILES. Falls back to the default profiles if the sanitised list is empty.
GTV_ServerList
GTV_ServerCreateProfile
Display name for the server. Uses the normalised URL if blank.
The server base URL. Must start with
http:// or https://. Returns invalid if the URL cannot be normalised.Optional existing profile. When provided, its
id, builtIn, and enabled fields are preserved.roAssociativeArray, or invalid on invalid URL.
GTV_ServerUpsertProfile
id. Returns the updated array.
GTV_ServerDeleteProfile
id from the list. If removing the profile would leave the list empty, the original list is returned unchanged.
GTV_ServerCanDelete
true if the profile exists and the list has more than one entry.
Server lookup
GTV_ServerGetProfileById
id. Returns invalid if not found.
GTV_ServerGetProfileByBaseUrl
baseUrl matches the given URL. Returns invalid if not found.
Probe ordering
GTV_ServerBuildAutoProbeList
SERVER_LAN_FORCE_RETRIES times (default: 3), followed by WAN servers once.
LAN retry behaviour — Because LAN servers may take a moment to become reachable after the device wakes, they are probed multiple times before falling through to the public server.
SERVER_LAN_FORCE_RETRIES is read from AppConstants(). Setting it to 1 disables the retry burst and probes each LAN server only once.GTV_ServerBuildRequestSequence
GTV_ServerBuildAutoProbeList, but moves preferredBaseUrl to the front. Use this when a previously working server is known.
A base URL to prioritise. When empty, the standard auto-probe order is returned unchanged.
GTV_FindActiveServer
When non-empty, only this URL is probed. Used to verify a specific server without cycling through the full list.
"" if none respond.
On success, the URL is saved to the registry via GTV_RegSaveLastServer.
Example
URL utilities
GTV_ServerNormalizeBaseUrl
- Strips a trailing
/ - Returns
""for any URL that does not start withhttp://orhttps:// - Corrects
http://172.17.11.2(no port) tohttp://172.17.11.2:3333
GTV_ServerInferType
"lan" for private-network IP ranges (172.17.x.x, 192.168.x.x, 10.x.x.x, localhost), and "wan" for everything else.