Skip to main content
AppConstants() is a BrightScript function that returns an associative array containing every tunable value in the app. Screens, tasks, and utilities call AppConstants() to read configuration rather than embedding magic values inline.
function AppConstants() as Object
    return {
        SERVER_LIST: [
            "http://172.17.11.2:3333",
            "https://admin.globaltv.lat"
        ],
        ' ... all other constants
    }
end function
AppConstants() creates a new associative array on every call. It is intentionally stateless — callers should store the result in a local variable if accessing multiple fields.

Server list

SERVER_LIST: [
    "http://172.17.11.2:3333",
    "https://admin.globaltv.lat"
]
SERVER_LIST provides the initial ordered list of backend servers. The app probes each server in turn using health checks and uses the first one that responds. LAN servers appear first so local deployments are preferred over the public endpoint.
EntryTypeDescription
http://172.17.11.2:3333LANLocal development server on the LAN segment.
https://admin.globaltv.latWANProduction public backend.
See Server manager for how the probe sequence is built and how profiles are persisted.

API paths

These paths are appended to the active server’s base URL to form full endpoint URLs.
ConstantValueDescription
PATH_HEALTH/healthHealth check endpoint. Polled to confirm a server is reachable before auth.
PATH_HANDSHAKE/api/v1/app/devices/handshakeDevice registration handshake on the primary server.
PATH_ADS/api/v1/app/ads/activeFetch currently active ads for the channel.
PATH_METRICS/api/v1/app/metrics/trackSend playback and usage metrics events.
PATH_AUTH_TPL/auth/{user}/{pass}Auth URL template. {user} and {pass} are replaced at runtime with encoded credentials.
PATH_PLAYLIST_TPL/auth/{user}/{pass}/playlist/m3u8/hlsPlaylist URL template. Returns an M3U8 HLS playlist after authentication.

Ads API

The ads system optionally uses a dedicated ads server (ADS_API_BASE_URL) separate from the main backend.
ConstantValueDescription
ADS_API_BASE_URLhttps://ads.globaltv.lat/api/v1Base URL for the dedicated ads API.
ADS_PATH_HANDSHAKE/app/devices/handshakeAds server handshake path.
ADS_PATH_ACTIVE/app/ads/activeFetch active ads from the ads server.
ADS_PATH_IMPRESSIONS/app/impressions/events/batchSubmit batched impression events.
ADS_USE_DEDICATEDtrueWhen true, the ads system uses ADS_API_BASE_URL instead of the main server.
ADS_HANDSHAKE_ENABLEDtrueWhen true, the ads handshake runs before fetching active ads.
To route ads traffic through the main backend instead of the dedicated ads server, set ADS_USE_DEDICATED to false. The system will fall back to PATH_ADS on the active primary server.

Timeouts and retries

ConstantValueDescription
TIMEOUT_HEALTH2500 msMaximum wait time for a health check response. Kept short so server probing is fast.
TIMEOUT_AUTH15000 msMaximum wait time for an auth request. Longer to allow for slow backends.
TIMEOUT_HTTP12000 msDefault HTTP timeout for all other requests.
RETRY_MAX3Maximum number of retry attempts for failed requests.
SERVER_LAN_FORCE_RETRIES3Number of times each LAN server is tried before falling back to WAN servers. Compensates for transient LAN latency.

Registry keys

These constants define the key names used when reading and writing to the Roku registry. See Registry for full usage.
ConstantKey nameStored value
REG_SECTIONGlobalTVThe registry section all keys are written under.
REG_KEY_USERusernameAuthenticated username.
REG_KEY_PASSpasswordAuthenticated password.
REG_KEY_SERVERlastServerBase URL of the last successfully connected server.
REG_KEY_CHANNELlastChannelIndexIndex of the last viewed channel in the grid.
REG_KEY_SAFE_MARGINuiSafeMarginPctUser-configured safe-area margin as a percentage.
REG_KEY_SERVER_PROFILESserverProfilesJSON-serialized array of server profile objects.

Polling intervals

ConstantValueDescription
ADS_POLL_MS10000 msHow often the ads task polls for new active ads.
NET_RETRY_MS30000 msHow often the connectivity task retries after detecting the network is down.
FREEZE_CHECK_MS10000 msInterval for the player freeze-detection watchdog.
SESSION_AUTH_CHECK_MS420000 ms (7 min)How often a background session auth check runs to detect expired credentials.

App identity

ConstantValueDescription
APP_IDENTITYGlobalTV_RokuStable identifier sent in handshake and metrics requests to identify this client.
APP_VERSION1.0.6Current app version string. Keep in sync with major_version.minor_version.build_version in the manifest.

Auth reason codes

GTV_AuthClassifyFailure() maps HTTP responses and body signals to one of these reason codes. UI components use the code to show the correct error message.
ConstantCodeMeaning
AUTH_REASON_NONE0No auth failure — request succeeded or failure is unclassified.
AUTH_REASON_NETWORK_DOWN460HTTP returned -1 — the network is unreachable.
AUTH_REASON_CREDENTIALS401Wrong username or password.
AUTH_REASON_INACTIVE470Account exists but subscription is inactive.
AUTH_REASON_PASSWORD_CHANGED471Credentials were valid but the password has been changed or the session was revoked.

Colors

All color values use Roku’s 0xRRGGBBAA hex format as strings.
ConstantValueUse
COLOR_PRIMARY0x2D57C1FFPrimary brand blue — buttons, highlights, focus indicators.
COLOR_BG0x0F1020FFApp background — deep navy, used for screen backgrounds.
COLOR_BG_CARD0x1A1A2EFFCard and panel background — slightly lighter than COLOR_BG. Also used as splash_color in the manifest.
COLOR_TEXT0xFFFFFFFFPrimary text — white.
COLOR_TEXT_DIM0x9E9E9EFFSecondary text — medium grey for labels and metadata.
COLOR_ERROR0xE53935FFError state — red.
COLOR_SUCCESS0x43A047FFSuccess state — green.
COLOR_WARNING0xFB8C00FFWarning state — amber.
COLOR_OVERLAY0x000000CCSemi-transparent black overlay for modal dialogs and banners.

Font sizes

Font sizes are integer pixel values for use with Roku’s roFontRegistry at 1080p design resolution. GTV_GetLayoutContext() scales them proportionally for other resolutions.
ConstantValueUse
FONT_H148Primary headings — screen titles.
FONT_H236Secondary headings — section labels.
FONT_BODY24Body text — descriptions, menu items.
FONT_SMALL18Small labels — metadata, timestamps.
FONT_NUMBER72Large channel number display in the number overlay.

Timing

ConstantValueDescription
SPLASH_MS1500 msHow long SplashScreen is held before the app proceeds. Matches splash_min_time in the manifest.
BANNER_MS3000 msHow long the channel banner remains visible after it is shown.
BANNER_FADE_MS300 msDuration of the banner fade-out animation.
CHANNEL_BUF_MS1200 msBuffer wait time after a channel change before the player starts. Prevents rapid-fire stream requests when navigating.

Flags

ConstantValueDescription
PARSER_STRICT_CHANNEL_NUMBERtrueWhen true, the M3U parser rejects channels that do not have a valid integer channel number.
CHANNEL_TILE_MODE"badge_only"Controls what is rendered on channel tiles in the grid. "badge_only" shows only the channel number badge without a logo.
LAYOUT_DIAGfalseEnables layout diagnostics — prints design resolution resolution and scale factor to the debug log.
MAINSCREEN_GRID_DIAGfalseEnables grid layout diagnostics on the main channel grid screen.
ADS_FLOW_DIAGfalseEnables verbose logging of the ads state machine transitions.
Leave all _DIAG flags set to false before packaging for submission. These flags generate significant log output and are intended only for local debugging.

Safe margin

The safe-area margin offsets the UI inward from all edges to avoid overscan on TVs that clip the image.
ConstantValueDescription
UI_SAFE_MARGIN_PCT0Default safe-area margin as a percentage of screen dimensions. 0 means no inset.
UI_SAFE_MARGIN_MIN_PCT0Minimum allowed value when the user adjusts the margin in Settings.
UI_SAFE_MARGIN_MAX_PCT10Maximum allowed value — 10% inset on each edge.
The user can override UI_SAFE_MARGIN_PCT at runtime from the Settings screen; the override is stored in the registry under REG_KEY_SAFE_MARGIN.

Helper functions

GTV_GetSafeArea()

Returns the usable screen rectangle after applying the safe-area margin.
function GTV_GetSafeArea(node as Object) as Object
    size = GTV_GetDesignSize(node)
    pct  = GTV_GetSafeMarginPct()

    x = Int(size.w * pct / 100.0)
    y = Int(size.h * pct / 100.0)
    w = size.w - (x * 2)
    h = size.h - (y * 2)

    return {
        screenW: size.w,
        screenH: size.h,
        x: x, y: y, w: w, h: h,
        pct: pct
    }
end function
Return fieldDescription
screenW, screenHFull screen dimensions before inset.
x, yTop-left origin of the safe area.
w, hWidth and height of the safe area.
pctThe margin percentage that was applied.

GTV_GetLayoutContext()

Builds a layout context used by all screens to position and size elements consistently. Derives a uniform scale factor so UI designed at 1920×1080 scales correctly on HD and SD displays.
function GTV_GetLayoutContext(node as Object) as Object
    safe  = GTV_GetSafeArea(node)
    scale = Min(safe.w / 1920.0, safe.h / 1080.0)
    ' ... returns safeX, safeY, safeW, safeH, sx, sy
end function
Return fieldDescription
safeX, safeYOrigin of the layout area within the safe region.
safeW, safeHDimensions of the layout area.
sx, syUniform scale factor (always equal — the smaller of the two axes).
rawSx, rawSyUnclipped per-axis scale factors before uniformity is applied.
Use GTV_LX(), GTV_LY(), GTV_LW(), GTV_LH() to convert 1080p design coordinates to screen coordinates using the context.

GTV_GetDesignSize()

Resolves the active design resolution for a node, reading from currentDesignResolution, the scene’s bounding rect, or the display mode — whichever is available first.
function GTV_GetDesignSize(node as Object) as Object
    ' Returns { w: Integer, h: Integer }
    ' Resolution determined from:
    '   1. node.currentDesignResolution
    '   2. scene.currentDesignResolution
    '   3. node/scene boundingRect
    '   4. roDeviceInfo.GetDisplayMode()
end function

GTV_AuthClassifyFailure()

Maps an HTTP response to one of the AUTH_REASON_* constants by inspecting the status code, response body, and server-provided reason strings. Supports both English and Spanish error messages.
function GTV_AuthClassifyFailure(
    httpCode       as Integer,
    reasonText     = invalid as Dynamic,
    bodyText       = invalid as Dynamic,
    subscriberActive = invalid as Dynamic
) as Integer
ParameterDescription
httpCodeThe HTTP status code. -1 indicates a network failure.
reasonTextThe HTTP reason phrase string from the response.
bodyTextThe raw response body — may be a string or a parsed associative array.
subscriberActiveOptional Boolean from the server payload. If false, returns AUTH_REASON_INACTIVE.
The function normalizes text (lowercases and strips accents) before pattern matching, so it handles accented Spanish characters in server responses correctly.

Build docs developers (and LLMs) love