Roku SDK API Reference
Complete reference for the public methods and observable fields exposed by the StreamLayer Roku SDK node.
This page documents the public API of the StreamLayer Roku SDK. The SDK is delivered as a SceneGraph node (StreamLayer) that you add to your scene. All methods are invoked with callFunc on that node, and state is read back through observable fields.
For setup instructions, see the Integration Guide. For version history, see the Changelog.
' The SDK node, created from the SceneGraph component
m.streamLayer = m.top.createChild("StreamLayer")Invocation pattern
Every method below is called through the node, for example:
m.streamLayer.callFunc("setEvent", "nba-lakers-2026-05-28"). Calling a method
that is not available in the current SDK mode is a safe no-op — it is logged,
not thrown.
Table of Contents
Initialization & Lifecycle
initSdk
function initSdk(params as object) as booleanInitializes the SDK: configures logging, analytics, and ad modes, validates the optional player reference, loads configuration, and starts the SceneGraph runtime. Call this once before any other method.
| Field | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Your SDK API Key from StreamLayer Studio. |
apiUrl | string | No | API base URL. Defaults to the configured environment URL when empty. |
playerRef | roSGNode | No | The host Video node. Must expose control and state fields. |
isLoggingEnabled | boolean | No | Enables SDK logging. Default false. |
isAnalyticsEnabled | boolean | No | Enables analytics reporting. Default false. |
isPauseAdsEnabled | boolean | No | Enables pause ad units. Default true. |
isVastModeEnabled | boolean | No | Runs the SDK in VAST mode (host-supplied pause ads). Default false. |
isPrefetchEnabled | boolean | No | Prefetches VAST pause ad creatives. Default false. |
Returns: boolean — true when parameters are accepted and initialization starts; false when params is missing.
Example:
success = m.streamLayer.callFunc("initSdk", {
apiKey: "your-sdk-api-key"
apiUrl: "https://api.streamlayer.io"
playerRef: m.videoPlayer
isLoggingEnabled: true
isAnalyticsEnabled: true
isVastModeEnabled: false
})
' success = true → the StreamLayer Element runtime is initializingattachPlayer
sub attachPlayer(ref as object)Attaches (or replaces) the host video player after initialization. The reference must be an roSGNode that exposes control and state fields; otherwise it is rejected with a warning and ignored.
| Parameter | Type | Description |
|---|---|---|
ref | roSGNode | The host Video node to attach. |
Example:
m.streamLayer.callFunc("attachPlayer", m.videoPlayer)setEvent
sub setEvent(hostEventId as string)Binds the SDK to a host event so the StreamLayer Element starts receiving interactive content for it. The player must be attached first.
| Parameter | Type | Description |
|---|---|---|
hostEventId | string | The host's event identifier for the current stream. |
Example:
m.streamLayer.callFunc("setEvent", "nba-lakers-2026-05-28")getVersion
function getVersion() as objectReturns the running SDK version and product name.
Returns: object with:
| Field | Type | Description |
|---|---|---|
version | string | Semantic version string, for example 2.8.0-001. |
name | string | Always "StreamLayer Roku SDK". |
Example:
info = m.streamLayer.callFunc("getVersion")
print info.name + " v" + info.version
' StreamLayer Roku SDK v2.8.0-001Playback & Pause Ads
setPauseState
sub setPauseState(pauseState as boolean)Notifies the SDK that the host player's pause state changed. While a promo or notification is visible, the call is ignored. Pausing also cancels any scheduled overlay.
| Parameter | Type | Description |
|---|---|---|
pauseState | boolean | true when the player is paused, false when playing. |
Example:
m.streamLayer.callFunc("setPauseState", true)showPauseAd
sub showPauseAd(params = invalid)Requests a pause ad unit for the current event. In VAST mode you must pass a params object containing the creative URL; in full mode the SDK loads its own pause ad units and the argument is optional. The call is ignored if no event is set.
| Field | Type | Required | Description |
|---|---|---|---|
params | object | VAST mode only | Object with the VAST creative, for example { vastUrl: "..." }. |
Example:
' VAST mode
m.streamLayer.callFunc("showPauseAd", { vastUrl: "https://ads.example.com/vast.xml" })
' Full mode
m.streamLayer.callFunc("showPauseAd")closePauseAd
sub closePauseAd()Closes the active pause ad unit. Routes to the external (VAST) or internal close path depending on the current mode.
Example:
m.streamLayer.callFunc("closePauseAd")setVastModeEnabled
sub setVastModeEnabled(enabled as boolean)Switches the SDK between full mode and VAST mode at runtime. No-ops if the mode is already set.
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | true for VAST mode, false for full mode. |
Example:
m.streamLayer.callFunc("setVastModeEnabled", true)resumeRequested
sub resumeRequested()Signals that playback should resume — typically from the pause ad unit's Play button. Sets the observable isResumeRequested field to true so the host can resume its player.
Example:
m.streamLayer.callFunc("resumeRequested")Overlay & Focus
closeOverlay
sub closeOverlay()Closes all active StreamLayer Element overlays and any open pause ad unit, cancels any scheduled overlay, and resets the promo and notification visibility flags.
Example:
m.streamLayer.callFunc("closeOverlay")setFocus
sub setFocus(value)Forwards focus to whichever surface is currently visible — the promo, notification, or pause ad presenter.
| Parameter | Type | Description |
|---|---|---|
value | boolean | true to give the visible surface focus, false to remove it. |
Example:
m.streamLayer.callFunc("setFocus", true)Observable Fields
Read these fields, or observe them with observeField, to react to SDK state. All are set by the SDK; the host observes them.
| Field | Type | Description |
|---|---|---|
log | string | Latest log line emitted by the SDK (when logging is enabled). |
disableFocus | boolean | When true, the host should not hand focus to the SDK. |
isPromoVisible | boolean | true while a promo (interactive ad unit) overlay is on screen. |
isNotificationVisible | boolean | true while a Live Moment Notification is on screen. |
isPauseAdVisible | boolean | true while a pause ad unit is on screen. |
isResumeRequested | boolean | Set to true when the SDK requests stream resume. The host resumes playback and may reset it. |
Example:
m.streamLayer.observeField("isResumeRequested", "onResumeRequested")
sub onResumeRequested(event as object)
if event.getData() = true then m.videoPlayer.control = "resume"
end subUpdated about 2 months ago
