From 201edd7a9b74d55f7e0885ecbca839e5cc1181e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 13 Feb 2013 00:12:44 +0100 Subject: [PATCH] ... --- app.js | 17 +++++++++---- cosm.js | 66 +++++++++++++++++++++++++++++++++--------------- package.json | 1 - views/index.jade | 26 ++++++++++--------- 4 files changed, 72 insertions(+), 38 deletions(-) diff --git a/app.js b/app.js index 93fcbd1..6e63822 100644 --- a/app.js +++ b/app.js @@ -6,7 +6,9 @@ var express = require('express') , cosm = require('./cosm.js') , osc = require('./osc.js'); -var cosmClient = new cosm([91755, 70632], 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g'); +var cosmStreams = [ 70632 ]; + +var cosmClient = new cosm(cosmStreams, 'orKBBdLAKuKJU-RxqmZpZB6q0baSAKxBTVhKdjhUNkdyVT0g'); var oscClient = new osc('localhost', 8000); @@ -27,13 +29,17 @@ app.configure('development', function () { }); app.get("/", function(req, res) { - res.render('index', { title: 'COSM display' }); + 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) { - console.log(data); + console.log("bla" + data); + }); + + cosmClient.getStreams(cosmStreams, function(object) { + socket.emit('gotstream', object); }); }); @@ -42,9 +48,10 @@ server.listen(app.get('port'), function () { }); -// this event is send by cosm client when new data arrives (just when values changed) + +// 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); + io.sockets.emit('changedvalue', object); }); \ No newline at end of file diff --git a/cosm.js b/cosm.js index 6ac919d..a45f9cc 100644 --- a/cosm.js +++ b/cosm.js @@ -2,13 +2,14 @@ var restify = require('restify') , util = require('util') , EventEmitter = require('events').EventEmitter; -var COSM = function(streams, key) { +// constructor function +function Cosm(streams, key) { var self = this; - var streams = streams; - var interval = 1000; + self._streams = streams; + self._interval = 5000; - var jsonClient = restify.createJsonClient({ + self._jsonClient = restify.createJsonClient({ url: 'http://api.cosm.com', headers: { 'X-ApiKey': key }, version:'*' @@ -20,7 +21,7 @@ var COSM = function(streams, key) { for(var i=0; i