50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
var readline = require('readline');
|
|
var dateFormat = require('dateformat');
|
|
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');
|
|
|
|
oscServer.on("message", function (msg, rinfo) {
|
|
var dateString = dateFormat(new Date(), "HH:MM:ss.L");
|
|
console.log(dateString + "\t" + msg);
|
|
});
|
|
|
|
oscClient.send('/subscribe','192.168.23.102', listenPort, "sekret");
|
|
|
|
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);
|
|
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);
|
|
process.exit(0);
|
|
});
|
|
|
|
|
|
function isNumber(value) {
|
|
if ((undefined === value) || (null === value)) {
|
|
return false;
|
|
}
|
|
if (typeof value == 'number') {
|
|
return true;
|
|
}
|
|
return !isNaN(value - 0);
|
|
}
|
|
|
|
|