AdsPollingTask) that continuously polls a dedicated ad server, processes snapshots, and emits ad payloads to the player for rendering.
Configuration
All ads constants are defined inAppConstants.brs:
When
ADS_USE_DEDICATED = true, the ads task uses ADS_API_BASE_URL (https://ads.globaltv.lat/api/v1) as its base URL instead of the main app server.Handshake
On startup,AdsPollingTask calls TryAdsHandshake() before beginning the polling loop. The handshake registers the device with the ad server:
ADS_PATH_HANDSHAKE_FALLBACK (empty string by default — no fallback configured).
Polling loop
After the handshake, the task enters awhile true loop with a wait() call:
ADS_POLL_MS = 10000ms (10 seconds). The server can return a next_check_at field (ISO 8601 timestamp or Unix timestamp) to override the next interval. The minimum enforced interval is 2,000 ms.
Poll parameters
Each poll request includes:| Parameter | Source |
|---|---|
device_id | m.global.deviceId or roDeviceInfo.GetChannelClientId() |
stream_position | Current channel number from m.global.channelList |
stream_id | m.top.streamId if set |
since_version | Version token from last successful response |
stream_position, one by stream_id) and tries them in order, falling back if one returns HTTP 422 with a stream-related error.
Active ad endpoint
Version tracking
Thesince_version token is updated from the version or since_version field in each successful response. This allows the server to send only changes since the last snapshot. If the server returns HTTP 422 with a since_version validation error, the token is reset to "" to force a full snapshot on the next poll.
Snapshot processing
ProcessPollResult() handles the response:
| HTTP code | Behavior |
|---|---|
200 | Parse JSON, update sinceVersion, emit ad payload |
204 | No changes — keep current ad state |
422 | If since_version validation error: reset token. Otherwise: log warning |
401 / 403 | Emit sessionInvalid event |
470 / 471 | Emit userInactive event |
| Other | Log warning, keep current ad state |
ads: [] array:
Impression reporting
Impressions are reported in batch to:ADS_PATH_IMPRESSIONS = "/app/impressions/events/batch" in AppConstants.brs.
Ad formats
Three ad display formats are supported, each rendered by a dedicated SceneGraph component:Format A — Banner
A banner ad displayed at the bottom or top of the screen. Component:
AdFormatA.Format B — Overlay
A semi-transparent overlay ad rendered on top of the video. Component:
AdFormatB.Format C — Viewport reduction
The video viewport is shrunk and the ad fills the freed space. Component:
AdFormatC.format.type field in the ad payload (e.g., "A", "B", or "C"). The AdManager component reads this field and instantiates the correct renderer.
Channel change reset
When the user switches channels, the polling task receives aresetChannel = true signal. This resets sinceVersion to "" and immediately polls for ads relevant to the new channel:
Session and account errors
The ads polling task emits signals on auth-related errors detected in poll responses:| Signal | Trigger |
|---|---|
sessionInvalid | Password changed or invalid credentials detected in HTTP error or payload |
userInactive | Account inactive flag or inactive keyword found in payload |
adsCleared | Ads cleared after session/inactive error, or server returns empty ad list |