Skip to content

Commit

Permalink
[fix]: Remove infinte broadcast loop, need to fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Jun 14, 2011
1 parent 4bc951b commit 96125c1
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lib/hookio/hook.js
Expand Up @@ -25,26 +25,34 @@ var Hook = exports.Hook = function (options) {
}

self.on('o.*', function(event, data){

console.log('I am currently sending data to my outputs on: '.green + event.toString().yellow + ' ' + JSON.stringify(data).grey);

var c = event.split('.');
c.shift();
c.unshift('i');

if (self.remote && self.remote.input) {
c.shift();
c.unshift('i');
self.remote.input(c.join('.'), data);
}
if(self.client && self.client.input){
self.client.input(event, data);
self.client.input(c.join('.'), data);
}
});

self.on('i.*', function(event, data){

console.log('I am currently getting data on my inputs from: '.green + event.toString().yellow + ' ' + JSON.stringify(data).grey);

var c = event.split('.');
c.shift();
c.unshift('o');
if (self.remote && self.remote.output) {
c.shift();
c.unshift('o');
self.remote.output(c.join('.'), data);
}
if(self.client && self.client.output){
self.client.output(event, data);
// TODO: Don't rebroadcast to self
//self.client.output(c.join('.'), data);
}
});

Expand Down Expand Up @@ -112,8 +120,10 @@ Hook.prototype._listen = function(options, callback){
};

this.input = function ( event, data ) {
console.log('getting input from: '.green + event.yellow + ' ' + JSON.stringify(data).grey);
console.log('sending output to: '.green + ' ' + event.yellow + ' ' + JSON.stringify(data).grey);
self.emit(event, data);
}

this.output = function ( event, data ) {
self.emit(event, data);
}

Expand Down Expand Up @@ -167,13 +177,18 @@ Hook.prototype.connect = function (options, callback) {
var client = dnode({
input : function (event, data) {
self.emit(event, data);
},
output: function ( event, data ) {
//self.emit(event, data);
}

});

client.connect(self.port, function (remote, conn) {

self.remote = remote;
self.conn = conn;
self.client = client;

remote.report(self.name, function(newName, newID){

Expand All @@ -187,7 +202,6 @@ Hook.prototype.connect = function (options, callback) {
});

}

// Hook.spawn()
// Uses forever to spawn up more hooks programatically

Expand Down

0 comments on commit 96125c1

Please sign in to comment.