Permalink
Browse files

Working implementation!

  • Loading branch information...
1 parent 8425690 commit d57af35ed784416c7383882e1abddaaf2b34fc50 Mark Cahill committed Sep 8, 2011
Showing with 24 additions and 19 deletions.
  1. +13 −6 listeners/couchdb.js
  2. +3 −2 server.js
  3. +8 −11 telemetry.js
View
@@ -1,13 +1,20 @@
var nano = require('nano');
-exports = module.exports = function(config, options) {
+exports = module.exports = function(config) {
this.url = function(config) {
- return "https://" + config.username + ":" + config.password +
- "@" + config.host + ":" + config.port;
+ var url = "https://" + encodeURIComponent(config.username) + ":" +
+ encodeURIComponent(config.password) +
+ "@" + encodeURIComponent(config.host);
+ if (config.port) {
+ url += ":" + parseInt(config.port);
+ }
+ return url;
};
- this.db = nano(this.url(config)).db;
- this.db.use(config.database);
- options.input.bind('event:new', this.post);
+ this.db = nano(this.url(config)).use(config.input);
+ /**
+ * Post a message to the telemetry server
+ * Required method
+ */
this.post = function(data) {
console.log("DATA:", data);
this.db.insert(data, function(error, http_body, http_headers) {
View
@@ -29,8 +29,9 @@ app.post('/input/:input', function(req, res, next) {
// Send success
var data = JSON.parse(req.body.source.replace('castor ', ''));
- console.log(telemetry, input);
- telemetry.inputs[input].trigger('event:new', data);
+ for (var i = 0; i < telemetry.inputs[input].length; i++) {
+ telemetry.inputs[input][i].post(data);
+ }
res.end('', 200);
});
View
@@ -1,4 +1,3 @@
-var Backbone = require('backbone');
var telemetry = exports = module.exports = function(config) {
/**
* The inputs that are listening on this server
@@ -12,21 +11,19 @@ var telemetry = exports = module.exports = function(config) {
// Load inputs
for (var i in config) {
if (config.hasOwnProperty(i)) {
- this.inputs[i] = _.extend({
- name: i
- }, Backbone.Events);
- this.inputs[i].listeners = [];
+ this.inputs[i] = [];
// Initialize listeners for this input
for (var j = 0; j < config[i].length; j++) {
try {
- var listener = new (global[config[i][j].type])(config[i][j],
- {
- input: this.inputs[i]
- });
- this.inputs[i].listeners.push(listener);
+ var listener_config = config[i][j];
+ listener_config.input = i;
+ var listener = new (global[config[i][j].type])(listener_config);
+ this.inputs[i].push(listener);
+ console.log(config[i][j].type, "listening for events on " +
+ "input called", i);
} catch (e) {
- console.error("Could not load", config[i][j].type, e.message);
+ console.error("Could not load", config[i][j].type, "listener [", e.message, "]");
}
}
}

0 comments on commit d57af35

Please sign in to comment.