roku-ecp
Version:
A Node package designed to control Roku devices using TypeScript
43 lines (42 loc) • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.App = void 0;
const util_1 = require("./util");
class App {
/**
* Initializes a new App given its id and parent device
* @param {{}} appInfo App details (id required)
* @param {Roku} parent Parent device
*/
constructor(appInfo, parent) {
this.toString = () => `[${this.appInfo.id}]${this.appInfo.name ? ` ${this.appInfo.name}` : ""}${this.appInfo.version ? ` (v${this.appInfo.version})` : ""}`;
/**
* Returns an icon corresponding to the application
*/
this.icon = () => this.get(`query/icon/${this.appInfo.id}`);
/**
* Launches the app. Can accept launch parameters for deep linking.
* @param {{}} options Launch parameters (for deep linking)
*/
this.launch = (options) => this.post(`launch/${this.appInfo.id}`, options);
/**
* Exits the current channel, and launches the Channel Store details screen of the app.
*/
this.store = () => this.post("launch/11", { contentId: this.appInfo.id });
/**
* Exits the current channel, and launches the Channel Store details screen of the app (provided the app is not installed).
*/
this.install = () => this.post(`install/${this.appInfo.id}`);
/**
* Sends custom events to the current application
* @param {{}} options Input parameters
*/
this.input = (options) => this.post("input", options);
this.appInfo = appInfo;
this.get = (path, params) => fetch(`${parent.location}${path}${util_1.queryString(params)}`);
this.post = (path, params) => fetch(`${parent.location}${path}${util_1.queryString(params)}`, {
method: "post"
});
}
}
exports.App = App;