Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Last active December 17, 2015 17:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiyoh/5649037 to your computer and use it in GitHub Desktop.
Save taiyoh/5649037 to your computer and use it in GitHub Desktop.
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