Skip to content

Commit

Permalink
feat: add input command
Browse files Browse the repository at this point in the history
  • Loading branch information
bchelkowski committed Dec 19, 2023
1 parent 0c10e28 commit 4f2ec40
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 32 deletions.
67 changes: 44 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Environment variables (command argument/option):

### assets

Roku ECP - `query/r2d2-bitmaps`
Roku ECP - GET `query/r2d2-bitmaps`

Returns a list of the assets that have been loaded into texture memory
and the amount of used, available, and maximum memory on your device (in bytes).
Expand All @@ -82,10 +82,10 @@ Environment variables (command argument/option):

Roku ECP:

* `query/fwbeacons`
* `query/fwbeacons/track`
* `query/fwbeacons/track/<channelId>`
* `query/fwbeacons/untrack`
* GET `query/fwbeacons`
* POST `fwbeacons/track`
* POST `fwbeacons/track/<channelId>`
* POST `fwbeacons/untrack`

Tracks channel and media lifecycle events for a specific channel.
To use these commands, the device must have developer mode enabled.
Expand All @@ -104,7 +104,7 @@ Devices that are keyed may monitor channels from the Roku Channel Store that are
* **untrack** - Disables tracking of channel and media lifecycle events (if enabled) and discards all queued events.

```bash
roku beacons [channelId] [command = 'log'] [--ip <Roku device IP>]
roku beacons [command = 'log'] [channelId] [--ip <Roku device IP>]
```

* **channelId** - channel id for a sideloaded channel or production/beta channel linked to the Roku developer's account
Expand All @@ -118,7 +118,7 @@ Environment variables (command argument/option):

### device

Roku ECP - `query/device-info`
Roku ECP - GET `query/device-info`

Retrieves device information similar to that returned by roDeviceInfo.

Expand All @@ -135,7 +135,7 @@ Environment variables (command argument/option):

### fps

Roku ECP - `query/graphics-frame-rate`
Roku ECP - GET `query/graphics-frame-rate`

Returns the recent number of rendered graphics frames per seconds (this value is separate from the video frame rate).
Developer mode must be enabled to use this command.
Expand All @@ -152,7 +152,7 @@ Environment variables (command argument/option):

### icon

Roku ECP - `query/icon/<CHANNEL_ID>`
Roku ECP - GET `query/icon/<CHANNEL_ID>`

Downloads under iconPath an icon file corresponding to the application identified by channelId.
The binary data with an identifying MIME-type header is returned.
Expand All @@ -171,13 +171,34 @@ Environment variables (command argument/option):
* **ICON_PATH** (iconPath)
* **ROKU_IP** (ip)

### input

Roku ECP - POST `input?<query>`

Sends custom events to the current application.
It takes a user-defined list of name-value pairs sent as query string URI parameters.
Eg. `contentId=contentId1234&mediaType=episode`
The external control server places these name-value pairs into an associative array,
and passes them directly through to the currently executing channel script
using a Message Port attached to a created roInput object.

```bash
roku input <query> [--ip <Roku device IP>]
```

* **ip** - IP of the Roku device

Environment variables (command argument/option):

* **ROKU_IP** (ip)

### key

Roku ECP:

* `keydown/<KEY>`
* `keyup/<KEY>`
* `keypress/<KEY>`
* POST `keydown/<KEY>`
* POST `keyup/<KEY>`
* POST `keypress/<KEY>`

Sends key press/down/up

Expand Down Expand Up @@ -225,9 +246,9 @@ Environment variables (command argument/option):

Roku ECP:

* `query/sgnodes/all`
* `query/sgnodes/roots`
* `query/sgnodes/nodes?node-id=nodeId`
* GET `query/sgnodes/all`
* GET `query/sgnodes/roots`
* GET `query/sgnodes/nodes?node-id=nodeId`

Returns all/root or finds some rendered nodes.

Expand Down Expand Up @@ -286,8 +307,8 @@ Environment variables (command argument/option):

Roku ECP:

* `query/chanperf`
* `query/chanperf/<channelld>?duration-seconds=<seconds>`
* GET `query/chanperf`
* GET `query/chanperf/<channelld>?duration-seconds=<seconds>`

Returns the current memory and CPU utilization of the channel running in the foreground (RAM usage is reported bytes).
The foreground channel may either be a sideloaded channel or a channel from the Roku Channel Store.
Expand All @@ -314,7 +335,7 @@ Environment variables (command argument/option):

### player

Roku ECP - `query/media-player`
Roku ECP - GET `query/media-player`

Returns a child element named 'player' that identifies the media player state.
The information returned includes the current stream segment and position of the content being played,
Expand All @@ -333,7 +354,7 @@ Environment variables (command argument/option):

### registry

Roku ECP - `query/registry/<CHANNEL_ID>`
Roku ECP - GET `query/registry/<CHANNEL_ID>`

Lists the entries in the device registry for a sideloaded channel or production/beta channel linked to the Roku developer's account.
The channel ID must be provided; for sideloaded channels, use "dev" as the channelId.
Expand Down Expand Up @@ -384,9 +405,9 @@ Environment variables (command argument/option):

Roku ECP:

* `query/sgrendezvous`
* `query/sgrendezvous/track`
* `query/sgrendezvous/untrack`
* GET `query/sgrendezvous`
* POST `sgrendezvous/track`
* POST `sgrendezvous/untrack`

Lists the node rendezvous events for a sideloaded channel or production/beta channel linked to the Roku developer's account.

Expand All @@ -402,7 +423,7 @@ Tracking a different channel clears any queued rendezvous events.
* **untrack** - Stops the tracking of rendezvous events.

```bash
roku rendezvous [channelId] [command = 'log'] [--ip <Roku device IP>]
roku rendezvous [command = 'log'] [channelId] [--ip <Roku device IP>]
```

* **channelId** - channel id for a sideloaded channel or production/beta channel linked to the Roku developer's account
Expand Down
9 changes: 9 additions & 0 deletions src/cli/arguments/inputQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ParsedArgumentsObject } from '@caporal/core';

export function getInputQueryArgumentDefinition(): [string, string] {
return ['<inputQuery>', 'Input query params eg. contentID=contendId123&mediaType=episode'];
}

export function getInputQuery(args: ParsedArgumentsObject): string {
return args.inputQuery as string;
}
15 changes: 15 additions & 0 deletions src/cli/commands/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { CreateCommandParameters, Command } from '@caporal/core';
import { envVariables } from '../../env/args';
import input from '../../requests/input';
import { getInputQuery, getInputQueryArgumentDefinition } from '../arguments/inputQuery';
import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';

export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Sends custom events to the current application.')
.argument(...getInputQueryArgumentDefinition())
.option(...getRokuIPOptionDefinition())
.action(async ({ args, options }) => input({
query: getInputQuery(args) || '',
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
}));
}
2 changes: 1 addition & 1 deletion src/cli/commands/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
.option(...getRokuIPOptionDefinition())
.action(async ({ args, options }) => {
const _sgNodes = await sgNodes({
nodeId: getNodeId(options),
nodeId: getNodeId(args),
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
type: getType(args),
});
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export {
DownloadScreenshotOptions,
GraphicsFrameRateOptions,
InputOptions,
InputType,
InstalledAppsOptions,
KeyOptions,
LaunchOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { default as downloadIcon, DownloadIconOptions } from './downloadIcon';
export { default as downloadPackage, DownloadPackageOptions } from './downloadPackage';
export { default as downloadScreenshot, DownloadScreenshotOptions } from './downloadScreenshot';
export { default as graphicsFrameRate, GraphicsFrameRateOptions } from './graphicsFrameRate';
export { default as input, InputOptions, InputType } from './input';
export { default as input, InputOptions } from './input';
export { default as installedApps, InstalledAppsOptions } from './installedApps';
export { default as keyDown, KeyOptions } from './keyDown';
export { default as keyPress } from './keyPress';
Expand Down
8 changes: 2 additions & 6 deletions src/requests/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import { RequestMethod } from '../utils/RequestMethod.enum';
import { RokuPort } from '../utils/RokuPort.enum';
import RokuRequest from '../utils/RokuRequest';

export type InputType = { [key: string]: string };

export type InputOptions = {
input: InputType;
query: string;
rokuIP?: string;
};

export default (options: InputOptions) => {
const inputEntries = Object.entries(options.input);
const query = inputEntries.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&');
const path = `/input?${query}`;
const path = `/input?${options.query}`;

return new RokuRequest({
method: RequestMethod.POST,
Expand Down

0 comments on commit 4f2ec40

Please sign in to comment.