Created
January 23, 2021 18:04
-
-
Save gmisail/2115d4a14761058d128f04438294be88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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