2013-01-30 14:30:49 +00:00
|
|
|
var express = require('express')
|
2013-01-30 23:09:00 +00:00
|
|
|
, 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');
|
2013-01-30 23:09:00 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2013-01-30 23:09:00 +00:00
|
|
|
app.get("/", function(req, res) {
|
2013-02-12 23:12:44 +00:00
|
|
|
res.render('index', { title: 'COSM display', streams: cosmStreams });
|
2013-01-30 23:09:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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 23:09:00 +00:00
|
|
|
});
|
|
|
|
});
|
2013-01-30 14:30:49 +00:00
|
|
|
|
2013-01-30 23:09:00 +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-01-30 23:09:00 +00:00
|
|
|
|
|
|
|
|
2013-02-12 23:12:44 +00:00
|
|
|
|
|
|
|
// this event is send by cosm client when new data arrives (just when values changes)
|
2013-01-30 23:09:00 +00:00
|
|
|
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);
|
2013-01-30 23:09:00 +00:00
|
|
|
});
|