From 0fb8f8cf8a1cd27f2e04860957b93ddc5aa0cd23 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Sat, 19 Oct 2013 07:23:09 -0700 Subject: [PATCH] make sure to emit 'line' and 'connection' events --- README.md | 5 ++++- lib/index.js | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) 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;