diff --git a/README.md b/README.md index bbcd9d1..796f1ce 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,10 @@ Start the server. An options callback that gets called when the server is listening. ## Default Events -* `error` - this is simply the client connection error event being bubbled up to the server. +* `error` - this is simply the client connection error event being bubbled up to the server. listener definition: `function(error)` +* `line` - this is called with each raw line (not split on delimiter or command lowered, etc). listener definition: `function(connection, line)` +* `connection` - this is called with each new connection. listener definition `function(connection)` + ## License ``` diff --git a/lib/index.js b/lib/index.js index eeab8e3..b15da40 100644 --- a/lib/index.js +++ b/lib/index.js @@ -36,8 +36,12 @@ cmdsrv.prototype.handle = function(connection){ var self = this; var buffer = ""; + this.emit("connection", connection); + connection.on("line", function(line){ - var parts = line.trim().split(self.delimiter); + line = line.trim(); + self.emit("line", connection, line) + var parts = line.split(self.delimiter); if(!parts.length){ return;