Permalink
Browse files

Emit events. Closes #5

  • Loading branch information...
tj committed Sep 7, 2010
1 parent 6ed0811 commit d8974479776c9dd9212a6f42670445cd8525847e
Showing with 15 additions and 1 deletion.
  1. +4 −0 examples/google.js
  2. +11 −1 lib/soda/client.js
View
@@ -13,6 +13,10 @@ var browser = soda.createClient({
browser: 'firefox'
});
+browser.on('command', function(cmd, args){
+ console.log(' \x1b[33m%s\x1b[0m: %s', cmd, args.join(', '));
+});
+
browser
.chain
.session()
View
@@ -10,7 +10,8 @@
*/
var http = require('http')
- , qs = require('querystring');
+ , qs = require('querystring')
+ , EventEmitter = require('events').EventEmitter;
/**
* Initialize a `Client` with the given `options`.
@@ -32,8 +33,15 @@ var Client = exports = module.exports = function Client(options) {
this.browser = options.browser || 'firefox';
this.url = options.url;
if (this.browser[0] !== '*') this.browser = '*' + this.browser;
+ EventEmitter.call(this);
};
+/**
+ * Interit from `EventEmitter`.
+ */
+
+Client.prototype.__proto__ = EventEmitter.prototype;
+
/**
* Initialize a new session, then callback `fn(err, sid)`
*
@@ -69,6 +77,8 @@ Client.prototype.session = function(fn){
*/
Client.prototype.command = function(cmd, args, fn){
+ this.emit('command', cmd, args);
+
// HTTP client
var client = http.createClient(this.port, this.host);

0 comments on commit d897447

Please sign in to comment.