chaosc-fetcher/oscreceiver.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2012-12-18 15:21:46 +00:00
var readline = require('readline');
2012-12-17 13:58:03 +00:00
var osc = require('node-osc');
var listenPort = 8000;
var hubAddress = '192.168.23.43';
var hubPort = 7110;
var oscClient = new osc.Client(hubAddress, hubPort);
var oscServer = new osc.Server(listenPort, '0.0.0.0');
2012-12-18 15:21:46 +00:00
2012-12-17 13:58:03 +00:00
oscServer.on("message", function (msg, rinfo) {
console.log("message: " + msg);
2012-12-17 13:58:03 +00:00
});
2012-12-18 15:21:46 +00:00
oscClient.send('/subscribe','192.168.23.102', listenPort, "sekret");
2012-12-18 15:21:46 +00:00
var rl = readline.createInterface(process.stdin,process.stdout,null);
rl.on('line', function(cmd) {
var sepIndex = cmd.indexOf(":");
if(sepIndex > 0) {
var path = cmd.substr(0, sepIndex);
var val = cmd.substr(sepIndex+1);
if(isNumber(val)) parseFloat(val);
2012-12-18 15:21:46 +00:00
console.log("writing: %s with %s", path, val);
oscClient.send(path, val);
}
});
rl.on('close', function(cmd) {
console.log("bye bye");
oscClient.send('/unsubscribe', hubAddress, listenPort);
2012-12-18 15:21:46 +00:00
process.exit(0);
});
function isNumber(value) {
if ((undefined === value) || (null === value)) {
return false;
}
if (typeof value == 'number') {
return true;
}
return !isNaN(value - 0);
}