• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
No results for ""
EXPAND ALL

EDIT ON GITHUB

Roku SDK reference

Read time: 2 minutes
Last edited: May 16, 2022

Overview

This topic documents how to get started with the client-side Roku SDK, and links to reference information on all of the supported features. The Roku SDK is written in BrightScript.

SDK quick links

LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

ResourceLocation
SDK API documentationNone
GitHub repositoryroku-client-sdk
Sample applicationhello-roku
Published moduleavailable through GitHub releases

Getting started

After you complete the Getting Started process, follow these instructions to start using the LaunchDarkly SDK in your Roku Application.

We provide releases on GitHub. Download the latest release and extract the provided files into your source tree. You may need to rename the paths inside LaunchDarklyTask.xml depending on your project structure.

For SceneGraph usage add a LaunchDarklyTask node to your scene.

To create a client instance, you need your environment's mobile key. This authorizes your application to connect to a particular environment within LaunchDarkly. Your mobile key is available in the Projects tab of your Account settings page. Mobile keys are not secret and you can expose them in your client-side code without risk. Never embed a server-side SDK key into a client-side application.

Here's how:

REM get a reference to to task
launchDarklyNode = m.top.findNode("my-node-name")
REM create configuration
config = LaunchDarklyConfig("MY_MOBILE_KEY", launchDarklyNode)
REM create a user
user = LaunchDarklyUser("user-key")
REM initialize the client
LaunchDarklySGInit(config, user)

For each SceneGraph component you want to use the SDK in you need to initialize an interface to talk to the SceneGraph. This interface provides all the expected client functionality, such as evaluation.

Here's how:

REM create the scenegraph communication wrapper
launchDarkly = LaunchDarklySG(launchDarklyNode)
REM use the client
value = launchDarkly.boolVariation("MY_FLAG_KEY", false)
Use a single instance

It's important to create a single client instance. The client instance maintains internal state that allows LaunchDarkly to serve feature flags without making any remote requests. Do not instantiate a new client with every request.

Making feature flags available to this SDK

You must make feature flags available to mobile SDKs before the SDK can evaluate those flags. If an SDK tries to evaluate a feature flag that is not available, the user will receive the default value for that flag.

To make a flag available to this SDK, check the SDKs using Mobile key checkbox during flag creation, or on the flag's Settings tab. To make all of a project's flags available to this SDK by default, check the SDKs using Mobile key checkbox in your project Settings.

Creating a client outside of the SceneGraph API is similar. In the legacy API you do not need LaunchDarklySGInit or the LaunchDarklySG functions.

Here's how:

REM get a reference to the task
launchDarklyNode = m.top.findNode("MY_NODE_NAME")
REM create configuration
config = LaunchDarklyConfig("MY_MOBILE_KEY", launchDarklyNode)
REM create a user
user = LaunchDarklyUser("user-key")
REM create message port
messagePort = createObject("roMessagePort")
REM initialize the client
launchDarkly = LaunchDarkly(config, user, messagePort)
REM use the client
value = launchDarkly.boolVariation("MY_FLAG_KEY", false)

If not using the SceneGraph you need to poll events to drive the client in your standard event loop:

while (true)
REM do not wait forever or timers will break
msg = wait(3000, messagePort)
if launchDarkly.handleMessage(msg) then
REM this message was for the client
else
REM handle non client messages
end if
end while

Supported features

This SDK supports the following features: