Custom BrightScript Commands for Roku Clients

Custom Roku BrightScript commands can be added to the Roku BrightScript client. The application should override the default customCommands.brs file to inject additional client commands that can be invoked using the invokeCommand function.

Do the following steps to add a custom BrightScript command:

  1. Add a copy of the base cloud client’s customCommands.brs that is found in the <Engine Version>/src/cloud/source folder.
  2. Add the BrightScript function to the customCommands.brs (or any other required .brs file in the app’s roku client folder).
  3. Register the new custom function with the initCustomCommands() function with customCommands.brs as shown in the following example:

    sub initCustomCommands()
        ' first parameter of addCustomCommand is the string name of the command to be used by the server app.
        ' The second parameter is the action function or sub that is bound to the command name.
        addCustomCommand("customCommand1", command1Implementation)
        addCustomCommand("getInfoWithResponse", getDeviceInfoCommand)
    end sub
    sub command1Implementation(params as object)
        'Some BrightScript function
    end sub
    sub getDeviceInfoCommand(params as object)
        deviceInfo = CreateObject("roDeviceInfo")
        ' The sequence number of the request must be included if a response is sent back
        response = {event: "response", sequence: m.lastSequence}
        response["version"] = deviceInfo.GetVersion()
        response["externalip"] = deviceInfo.GetExternalIp()
        response["connectiontype"] = deviceInfo.GetConnectionType()
        response["graphics"] = deviceInfo.GetGraphicsPlatform()
    end sub

The Cloud Solution provides the invokeCommand function to invoke the named function.