Custom panels
Your channel can add a panel of its own to the SDK's tab strip. Build the panel as a SceneGraph component that extends the published MaestroCustomPanel base, create it, and hand it to the SDK with addPanelToEvent. The SDK then treats it as one of its own panels: a tab with your title and icon, the event and player clock pushed to it, focus and keys routed normally, panel view / engage / card-focus analytics beacons, and survival across config reloads.
Setup
- Copy the SDK's published
MaestroCustomPanelfolder into your channel (for example,components/maestro/MaestroCustomPanel/). The folder will be in the example repo (maestro-roku-sdk-example) once it ships. Don't edit the copy: copy it again to update. - Create a SceneGraph component that
extends="MaestroCustomPanel". - Call
addPanelToEventon theMaestroPanelnode.
<component name="MyStatsPanel" extends="MaestroCustomPanel">
<script type="text/brightscript" uri="MyStatsPanel.brs" />
<children>
<Label id="heading" translation="[40, 24]" />
<LabelList id="rows" translation="[40, 120]" itemSize="[640, 56]" />
</children>
</component>
sub init()
m.top.panelType = "myStats" ' unique key (letters, digits, _)
m.top.title = "My Stats" ' tab label
m.top.iconUri = "pkg:/images/myStatsNavIcon.png" ' tab icon (36 × 36)
m.top.order = 0 ' 0 = first tab; -1 = after the SDK's tabs
m.rows = m.top.findNode("rows")
m.rows.observeFieldScoped("itemFocused", "onRowFocused")
m.rows.observeFieldScoped("itemSelected", "onRowSelected")
end sub
' Called by the SDK each time the tab gets focus: fetch once per event
sub getData(params = invalid as dynamic)
if m.loadedEventId = m.top.eventID then return
m.loadedEventId = m.top.eventID
' fetch for m.top.eventID, then draw
end sub
' Focus came in from the tab bar
sub onFocusEntered()
m.rows.setFocus(true)
end sub
sub onRowFocused(event as object)
emitCardFocus("statRow", event.getData())
end sub
sub onRowSelected(event as object)
emitEngage("select", "statRow")
end sub
' Return false for keys the panel does not handle: the SDK moves focus to the tab bar
function onKeyEvent(key as string, press as boolean) as boolean
if press and key = "up" and m.rows.itemFocused = 0
clearCardFocus()
requestFocusReturn()
return true
end if
return false
end function
Then add the panel from your channel's Maestro script, before or after the SDK's config loads:
' Maestro.brs: call once m.maestro exists (Getting Started, step 2)
sub addMyStatsPanel()
panel = createObject("roSGNode", "MyStatsPanel")
accepted = m.maestro.callFunc("addPanelToEvent", {
node: panel
panelType: panel.panelType ' "myStats"
title: panel.title ' "My Stats"
iconUri: panel.callFunc("stagedIconUri") ' see Icons below
order: panel.order ' 0
})
if not accepted then print "Custom panel rejected: "; m.maestro.errorInformation.message
end sub
Spec fields
| Field | Required | Description |
|---|---|---|
node | yes | The panel node. Must extend MaestroCustomPanel (the SDK checks for a panelType field). |
panelType | yes | Unique identifier: letters, digits and _ only. Used as the node's id, the tab key, and the analytics type. See the reserved types below. |
title | yes | The tab label. Also the analytics panel name (e4). |
iconUri | no | The tab icon URI. A pkg:/ path must be staged with stagedIconUri() first (see Icons). Without one, the SDK's fallback tab icon shows. |
order | no | Tab position: 0 is first, the SDK's tabs shift right. Equal orders keep the insertion order. -1 or past the end goes last. Defaults to -1. |
addPanelToEvent returns true when the panel was accepted. A rejection is logged as addPanelToEvent rejected - <reason> and reported on errorInformation as { message, panelType }. Reasons:
- The spec isn't an associative array, or has no
node. - The node has no
panelTypefield (it doesn't extendMaestroCustomPanel). panelTypeis missing, or has characters other than letters, digits and_.panelTypeis a type the SDK builds itself:HelloWorld,EmptyView, or a panel type in the page config.panelTypeis reserved: a name theMaestroPanelnode already uses internally (for examplesceneoroverlays). Pick a distinctive type.titleis missing, ororderisn't a number.
removePanelFromEvent(panelType) removes the panel and its tab. Returns false for an unknown panel type.
Panel contract
The base declares all fields the SDK reads and writes. Override the named functions in your subclass.
| Direction | Field / function | What |
|---|---|---|
| Your init sets, SDK reads | panelType, title, iconUri, order | Tab and analytics identity. The spec's values override the node's own. |
| SDK writes | id, panelType | Both set to the spec's panelType. |
| SDK writes | name, client, clientConfig, displayQRCodes | As the SDK sets its own panels. name is the title. |
| SDK writes | eventID | The page config's first event, or the session's; "" on a multi-event page. Re-sent on every rebuild. |
| SDK writes | timeCode | Player position as epoch ms string, floored to 500 ms; "" before the first tick. |
| SDK writes | visible | Follows the tab, like any panel. |
| SDK calls | getData() | Each time the tab gets focus, and again when the tab strip is rebuilt. Also at build time when fetchDataOnInit is true. Make it safe to call repeatedly. |
| SDK calls | endSession() | When the session ends. An override must call mcpEndSession() to stop managed timers. |
| Override | onEventIdChanged(eventId) | A new event (stream switch). |
| Override | onTimeCodeChanged(timeCode) | The player moved (at most twice a second). |
| Override | onFocusEntered() | Focus entered from the tab bar: move focus to your first control. |
| Override | onKeyEvent(key, press) → boolean | Return false for keys the panel does not handle. See Focus and keys. |
| Call | emitEngage(action, target, metadata?) | Sends an engage beacon (e5 = action, e6 = target). |
| Call | emitCardFocus(card, index, list?) | Sends a card-focus beacon after 300 ms of dwell. |
| Call | clearCardFocus() | Cancels any pending card-focus beacon. |
| Call | requestFocusReturn() | Returns focus to the SDK's tab bar, or to your channel in single-tab mode. |
| Call | mcpTimer(seconds, callbackName, repeat?) | A timer that endSession stops automatically. |
| Call | showError(title, subTitle?, iconUri?, width?, height?) | Shows the SDK's error view in the panel's place. |
| Call | reloadPanel() | Clears the error view and calls getData again. |
| Call | stagedIconUri() | Returns the icon URI suitable for passing to addPanelToEvent (see Icons). |
| Call | stagedUri(uri) | Returns any pkg:/ URI copied to tmp:/, where the SDK can load it. |
A setDataToPanel write for your panel type (before or after the add) is applied field by field and re-applied on every rebuild. Only fields the node declares are written on a rebuild.
userSettings hide_panel applies to a host panel: it gets no tab.
Focus and keys
- Down from the tab bar enters the panel and calls
onFocusEntered(). - A key your
onKeyEventreturnsfalsefor goes to the SDK. Back, Up and Left move focus to the tab bar (Left goes to the overlay when one is on screen). A short OK stays in the panel. - Holding OK to close the drawer works only in builds that enable the long press (Paramount today).
- Single-tab mode: with
hidePanelSelector: trueinconfigand a host panel as the only tab, there is no tab bar. Back from the panel bubbles to your scene.requestFocusReturn(), or removing the panel while it has focus, sets theMaestroPanelfieldhandleLoadingSceneActionto"returnFocus". Observe it increateMaestroPanel()withobserveFieldScopedand take focus back:
sub onMaestroHandleLoadingSceneAction(event as object)
if event.getData() = "returnFocus" then m.maestro.showPanel = false ' the showPanel observer moves focus
end sub
Lifecycle
- Before the config lands: the spec is kept and the panel is mounted on the next build, which also sends
rendered:channelswith the panel listed. - After the config lands: the panel is mounted immediately, the tab strip is rebuilt, and
rendered:channelsis sent again.panelsBuiltis not set again. The rebuild re-focuses the current tab: that tab's panel getsgetData()again, anduserViewedPaneland a panel view follow. - Debug panel: a host panel counts as a supported panel, so it replaces the
HelloWorlddebug panel shown withuseProdEnv: false. - Same
panelTypeadded again: the same node updates its metadata; a different node replaces it. If the viewer was inside the panel being replaced, focus returns to the tab bar first. - Config reload,
userSettingsrebuild oruserDidStartWatchingEvent: host panels are kept across rebuilds and have their event fields re-applied. - SDK panel with the same type: a configured SDK panel whose type matches a host panel is skipped. The host panel wins.
removePanelFromEvent:endSessionis called, the node is detached, the tab is removed, andrendered:channelsis sent. If the viewer was inside the panel, focus returns to the tab bar first (single-tab mode: see Focus and keys).destroySDK: all host panels are ended and detached. AfterrestartSDK, add them again.- Single-tab mode (
hidePanelSelector: truewith one tab): adding a host panel to a page with one SDK panel makes two tabs; the tab bar appears and the panels move back under it.
Icons
The SDK draws the tab icon from inside its component library, where your channel's pkg:/ path does not resolve. Stage the icon before calling addPanelToEvent: pass panel.callFunc("stagedIconUri") as the spec's iconUri.
stagedIconUri() copies a pkg:/ icon to tmp:/maestroCustomPanel_<panelType>_<filename> and returns that path. http(s):// and tmp:/ URIs pass through unchanged. Call it after iconUri and panelType are set on the node.
For error view icons, use stagedUri(uri) (it accepts any URI, not just the icon field).
Analytics
The panel's panelType is its analytics e2_class and e3_order; its title is e4_family. Because the SDK cannot name host panel types in advance, they use the same generic builders as designed panels (panelViewDesigned / panelEngageDesigned).
- View: sent on the 1-second focus debounce, as a generic view event.
- Engage: call
emitEngage(action, target)from your panel code. The SDK builds the beacon from thepanelEngagefield and drops an engage without anaction. Avariantorpanelkey in the metadata is ignored. - Card focus: call
emitCardFocus(card, index)when a list item gets focus; callclearCardFocus()when focus leaves the list.
Your channel receives the beacons on trackAction and trackImpression like any other panel.
Rules
mcpprefix is reserved. The base's scripts and yours share one scope (as every SceneGraph parent and child do). A function named the same as one in the base replaces it. Override only the plain-named functions above (getData,onFocusEntered, etc.).- An
endSessionoverride must callmcpEndSession(), or the base's managed timers keep running. idis overwritten withpanelTypeby the SDK. Do not rely on the node's initial id.- Multi-event pages pass
""foreventID: there is no single event to fetch for. - Keep the base plain BrightScript. The published folder uses no BrighterScript features (
import,namespace, template strings) so it compiles as-is in any channel.