Last active
December 17, 2015 17:49
-
-
Save taiyoh/5649031 to your computer and use it in GitHub Desktop.
lirc_webのapp.jsの一部をこんな感じで書き換えた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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