Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Last active Dec 17, 2015
Embed
What would you like to do?
lirc_webにつなぎっぱにしてイベントを待つプロセス
//
// lirc_web
// v0.0.4
// Alex Bain <alex@alexba.in>
//
// Requirements
//
var lirc_node = require('lirc_node'),
consolidate = require('consolidate'),
swig = require('swig'),
http = require('http');
var opts = {
hostname: 'example.com',
path: '/api/stream',
auth: 'foo:bar'
};
var req = http.request(opts, function(res) {
res.setEncoding('utf8');
//console.log('connected', res.headers);
res.on('data', function(chunk) {
chunk = chunk.replace(/\n+$/, '');
console.log('BODY: ' + chunk);
if (!chunk) return;
var data = JSON.parse(chunk);
lirc_node.irsend.send_once(data.remote, data.command, function() {});
});
res.on('end', function() {
console.log('disconnected');
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment