├── test ├── .gitignore ├── find.js ├── info.js ├── launch.js ├── query.js ├── input.js ├── icon.js ├── type.js └── dev-video.js ├── .gitignore ├── package.json ├── LICENSE ├── README.md └── roku.js /test/.gitignore: -------------------------------------------------------------------------------- 1 | *.png 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | .DS_Store 17 | -------------------------------------------------------------------------------- /test/find.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | 4 | ssdp.once('response', function inResponse(msg, rinfo) { 5 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 6 | console.log('roku found at', location); 7 | process.exit(0); 8 | }); 9 | 10 | ssdp.search('roku:ecp'); 11 | -------------------------------------------------------------------------------- /test/info.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | 4 | ssdp.once('response', function inResponse(msg, rinfo) { 5 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 6 | 7 | var device = new Roku(location); 8 | 9 | device.info(function(e, obj) { 10 | console.log(obj); 11 | }); 12 | }); 13 | 14 | ssdp.search('roku:ecp'); -------------------------------------------------------------------------------- /test/launch.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | 4 | ssdp.once('response', function inResponse(msg, rinfo) { 5 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 6 | 7 | var device = new Roku(location); 8 | 9 | device.press(Roku.HOME); 10 | device.delay(1000); 11 | 12 | device.launch('pandora', function() { 13 | process.exit(0); 14 | }); 15 | }); 16 | 17 | ssdp.search('roku:ecp'); 18 | -------------------------------------------------------------------------------- /test/query.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | 4 | ssdp.once('response', function inResponse(msg, rinfo) { 5 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 6 | 7 | var device = new Roku(location); 8 | 9 | device.apps(function(e, apps) { 10 | if (e) throw e; 11 | 12 | console.log('installed apps:') 13 | apps.forEach(function(app) { 14 | console.log(app.id + ':\t', app.name, '(v' + app.version + ')'); 15 | }); 16 | 17 | process.exit(0); 18 | }); 19 | }); 20 | 21 | ssdp.search('roku:ecp'); 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "roku", 3 | "version": "0.2.0", 4 | "description": "control your roku from node", 5 | "main": "roku.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/TheThingSystem/roku" 12 | }, 13 | "keywords": [ 14 | "roku", 15 | "remote", 16 | "control" 17 | ], 18 | "author": "Elijah Insua ", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/TheThingSystem/roku/issues" 22 | }, 23 | "dependencies": { 24 | "sax": "~0.5.4", 25 | "request": "~2.22.0", 26 | "async": "~0.2.9" 27 | }, 28 | "devDependencies": { 29 | "node-ssdp": "0.0.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/input.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | 4 | ssdp.once('response', function inResponse(msg, rinfo) { 5 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 6 | 7 | var device = new Roku(location); 8 | 9 | device.input({ 10 | 'touch.0.x' : 200.0, 11 | 'touch.0.y' : 135.0, 12 | 'touch.0.op' : 'down' 13 | }); 14 | 15 | device.input({ 16 | 'orientation.x' : .5, 17 | 'orientation.y' : .5, 18 | 'orientation.z' : .5 19 | }); 20 | 21 | device.input({ 22 | 'magnetic.x' : 100, 23 | 'magnetic.y' : 0, 24 | 'magnetic.z' : 0 25 | }); 26 | 27 | 28 | device.input({ 29 | 'rotation.x' : .5, 30 | 'rotation.y' : .5, 31 | 'rotation.z' : .5 32 | }); 33 | }); 34 | 35 | ssdp.search('roku:ecp'); -------------------------------------------------------------------------------- /test/icon.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | var fs = require('fs'); 4 | var async = require('async') 5 | 6 | ssdp.once('response', function inResponse(msg, rinfo) { 7 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 8 | 9 | var device = new Roku(location); 10 | 11 | device.apps(function(e, apps) { 12 | if (e) throw e; 13 | 14 | async.each(apps, function(app, fn) { 15 | console.log('fetching', app.name + "'s", 'icon'); 16 | var ws = fs.createWriteStream(__dirname + '/' + app.id + '.png'); 17 | var rs = device.createIconStream(app.id) 18 | 19 | rs.pipe(ws) 20 | rs.on('end', fn); 21 | }, function() { 22 | console.log('done'); 23 | process.exit(0); 24 | }); 25 | }); 26 | }); 27 | 28 | ssdp.search('roku:ecp'); -------------------------------------------------------------------------------- /test/type.js: -------------------------------------------------------------------------------- 1 | var ssdp = new (require('node-ssdp'))() 2 | var Roku = require('../roku.js'); 3 | 4 | ssdp.once('response', function inResponse(msg, rinfo) { 5 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 6 | 7 | var device = new Roku(location); 8 | device.press(Roku.HOME); 9 | device.delay(2000); 10 | device.press(Roku.DOWN); 11 | device.press(Roku.DOWN); 12 | device.press(Roku.SELECT); 13 | 14 | device.type("pandora"); 15 | 16 | device.delay(1500); 17 | 18 | device.press(Roku.RIGHT); 19 | device.press(Roku.RIGHT); 20 | device.press(Roku.RIGHT); 21 | device.press(Roku.RIGHT); 22 | device.press(Roku.RIGHT); 23 | device.press(Roku.RIGHT); 24 | device.press(Roku.UP); 25 | device.press(Roku.SELECT); 26 | 27 | device.delay(1000); 28 | device.press(Roku.SELECT); 29 | device.delay(5000); 30 | device.press(Roku.SELECT); 31 | device.delay(10, process.exit); 32 | }); 33 | 34 | ssdp.search('roku:ecp'); 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Elijah Insua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /test/dev-video.js: -------------------------------------------------------------------------------- 1 | /* 2 | In order to use this you'll want to grab the roku development sdk: 3 | http://wwwimg.roku.com/static/sdk/RokuSDK.zip 4 | 5 | After extracting, you'll want to enable developer mode: 6 | http://sdkdocs.roku.com/display/sdkdoc/Developer+Guide#DeveloperGuide-52ApplicationSecurity 7 | 8 | Now you can install the `samplevideoplayer` found in the extracted RokuSdk.zip folder 9 | 10 | 1. find your roku 11 | node node-roku/test/find.js 12 | 13 | 2. install the sample app 14 | in a browser go to the ip found in step #1 on port 80 (e.g http://192.168.0.8:80/) 15 | 16 | 3. upload samplevideoplayer.zip 17 | 18 | 4. run this script 19 | 20 | by default when running this code it will launch a ted talk, but you can provide it with any sort of mp4 hosted online. 21 | 22 | node node-roku/test/dev-video.js 23 | 24 | or 25 | 26 | node node-roku/test/dev-video.js http://video2.research.att.com/pub/United_Way_2011_1000kbps_640x380.mp4 27 | 28 | */ 29 | 30 | 31 | 32 | var ssdp = new (require('node-ssdp'))() 33 | var Roku = require('../roku.js'); 34 | 35 | ssdp.once('response', function inResponse(msg, rinfo) { 36 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 37 | 38 | var device = new Roku(location); 39 | 40 | device.press(Roku.HOME); 41 | device.delay(1000); 42 | 43 | device.launch(process.argv[2] || 'http://video.ted.com/talks/podcast/VilayanurRamachandran_2007_480.mp4', function() { 44 | }); 45 | }); 46 | 47 | ssdp.search('roku:ecp'); 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | roku 2 | ==== 3 | 4 | wrapper around the roku "external control" api 5 | 6 | ## install 7 | 8 | `npm install roku` 9 | 10 | ## use 11 | 12 | ```javascript 13 | 14 | var ssdp = new (require('node-ssdp'))() 15 | var Roku = require('../roku.js'); 16 | 17 | ssdp.once('response', function inResponse(msg, rinfo) { 18 | var location = msg.toString().match(/Location: (.*)/i)[1].trim(); 19 | 20 | var device = new Roku(location); 21 | 22 | device.press(Roku.HOME); 23 | device.delay(1000); 24 | 25 | device.launch('pandora', function() { 26 | process.exit(0); 27 | }); 28 | }); 29 | 30 | ssdp.search('roku:ecp'); 31 | 32 | ``` 33 | 34 | [more examples](https://github.com/tmpvar/node-roku/tree/master/test) 35 | 36 | ## api 37 | 38 | ### type(string [, fn]) 39 | 40 | Types the provided string into a field 41 | 42 | ### press(button) 43 | 44 | Simulates a button press on the remote control 45 | 46 | ### delay(ms) 47 | 48 | Add a delay into the command queue to allow the roku to keep up with what you want to do. 49 | 50 | ### input(obj) 51 | 52 | Pass arguments into the currently running app. see [test/input.js](https://github.com/tmpvar/node-roku/blob/master/test/input.js) 53 | 54 | ### apps(function(err, array) {}); 55 | 56 | list the installed apps on the roku 57 | 58 | ### createIconStream(appId) 59 | 60 | create a PNG stream 61 | 62 | ### launch(string) 63 | 64 | Using the `launch` command you can open application or allow a development application handle the protocol. 65 | 66 | see the example code in [test/launch.js](https://github.com/tmpvar/node-roku/blob/master/test/launch.js) and [test/dev-video.js](https://github.com/tmpvar/node-roku/blob/master/test/dev-video.js) 67 | 68 | ### info(function(err, obj) {}); 69 | 70 | returns an object of information about the roku 71 | 72 | example object: 73 | 74 | ``` 75 | 76 | { major: '1', 77 | minor: '0', 78 | deviceType: 'urn:roku-com:device:player:1-0', 79 | friendlyName: 'Roku Streaming Player', 80 | manufacturer: 'Roku', 81 | manufacturerURL: 'http://www.roku.com/', 82 | modelDescription: 'Roku Streaming Player Network Media', 83 | modelName: 'Roku Streaming Player 4200X', 84 | modelNumber: '4200X', 85 | modelURL: 'http://www.roku.com/', 86 | serialNumber: '1GH35D054697', 87 | UDN: 'uuid:31474833-3544-a9d5-0000-05006d1f0000', 88 | serviceType: 'urn:roku-com:service:ecp:1', 89 | serviceId: 'urn:roku-com:serviceId:ecp1-0', 90 | SCPDURL: 'ecp_SCPD.xml' } 91 | 92 | ``` 93 | 94 | 95 | ## license 96 | 97 | [MIT](http://tmpvar.mit-license.org) 98 | -------------------------------------------------------------------------------- /roku.js: -------------------------------------------------------------------------------- 1 | var sax = require('sax'), 2 | request = require('request'), 3 | async = require('async'), 4 | qs = require('querystring'); 5 | 6 | 7 | function Roku(url) { 8 | this.baseUrl = url; 9 | this.commandQueue = []; 10 | this.queued = false; 11 | } 12 | 13 | // Define key constants 14 | [ 15 | 'Home', 16 | 'Rev', 17 | 'Fwd', 18 | 'Play', 19 | 'Select', 20 | 'Left', 21 | 'Right', 22 | 'Down', 23 | 'Up', 24 | 'Back', 25 | 'InstantReplay', 26 | 'Info', 27 | 'Backspace', 28 | 'Search', 29 | 'Enter', 30 | ].forEach(function(name) { 31 | Object.defineProperty(Roku, name.toUpperCase(), { 32 | enumerable: true, 33 | value: name 34 | }); 35 | }); 36 | 37 | Roku.prototype.type = function(string, fn) { 38 | var press = this.press.bind(this); 39 | 40 | string.split('').forEach(function(key) { 41 | press('Lit_' + escape(key), fn); 42 | }, fn); 43 | }; 44 | 45 | Roku.prototype.press = function(string, fn) { 46 | this.commandQueue.push(function(callback) { 47 | request.post(this.baseUrl + 'keypress/' + string, callback); 48 | }.bind(this)); 49 | 50 | this.processQueue(); 51 | }; 52 | 53 | Roku.prototype.delay = function(ms, fn) { 54 | this.commandQueue.push(function(callback) { 55 | setTimeout(function() { 56 | fn && fn(); 57 | callback(); 58 | }, ms); 59 | }); 60 | 61 | this.processQueue(); 62 | }; 63 | 64 | 65 | // TODO: need better tests for this, not sure if it's actually working 66 | Roku.prototype.input = function(obj, fn) { 67 | var url = this.baseUrl + 'input?' + qs.stringify(obj); 68 | request.post(url, function(e, r, b) { 69 | fn && fn(e); 70 | }); 71 | }; 72 | 73 | Roku.prototype.apps = function(fn) { 74 | var parser = sax.createStream(); 75 | request.get(this.baseUrl + 'query/apps').pipe(parser).on('error', fn); 76 | 77 | var result = [], pending = null; 78 | parser.on('opentag', function(node) { 79 | if (node.name === 'APP') { 80 | pending = { 81 | id: parseInt(node.attributes.ID, 10), 82 | version: node.attributes.VERSION 83 | }; 84 | } 85 | }); 86 | 87 | parser.on('text', function(name) { 88 | name = name.trim(); 89 | if (pending && name) { 90 | pending.name = name; 91 | result.push(pending); 92 | pending = null; 93 | } 94 | }); 95 | 96 | parser.on('end', function() { 97 | fn(null, result); 98 | }); 99 | }; 100 | 101 | Roku.prototype.createIconStream = function(appId) { 102 | return request.get(this.baseUrl + 'query/icon/' + appId); 103 | }; 104 | 105 | Roku.prototype.launch = function(name, fn) { 106 | var baseUrl = this.baseUrl; 107 | if (name.indexOf('://') > -1) { 108 | 109 | this.commandQueue.push(function(callback) { 110 | request({ 111 | url: name, 112 | method: 'HEAD' 113 | }, function(e, res, body) { 114 | 115 | var url = baseUrl + 'launch/dev?' + qs.stringify({ 116 | url: name, 117 | streamformat : res.headers['content-type'].split('/').pop(), 118 | }); 119 | 120 | request.post(url, function(e, r, b) { 121 | callback(e) 122 | fn && fn(e) 123 | }); 124 | }); 125 | }.bind(this)); 126 | } else { 127 | this.commandQueue.push(function(callback) { 128 | 129 | name = name.toLowerCase(); 130 | this.apps(function(e, results) { 131 | if (e) return fn(e); 132 | 133 | for (var i=0; i