chaosc-cosmdisplay/app.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2013-01-30 14:30:49 +00:00
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, path = require('path')
, io = require('socket.io').listen(server)
, cosm = require('./cosm.js')
, osc = require('./osc.js');
2013-02-12 23:12:44 +00:00
var cosmStreams = [ 70632 ];
var cosmClient = new cosm(cosmStreams, 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g');
var oscClient = new osc('localhost', 8000);
2013-01-30 14:30:49 +00:00
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function () {
app.use(express.errorHandler());
app.locals.pretty = true;
});
app.get("/", function(req, res) {
2013-02-12 23:12:44 +00:00
res.render('index', { title: 'COSM display', streams: cosmStreams });
});
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
2013-02-12 23:12:44 +00:00
console.log("bla" + data);
});
cosmClient.getStreams(cosmStreams, function(object) {
socket.emit('gotstream', object);
});
});
2013-01-30 14:30:49 +00:00
server.listen(app.get('port'), function () {
2013-01-30 14:30:49 +00:00
console.log("Express server listening on port " + app.get('port'));
});
2013-02-12 23:12:44 +00:00
// this event is send by cosm client when new data arrives (just when values changes)
cosmClient.on('changedvalue', function(object) {
console.log("changedvalue: " + JSON.stringify(object));
oscClient.send('/cosm/' + object.stream + "/" + object.displayname, object.value);
2013-02-12 23:12:44 +00:00
io.sockets.emit('changedvalue', object);
});