Skip to main content

Getting Started

How a Roku channel loads the Maestro SDK, starts a session, shows the panel and cleans up. Panels, overlays and modules build on these steps: see Panel Integration and Overlay Integration.

Before you start​

  • A Roku device in developer mode, and a SceneGraph channel you can sideload
  • A Maestro site ID, and the page ID or event ID of the content to show
  • The SDK version to load, from Maestro

How the code is organized​

The SDK is one node, MaestroPanelLib:MaestroPanel. Your channel keeps its player, layout and focus, and talks to the SDK only through that node's fields and functions.

  • The Scene loads the library, once per channel run (step 1).
  • The component that owns your player creates the panel for each playback and removes it after (steps 2 to 7). Keep every Maestro call in one script that this component includes, for example Maestro.brs. Your player then calls only startMaestro(), setMaestroTimecode(), openMaestro() and stopMaestro().
  • Observe with observeFieldScoped, so stopMaestro() leaves nothing behind.

1. Load the library​

The SDK is a remote ComponentLibrary; nothing goes in your manifest. Load it from your Scene: Roku doesn't free a ComponentLibrary whose creating component is destroyed, so a library loaded from your player would stay in memory after every video.

<!-- MainScene.xml -->
<interface>
<field id="maestroLibraryStatus" type="string" />
</interface>
' MainScene.brs
sub init()
loadMaestroLibrary()
end sub

sub loadMaestroLibrary()
m.maestroLibrary = createObject("roSGNode", "ComponentLibrary")
m.maestroLibrary.observeFieldScoped("loadStatus", "onMaestroLibraryLoadStatus")
m.maestroLibrary.uri = "https://roku-sdk.us-central1-master.gcp.maestro.io/<version>/maestrokit.pkg"
end sub

sub onMaestroLibraryLoadStatus(event as object)
m.top.maestroLibraryStatus = event.getData() ' "loading", "ready" or "failed"
end sub

A "failed" load means the channel plays without Maestro. Every build shares one version number and the component namespace MaestroPanelLib.

2. Create the panel and observe it​

When playback starts, create MaestroPanelLib:MaestroPanel and append it as the last child of the component that owns your player, so it draws over the video. Observe its outputs before you set anything.

' Maestro.brs: call when playback starts
sub startMaestro()
status = m.top.getScene().maestroLibraryStatus
if status = "ready"
createMaestroPanel()
else if status <> "failed"
m.top.getScene().observeFieldScoped("maestroLibraryStatus", "onMaestroLibraryStatus")
end if
end sub

sub onMaestroLibraryStatus(event as object)
if event.getData() <> "ready" then return
m.top.getScene().unobserveFieldScoped("maestroLibraryStatus")
createMaestroPanel()
end sub

sub createMaestroPanel()
m.maestro = createObject("roSGNode", "MaestroPanelLib:MaestroPanel")
if m.maestro = invalid then return ' not a Maestro package
m.top.appendChild(m.maestro)

m.maestro.observeFieldScoped("showPanel", "onMaestroShowPanel") ' step 5
m.maestro.observeFieldScoped("onOverlayEvent", "onMaestroOverlayEvent") ' step 6
m.maestro.observeFieldScoped("panelsBuilt", "onMaestroPanelsBuilt") ' Panel Integration: modules
m.maestro.observeFieldScoped("errorInformation", "onMaestroError")
m.maestro.observeFieldScoped("trackAction", "onMaestroAnalytics")
m.maestro.observeFieldScoped("trackImpression", "onMaestroAnalytics")

' The latest timecode first (step 3), then the session (step 4)
if m.maestroTimecodeMs <> invalid then m.maestro.callFunc("onPlayerTimeCodeUpdated", m.maestroTimecodeMs)
startMaestroSession()
end sub

sub onMaestroError(event as object)
print "Maestro error: "; formatJson(event.getData())
end sub

sub onMaestroAnalytics(event as object)
' Forward to your analytics platform: see Analytics
sendAnalytics(event.getField(), event.getData())
end sub
OutputWhat your channel does
showPanelThe panel opened or closed, whoever changed it: resize your video, move focus
onOverlayEventAnswer will-appear; place focus after did-dismiss
onPanelEventOnly if your panels send events: their pages say which
panelsBuiltMount the SDK's modules: see Panel Integration
errorInformationLog it
trackAction, trackImpressionForward to your analytics: see Analytics
onSDKEventOptional. rendered:channels lists the panel types on screen

3. Send the timecode​

Call onPlayerTimeCodeUpdated on every position tick with the wall-clock time of the frame on screen, in epoch milliseconds, as a LongInteger. Start with playback, before the panel exists: createMaestroPanel() sends the latest value first, so the first panels build at the viewer's position.

' Your player: the Video node's position observer
sub onVideoPosition(event as object)
' m.streamStartMs: the stream's start as epoch ms (a LongInteger)
setMaestroTimecode(m.streamStartMs + Int(event.getData() * 1000))
end sub

' Maestro.brs
sub setMaestroTimecode(timecodeMs as longinteger)
m.maestroTimecodeMs = timecodeMs
if m.maestro <> invalid then m.maestro.callFunc("onPlayerTimeCodeUpdated", timecodeMs)
end sub

Overlays and the What Just Happened pill don't start without a timecode.

4. Start the session​

Set config first: it starts the panel config request. Then send each panel its data with setDataToPanel, one panel per write: the SDK reads only the first panel key of each write. Then any other field (userSettings, displayQRCodes, ...).

sub startMaestroSession()
m.maestro.config = {
siteID: "YOUR_SITE_ID"
pageId: "YOUR_PAGE_ID" ' or eventId
useProdEnv: true
}

' Each panel's data, one panel per write: { <panel type>: { <property>: value } }
' m.maestro.setDataToPanel = { PANEL_TYPE: { PROPERTY: value } }
end sub

The panels build once the config response arrives: then the SDK sets panelsBuilt and sends rendered:channels on onSDKEvent. Data sent before a panel is built is kept and applied when it builds.

  • A config without siteID, or without a page or event ID, is rejected and reported on errorInformation.
  • A page or event with no panels, or one Maestro doesn't find, sends rendered:channels with no panels.
  • Every build also reports a missing authToken or swId on errorInformation and loads the session anyway: ignore it unless your panels need them.

5. Show the panel and handle focus​

The panel starts hidden. Open it from your key handler, and restore your layout and focus in the showPanel observer: it runs for every close, including those the SDK makes itself.

' Call from your onKeyEvent, for example on Up
sub openMaestro()
if m.maestro = invalid then return
m.maestro.showPanel = true
m.maestro.callFunc("setPanelFocus")
end sub

sub onMaestroShowPanel(event as object)
if event.getData() = false then focusPlayer() ' your player's layout and focus
end sub

Back, Left and resizing your video are in Panel Integration.

6. Answer overlays​

The SDK asks before it shows an overlay. Answer will-appear at once, inside the observer: the SDK waits only briefly, then uses its defaults. After did-dismiss, move focus only if the SDK didn't.

sub onMaestroOverlayEvent(event as object)
overlayEvent = event.getData()
if overlayEvent = invalid then return

if overlayEvent.type = "will-appear"
m.maestro.setDataToOverlay = {
overlayId: overlayEvent.payload.overlayId
canAppear: true ' false while your own UI covers the video
canFocus: false ' true to let the viewer act on it
}
else if overlayEvent.type = "did-dismiss" and overlayEvent.payload.focusRestoredBySDK <> true
focusPlayer()
end if
end sub

See Overlay Integration for every event and when to say no.

7. Clean up​

When playback ends, end the SDK session, then remove the panel and any modules you mounted. The library stays loaded for the next video.

' Call when playback ends
sub stopMaestro()
m.top.getScene().unobserveFieldScoped("maestroLibraryStatus")
if m.maestro = invalid then return

m.maestro.callFunc("destroySDK") ' ends the session and sends its analytics
removeMaestroModules() ' see Panel Integration
m.top.removeChild(m.maestro)
m.maestro = invalid
end sub

Switch content​

  • Other content: set config again with the new IDs. The panel stays, and keeps its setDataToPanel data.
  • Another event only: set userDidStartWatchingEvent to its ID.
  • Keep sending the timecode: the SDK drops the previous playback's timecode on a switch.
note

The SDK keeps its config in m.global.maestroSDKConfig and m.global.maestroRemoteConfig, set once per channel run. To load a different library version in the same run, set both to invalid before you set the new uri.

Try the demo panels​

To see the SDK with several tabs and cards before you have a Maestro site, load the demo package and set showDemoPanel: true in place of the IDs:

' MainScene.brs, step 1
m.maestroLibrary.uri = "https://roku-sdk.us-central1-master.gcp.maestro.io/4.5.28-demo/maestrokit.pkg"

' Maestro.brs, step 4
m.maestro.config = {
showDemoPanel: true
useProdEnv: false
}

The SDK skips the Maestro config request and shows three tabs, Stats, Key Plays and Shop, from data bundled in the package. Up and down move between cards, OK expands or collapses a card, and Back collapses it. All teams, players and products in the demo are fictional.

note

showDemoPanel is only in the 4.5.28-demo package. Other packages ignore it and reject a config without siteID and a page or event ID.

Next steps​