hackcentercontrol/nodeartnet/app.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2012-12-28 22:17:47 +00:00
var express = require('express');
var app = express();
var server = require('http').createServer(app), io = require('socket.io').listen(server);
var osc = require('node-osc');
var host = process.argv.length > 2 ? process.argv[2] : 'distinto.lp-server.net';
var port = process.argv.length > 3 ? process.argv[3] : '5001';
var oscSender = new osc.Client(host, port);
var states = [];
server.listen(8080);
app.use(express.static('bootstrap'));
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function (socket) {
//socket.emit('news', { hello: 'world' });
2012-12-28 23:10:43 +00:00
var address = socket.handshake.address;
console.log("New connection from " + address.address + ":" + address.port);
2012-12-28 22:17:47 +00:00
socket.on('oscmessage', function (data) {
var chan = data.chan;
var value = data.val;
if(chan == null) return;
if(value == null) {
if(states[chan] == null) {
states[chan] = 1
} else if(states[chan] == 1) {
states[chan] = 0;
} else if(states[chan] == 0) {
states[chan] = 1;
}
value = states[chan];
}
// hier noch nicht einkommentieren, das sendet das sofort ins hackcenter
//oscSender.send(chan, value);
2012-12-28 23:10:43 +00:00
console.log(address, chan, value);
2012-12-28 22:17:47 +00:00
});
});