Skip to content

Instantly share code, notes, and snippets.

@gmisail
Created January 23, 2021 18:04
Show Gist options
  • Save gmisail/2115d4a14761058d128f04438294be88 to your computer and use it in GitHub Desktop.
Save gmisail/2115d4a14761058d128f04438294be88 to your computer and use it in GitHub Desktop.
const Roku = require('rokujs');
const roku = new Roku('roku-address');
Roku.discover(function (devices) {
console.log(devices);
/* example response
[ { server: 'Roku UPnP/1.0 MiniUPnPd/1.4',
address: '192.168.2.45',
location: 'http://192.168.2.45:8060/',
usn: 'uuid:roku:ecp:2N005M893730' } ]
*/
});
const readline = require('readline');
readline.emitKeypressEvents(process.stdin);
var Controller = {};
Controller.onUp = () => {
console.log("Button: Up");
roku.press('up');
}
Controller.onDown = () => {
console.log("Button: Down");
roku.press('down');
}
Controller.onLeft = () => {
console.log("Button: Left");
roku.press('left');
}
Controller.onRight = () => {
console.log("Button: Right");
roku.press('right');
}
Controller.onSelect = () => {
console.log("Button: Select");
roku.press('enter');
}
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
if (key.ctrl && key.name === 'c') {
process.exit();
} else {
console.log(`You pressed the "${str}" key`);
switch (key.name) {
case 'up': {
Controller.onUp();
break;
}
case 'down': {
Controller.onDown();
break;
}
case 'left': {
Controller.onLeft();
break;
}
case 'right': {
Controller.onRight();
break;
}
case 'return': {
Controller.onSelect();
break;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment