Use on('data') for v0.8.x

This commit is contained in:
Brian Carlson 2013-08-17 17:25:24 -05:00
parent 5108161a47
commit c98125b065

View File

@ -22,6 +22,13 @@ var Connection = function(config) {
this.ssl = config.ssl || false;
this._ending = false;
this._mode = TEXT_MODE;
this._emitMessage = false;
var self = this;
this.on('newListener', function(eventName) {
if(eventName == 'message') {
self._emitMessage = true;
}
});
};
util.inherits(Connection, EventEmitter);
@ -80,18 +87,16 @@ Connection.prototype.connect = function(port, host) {
};
Connection.prototype.attachListeners = function(stream) {
var self = this;
stream.on('readable', function() {
var buff = stream.read();
if(!buff) return;
self.setBuffer(buff);
var msg = self.parseMessage();
while(msg) {
self.emit('message', msg);
self.emit(msg.name, msg);
msg = self.parseMessage();
stream.on('data', function(buff) {
this.setBuffer(buff);
var msg;
while(msg = this.parseMessage()) {
if(this._emitMessage) {
this.emit('message', msg);
}
});
this.emit(msg.name, msg);
}
}.bind(this));
};
Connection.prototype.requestSsl = function(config) {
@ -401,6 +406,7 @@ Connection.prototype.parseMessage = function() {
case 0x64: //d
return this.parsed(buffer, length);
}
return false;
};
Connection.prototype.parseR = function(buffer, length) {