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/5649031 to your computer and use it in GitHub Desktop.
Save taiyoh/5649031 to your computer and use it in GitHub Desktop.
lirc_webのapp.jsの一部をこんな感じで書き換えた
app.get('/api/stream', function(req, res) {
console.log('connection catched');
var sock = req.socket;
conns[sock.fd] = sock;
res.on('close', function() {
delete conns[sock.fd];
console.log('disconnected: ' + Object.keys(conns).join(", "));
});
sock.on('close', function() {
delete conns[sock.fd];
});
sock.on('end', function() {
delete conns[sock.fd];
});
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.write("\n");
});
// API endpoint
app.post('/remotes/:remote/:command', function(req, res) {
console.log("Sending " + req.params.command + " to " + req.params.remote);
//lirc_node.irsend.send_once(req.params.remote, req.params.command, function() {});
var data = JSON.stringify({"remote":req.params.remote,"command":req.params.command}) + "\n";
Object.keys(conns).forEach(function(fd) {
var sock = conns[fd];
sock.write(data);
});
res.setHeader('Cache-Control', 'no-cache');
res.send(200);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment