> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Roku SDK reference

<View title="Developer" />

<View title="Federal docs">
  <Danger>
    **The Roku SDK is not available in federal environments**

    To learn more, read <a href="/docs/home/infrastructure/federal">LaunchDarkly in federal environments</a>.
  </Danger>
</View>

<View title="EU docs">
  <Danger>
    **The Roku SDK is not available in LaunchDarkly's European Union (EU) instance**

    To learn more, read <a href="/docs/home/infrastructure/eu">LaunchDarkly in the European Union (EU)</a>.
  </Danger>
</View>

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.

<Note>
  **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:

  <table>
    <thead>
      <tr>
        <th>Resource</th>
        <th>Location</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>SDK API documentation</td>
        <td>None</td>
      </tr>

      <tr>
        <td>Supported SDK Versions</td>
        <td>[Roku SDK](/docs/sdk/concepts/supported-versions#roku-sdk)</td>
      </tr>

      <tr>
        <td>GitHub repository</td>

        <td>
          [roku-client-sdk](https://github.com/launchdarkly/roku-client-sdk)
        </td>
      </tr>

      <tr>
        <td>Sample application</td>

        <td>
          [Roku](https://github.com/launchdarkly/hello-roku)
        </td>
      </tr>

      <tr>
        <td>Published module</td>

        <td>
          [available through GitHub releases](https://github.com/launchdarkly/roku-client-sdk/releases)
        </td>
      </tr>
    </tbody>
  </table>
</Note>

## Get started

After you complete the [Get started](/docs/home/getting-started) process, follow these instructions to start using the LaunchDarkly SDK in your Roku Application:

* [Install the SDK](#install-the-sdk)
* [Initialize the client](#initialize-the-client)
* (Optional) [Initialize an interface to SceneGraph](#initialize-an-interface-to-scenegraph)
* [Evaluate a flag](#evaluate-a-flag)

### Install the SDK

We provide releases on [GitHub](https://github.com/launchdarkly/roku-client-sdk/releases). 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.

### Initialize the client

To create a client instance, you need your environment's mobile key and the context for which you want to evaluate flags. This authorizes your application to connect to a particular environment within LaunchDarkly.

<Warning>
  **Roku SDK credentials**

  The Roku SDK uses a mobile key. Keys are specific to each project and environment. They are available on the **SDK keys** page under **Settings**. To learn more about key types, read [Keys](/docs/sdk/concepts/client-side-server-side#keys-and-credentials).

  Mobile keys are not secret and you can expose them in your client-side code without risk. However, never embed a server-side SDK key into a client-side application.
</Warning>

Here's how to create the client:

<CodeGroup>
  ```brightscript title="Roku SDK v2.0 (BrightScript)" lines wrap theme={null}
  ' get a reference to the task
  launchDarklyNode = m.top.findNode("my-node-name")

  ' create configuration
  config = LaunchDarklyConfig("example-mobile-key", launchDarklyNode)

  ' create a context. You'll need this context later, but you can ignore it for now.
  context = LaunchDarklyCreateContext({"key": "example-user-key", "kind": "user"})

  ' create message port
  messagePort = createObject("roMessagePort")

  ' initialize the client
  LaunchDarklySGInit(config, context)

  ```
</CodeGroup>

To learn more about the specific configuration options available in this SDK, read [SDK configuration](/docs/sdk/features/config#roku).

<Warning>
  **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.
</Warning>

### Initialize an interface to SceneGraph

If you are working with SceneGraph, then for each SceneGraph component in which you want to use the Roku SDK, 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:

<CodeGroup>
  ```brightscript title="BrightScript" lines wrap theme={null}
  ' create the scenegraph communication wrapper
  launchDarkly = LaunchDarklySG(launchDarklyNode)

  ```
</CodeGroup>

### Evaluate a flag

After you initialize the client, you can use it to check which variation a particular context will receive for a feature flag.

Here's how:

<CodeGroup>
  ```brightscript title="BrightScript" lines wrap theme={null}
  ' use the client
  value = launchDarkly.boolVariation("example-flag-key", false)
  ```
</CodeGroup>

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

<CodeGroup>
  ```brightscript title="BrightScript" lines wrap theme={null}
  while (true)

      ' do not wait forever or timers will break
      msg = wait(3000, messagePort)


      if launchDarkly.handleMessage(msg) then
          ' this message was for the client
      else
          ' handle non client messages
      end if
  end while
  ```
</CodeGroup>

<Warning>
  **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 context will receive the fallback value for that flag.

  To make a flag available to this SDK, check the **SDKs using Mobile key** checkbox during flag creation, or toggle on the option in the flag's right sidebar. To make all of a project's flags available to this SDK by default, check the **SDKs using Mobile key** checkbox on your project's [Flag settings page](/docs/home/account/edit-project).
</Warning>

## Supported features

This SDK supports the following features:

* [Anonymous contexts and users](/docs/sdk/features/anonymous#roku)
* [SDK configuration](/docs/sdk/features/config#roku), including
  * [Application metadata configuration](/docs/sdk/features/app-config#roku)
  * [Service endpoint configuration](/docs/sdk/features/service-endpoint-configuration#roku)
* [Context configuration](/docs/sdk/features/context-config#roku)
* [Flag variation evaluation](/docs/sdk/features/evaluating#roku)
* [Flag variation evaluation details](/docs/sdk/features/evaluation-reasons#roku)
* [Flushing events](/docs/sdk/features/flush#roku)
* [Getting all flags](/docs/sdk/features/all-flags#roku)
* [Identifying and changing contexts](/docs/sdk/features/identify#roku)
* [Logging configuration](/docs/sdk/features/logging#roku)
* [Monitoring SDK status](/docs/sdk/features/monitoring#roku)
* [Private attributes](/docs/sdk/features/private-attributes#roku)
* [Relay Proxy configuration, using proxy mode](/docs/sdk/features/relay-proxy-configuration/proxy-mode#roku)
* [Tracking custom events](/docs/sdk/features/events#roku)
* [Subscribing to flag changes](/docs/sdk/features/flag-changes#roku)
