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

EDIT ON GITHUB

Roku SDK reference

Read time: 1 minute
Last edited: Oct 26, 2021

Overview

This reference guide documents basic usage of our Roku SDK, and explains in detail how features work. LaunchDarkly's SDKs are open source. To learn more, read Roku Client GitHub repository. You can also try this SDK out by cloning and running a sample application.

The Roku SDK is written in BrightScript.

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, available in the Projects tab of your account settings page. Be sure to use a mobile key. Never embed a server-side SDK key into a mobile application.

Here's how:

1REM get a reference to to task
2launchDarklyNode = m.top.findNode("my-node-name")
3
4REM create configuration
5config = LaunchDarklyConfig("MY_MOBILE_KEY", launchDarklyNode)
6
7REM create a user
8user = LaunchDarklyUser("user-key")
9
10REM initialize the client
11LaunchDarklySGInit(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:

1REM create the scenegraph communication wrapper
2launchDarkly = LaunchDarklySG(launchDarklyNode)
3
4REM use the client
5value = launchDarkly.boolVariation("MY_FLAG_KEY", false)
Making feature flags available to this SDK

You must make feature flags available to client-side SDKs before the flags can be evaluated. If you evaluate a feature flag that is not available, you receive the default value for that flag. If you want a project's flags to be made 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:

1REM get a reference to the task
2launchDarklyNode = m.top.findNode("MY_NODE_NAME")
3
4REM create configuration
5config = LaunchDarklyConfig("MY_MOBILE_KEY", launchDarklyNode)
6
7REM create a user
8user = LaunchDarklyUser("user-key")
9
10
11REM create message port
12messagePort = createObject("roMessagePort")
13
14REM initialize the client
15launchDarkly = LaunchDarkly(config, user, messagePort)
16
17
18REM use the client
19value = 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:

1while (true)
2
3 REM do not wait forever or timers will break
4 msg = wait(3000, messagePort)
5
6
7 if launchDarkly.handleMessage(msg) then
8 REM this message was for the client
9 else
10 REM handle non client messages
11 end if
12end while

Supported features

This SDK supports the following features: