roku能不能安装软件
I own an Apple TV 4, Apple TV 3, Roku 4, Chromecast, and a Firefox OS TV. From that you can probably gather that I love streaming content, particularly sports and movies. I obviously also love coding, which is why I loved being a Partner Engineer for Mozilla's Firefox OS TV -- I was enthusiastically testing out TV apps and exploring edge APIs and responsive techniques.
我拥有一台Apple TV 4,Apple TV 3,Roku 4,Chromecast和Firefox OS TV。 从中您可能会发现我喜欢流媒体内容,尤其是体育和电影。 我显然也很喜欢编码,这就是为什么我喜欢成为Mozilla的Firefox OS TV的合作工程师的原因-我一直在热情地测试TV应用程序,并探索边缘API和响应技术。
I'm always interested in finding a way to do interesting stuff with JavaScript and streaming instantly hit me. I can't do anything with a closed ecosystem Apple TV but there are known ways of working with a Roku so I set out to do something interesting with the Roku and Node.js -- create remote control functionality.
我一直想找到一种方法来用JavaScript做有趣的事情,并且流媒体立即使我大吃一惊。 我无法在封闭的生态系统Apple TV上做任何事情,但是有使用Roku的已知方法,因此我着手对Roku和Node.js做一些有趣的事情-创建远程控制功能。
Node.js Roku远程 (Node.js Roku Remote)
There's a nice utility out there called node-roku
which discovers Roku devices, providing the IP address of each Roku so that you can network with it. The node-roku
utility also provides an API to retrieve device information and app listing from the Roku. I chose to create a script which, once started, allows the user to use their computer's keyboard to navigate around a Roku, select and launch apps, and more.
那里有一个叫做node-roku
的不错的实用程序,它可以发现Roku设备,并提供每个Roku的IP地址,以便您可以与它联网。 node-roku
实用程序还提供了一个API,用于从Roku中检索设备信息和应用列表。 我选择创建一个脚本,一旦启动,该脚本将允许用户使用计算机键盘在Roku中导航,选择和启动应用程序等。
Let's start with version 0.1.0
with the source code:
让我们从带有源代码的0.1.0
版本开始:
const readline = require('readline');
const request = require('request');
const Roku = require('node-roku');
const xml2json = require('xml2json');
// Will be populated once a device is found
var address;
// Map to this URL: http://******:8060/keypress/{key}
const keyEndpoint = {
// Arrow Keys
left: 'Left',
right: 'Right',
up: 'Up',
down: 'Down',
// Standard Keys
space: 'Play',
backspace: 'Back',
return: 'Select',
// Sequences (shift key)
H: 'home',
R: 'Rev',
F: 'Fwd',
S: 'Search',
E: 'Enter',
// Other
r: 'InstantReplay',
b: 'InfoBackspace'
};
const xmlToObject = xml => {
return JSON.parse(xml2json.toJson(xml));
}
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
console.log('Looking for the (first) Roku...');
// Find the Roku
// TODO: Allow for selection of multiple Rokus; current assuming only one
Roku.find((err, devices) => {
if(err) {
console.log('`roku.find` error: ', err);
process.exit();
}
if(!devices.length) {
console.log('No Roku devices found. Bailing.');
process.exit();
}
address = devices[0];
Roku.getDevice(address, (err, deviceDetail) => {
console.log('Connected to Device: ', xmlToObject(deviceDetail).root.device.friendlyName, ' (', devices[0],')');
console.log('Press keys to navigate the Roku and select content!');
});
});
// Start the keypress listener
process.stdin.on('keypress', (str, key) => {
var endpoint;
// Ignore everything until we're connected
if(!address) {
return;
}
// "Raw" mode so we must do our own kill switch
if(key.sequence === '\u0003') {
process.exit();
}
// Handle commands
endpoint = keyEndpoint[key.name] || keyEndpoint[key.sequence] || 'Lit_' + key.name;
// Ignore undefined keypresses (no name or sequence)
if(endpoint === 'Lit_undefined') {
return;
}
// Send command!
request.post(address + '/keypress/' + endpoint);
});
Now let's explain what's going on with the source code above:
现在,让我们解释上面的源代码发生了什么:
xml2json
is required because device information is returned as XMLxml2json
是必需的,因为设备信息以XML形式返回Interaction with the Roku is done via POST requests with the URL format of
http://******:8060/keypress/{key}
; a POST is sent on each keypress与Roku的交互是通过POST请求(URL格式为
http://******:8060/keypress/{key}
; 每个按键都会发送一个POSTreadline.emitKeypressEvents(process.stdin);
andprocess.stdin.setRawMode(true);
directs Node.js to operate outside of normal shell operation, thus we need to explicitly check forCONTROL+C
to shut down the remote and Node.js processreadline.emitKeypressEvents(process.stdin);
和process.stdin.setRawMode(true);
指示Node.js在正常的shell操作之外运行,因此我们需要显式检查CONTROL+C
以关闭远程和Node.js进程The keypress logic is this: we use an object,
keyEndpoint
, to map logical keypress events to known endpoints; if a key isn't designated, we pass it along to the Roku as a keypress (i.e. a key to a search box, for example).按键逻辑是这样的:我们使用对象
keyEndpoint
,将逻辑按键事件映射到已知端点; 如果未指定键,则将其作为键(例如,搜索框的键)传递给Roku。
获取Roku远程 (Get roku-remote)
I've published my Roku Remote code to both GitHub and NPM -- install and usage instructions are available in both places. Please give it a run, file issues, and I'd love contributions if you have them!
我已经将我的Roku Remote代码发布到了GitHub和NPM上 -安装和使用说明在两个地方都可用。 请运行它,提交问题,如果您有贡献,我将不胜感激!
A web interface for roku-remote would be sweet; it could have different Roku's you could direct, a listing of apps which could be clicked to launch, and so forth. I'm happy with this first step because it fits my needs, is easy to use, and there's plenty of room to grow. Happy streaming!
用于roku-remote的Web界面会很漂亮; 它可能具有您可以指导的其他Roku,可以单击以启动的应用程序列表等。 我对第一步很满意,因为它可以满足我的需求,易于使用,并且还有很大的增长空间。 直播愉快!
roku能不能安装软件