Browse Source

make sure to emit 'line' and 'connection' events

master
Brett Langdon 12 years ago
parent
commit
0fb8f8cf8a
2 changed files with 9 additions and 2 deletions
  1. +4
    -1
      README.md
  2. +5
    -1
      lib/index.js

+ 4
- 1
README.md View File

@ -83,7 +83,10 @@ Start the server.
An options callback that gets called when the server is listening. An options callback that gets called when the server is listening.
## Default Events ## 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 ## License
``` ```


+ 5
- 1
lib/index.js View File

@ -36,8 +36,12 @@ cmdsrv.prototype.handle = function(connection){
var self = this; var self = this;
var buffer = ""; var buffer = "";
this.emit("connection", connection);
connection.on("line", function(line){ 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){ if(!parts.length){
return; return;


Loading…
Cancel
Save