Directory structure
source/ vs components/
| Directory | Purpose |
|---|---|
source/ | Pure BrightScript code that runs in the main thread: app entry point, global state initialisation, constants, and utility libraries (logging, registry, HTTP, server selection). |
components/ | SceneGraph components — each sub-folder contains an .xml interface declaration and a .brs behaviour file. Components run in their own render-thread scope. Task nodes under components/tasks/ execute on background threads. |
Component hierarchy
The SceneGraph tree at runtime looks like this:MainScreen and PlayerScreen are kept alive simultaneously once the user reaches the home state so that the channel overlay can be toggled without re-creating either node.
Key design patterns
Global state via m.global
All shared runtime state lives in a single roSGNode accessible to every component as m.global. The node is initialised once by MainScene.init() calling GTV_InitGlobalState() from source/AppState.brs. Components read fields directly and write through the node to trigger observers elsewhere.
Task-based async work
All network I/O is performed in dedicatedTask nodes so the render thread never blocks. MainScene creates each task node, sets its input fields, sets control = "RUN", and observes its done field to receive the result.
Observer pattern
SceneGraph field observers wire components together without direct references. A child component exposes an output field; the parent observes it and reacts in a callback.Periodic timers
Background polling (session auth check, ads, connectivity) usesroSGNode Timer instances attached as children of MainScene. Timer durations and intervals come from constants in AppConstants().
Technology stack
BrightScript
Roku’s scripting language. Used for all logic in both
source/ and components/ .brs files.SceneGraph XML
Declarative component definitions (
.xml). Describe the component interface, script includes, and initial child nodes.Roku OS
Target platform. The channel runs inside a sandboxed
roSGScreen created in source/main.brs.Makefile
Build tooling:
make zip packages the channel, make install sideloads it to a device via the Roku Developer Application Installer.The
manifest file declares the channel version, splash screens, supported resolutions, and supports_input_launch=1 (required for deep-link input events).