react-native-roku-client
This is a fork of https://github.com/bschlenk/node-roku-client modified to work in a JS only react-native environment. The main difference is that this library doesn't support discovery of roku devices on the network. Yes, this makes it essentially useless. This requires knowing the ip of the roku.
If you are looking for a react-native version that does support discovery, you should look for another library.
Discover Roku devices via ssdp
and control the device with methods that perform http
requests to the device.
requirements:
- node
6.0.0 or higher
- connected to the same network as the Roku device.
- a router/network that supports UPnP (for ssdp)
Installation
$ npm install roku-client
Usage
// es2015; // commonjsconst Client keys = ; Client ; // Or, if the roku address is already knownconst client = 'http://192.168.1.17:8060';client;
Client.discover()
Invoking Client.discover()
will return a promise which resolves to a Client object on success. The Client will be initialized to the address of the first device to respond. This client object will contain the methods needed to control a roku device. Commands are sent to the Roku device via HTTP
protocol as found on the docs.
If there are mutiple Roku devices on the network, call discover
with the wait parameter set to true. It will return a promise that resolves to a list of all addresses found.
; ;
API Methods
Method Name | Return Type | Details |
---|---|---|
ip |
string |
network ip and port http://xxx.xxx.xxx.xxx:8060 |
.apps() |
Promise<{id: string, name: string, type: string, version: string}[]> |
List of all apps installed on this device. |
.active() |
Promise<{id: string, name: string, type: string, version: string}\|null>} |
A single object representing the active app, or null if the home screen is active. |
.info() |
Promise<Object> |
A map of this Roku device's properties. Varies from device to device. |
.keypress(key: string) |
Promise<void> |
Send a keypress from keys.js or a single character to send that letter (e.g. to an input box). |
.keydown(key: string) |
Promise<void> |
The same as keypress but tells the Roku to hold the key down. |
.keyup(key: string) |
Promise<void> |
The same as keyup but tells the Roku to release a key held with keyup ( a no-op if the key was not held). |
.icon(appId: number) |
Promise<string> |
Saves the image to a temp file and returns the filename. |
.launch(appId: number) |
Promise<void> |
Launch the given app by its id. |
.text(text: string) |
Promise<void> |
Send the text string as a series of keypress actions. |
.command() |
Commander |
Returns a Commander instance, which allows for easily chaining key commands to send to the Roku. |
Keypress Values
keys.js contains a list of keypress values understood by Roku. It can be accessed programmatically:
; keysHOME // 'Home'keysLEFT // 'Left'
Commander
The Client#command()
method provides a simpler interface over the keypress and text methods.
It allows them to be chained and repeated and handles all promise chaining internally.
Each key within the keys.js module is available on the commander
instance in camelcase form. Additionally, a .text()
method is available to send
text strings. Each key command takes an optional number to specify the number
of times to repeat the command, defaulting to 1
.
After chaining the desired methods, call .send()
to send them to the Roku. .send()
returns
a promise that completes when all buttons have been pressed, or when the Roku fails to respond to
any of the commands. A Commander
instance should not be reused after calling .send()
.
Examples
Navigate to a search box and enter text
client left text'Breaking Bad' ;
Turn the volume up by 10
client ;
Conditionally perform a command
let command = client;if goUp command = command; else command = command;command right ;
Konami code
client left right left right text'ba' ;
Testing
$ npm test
This will run the linter, unit tests, and coverage.
References
Roku - External Control Service Commands
Roku - Keypress Key Values
Additional Information
Tested on OSX & raspberry pi w/ raspbian jessie, and with Roku TV.