Nodeku — control your Roku with Node.js
Just a few hours ago I released an NPM package called Nodeku. It will discover Roku devices on your local network and provide you with a module to interface with that device via HTTP requests. Refer to the documentation for help.
$ npm install nodeku
const Nodeku = require('nodeku')
.then(device => device.launch(12)) // launches netflix app
.catch(error => console.error(error.stack))
Why did I build this?
I was (un)inspired by this package and how little it actually did, how it was more of a SEO boost for someone named “garciacom”, and most importantly — how the source code was no where to be found. Sketch. So I took a peak at the Roku External Control API docs and after some reading I discovered that you can send commands via HTTP requests.
Seemed like a fun side-project, I’m a web dev so this should be a piece of cake, right?
Along the way I learned about SSDP, got some practice with TDD, learned and implemented Continuous Delivery for publishing to NPM, and writing documentation.
This was the first time I got to play with this protocol and I think it’s pretty neat. It’s a part of the Universal Plug and Plug Protocol (UPnP). Basically, devices ping a service, for example IPv4’s service resides at the IP address 188.8.131.52 port 1900, to register themselves as available devices. Once registered you can ping that same service with certain headers to get information about a particular device or about any/all devices available. Here’s an example of headers for a request looking for a Roku device:
M-SEARCH * HTTP/1.1
In the case of my Roku device, it responded with XML data so I had to use the xml2json package because fuck xml amirite?
I’m using a test runner called Ava. It’s nice in that it’s api is inspired by Tape, very simple and effective. It also has the ability to run tests asynchronously, I had to give it a try and so far it’s been nice.
For code coverage Nodeku is using nyc as recommended by ava’s docs. Setup was painless and getting it to work with CircleCI was as well. Here’s an image of the output:
Just for kicks I threw in Immutable and I feel like it might kick me in the butt later on, maybe… we’ll see.
update 2017, Oct 6th: ImmutableJs has been removed!
Auto-publishing to NPM
Publishing made easy with CircleCI’s deployment scripts and a handy little NPM package named Publish. I set up an npm script which runs the publish binary. Publish will check what version is on NPM and what the local version is, if the local version has been bumped then it will trigger a publish onto NPM. Nifty!
Originally, I wanted to build an electron app to control my Roku but I figured that I need a sort of base module to interface with the device before building the electron app. So this project is a one step towards that goal.
Next, I will build a simple electron app to control my device. At the same time I will be looking at the official docs for leads on other features I could implement. The ability to search would be a good feature to have.
Enjoy and please report all issues on github.