Permalink
Browse files

System now emits "data" events instead of "read" events.

This follows the normal stream reader model.
  • Loading branch information...
1 parent 988a8c7 commit 49b37515c70063d348f3e0d8d992d0018535c914 @Trakkasure committed Jun 27, 2011
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/index.js
View
@@ -152,7 +152,7 @@ api.prototype.sentence=function(data) {
if (this.channel[channel]) this.channel[channel].emit('trap',e,this.channel[channel]);
} else // no trap. Send general packet.
if (this.channel[channel])
- this.channel[channel].read(this.packet);
+ this.channel[channel].data(this.packet);
} else
if (this.trap) {
var l=data.split(/=/);
@@ -506,10 +506,10 @@ function Channel(instance) {
this.buffer=[];
} else {
var b=this.buffer;
- this.buffer=[];
- b.push('.tag='+this.getId());
this.running(true);
this.saveBuffer(true);
+ this.buffer=[];
+ b.push('.tag='+this.getId());
this.callback=writeCallback;
this.callback(this); // allow setup before sending command.
this.callback=null;
@@ -524,24 +524,26 @@ function Channel(instance) {
instance.packet=[];
this.emit('done',p,this);
this.removeAllListeners('done');
+ this.removeAllListeners('data');
this.removeAllListeners('read');
@Trakkasure
Trakkasure Jun 27, 2011 Owner

This will go away soon.

this.running(false);
if (instance.commands.length) {
var c=instance.commands.shift();
if (this.getConnection().debug>0)
- util.debug('Channel ('+this.getConnection().getHost()+":"+this.getId()+') buffered commands('+instance.commands.length+1+'): '+JSON.stringify(c));
+ util.debug('Channel ('+this.getConnection().getHost()+":"+this.getId()+') buffered commands('+(instance.commands.length+1)+'): '+JSON.stringify(c));
cl=instance.closing;
instance.closing=false;
this.write(c[0],c[1]);
instance.closing=cl;
} else
if (instance.closing||instance.closeOnDone) this.close();
},
- read: function(data) { // Don't call instance directly. This is called when a full sentence is received (typically a !re line)
+ data: function(data) { // Don't call instance directly. This is called when a full sentence is received (typically a !re line)
if (this.getConnection().debug>2)
- util.debug('Channel read: '+data);
+ util.debug('Channel data: '+data);
if (this.saveBuffer())
instance.packet.push(data);
+ this.emit('data',[data],this);
@Trakkasure
Trakkasure Jun 27, 2011 Owner

This will go away soon.

this.emit('read',[data],this);
},
close:function(force) { // Close instance channel.

0 comments on commit 49b3751

Please sign in to comment.