Skip to content

Commit

Permalink
Miscellaneous organization and clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
tristandunn committed Jun 8, 2011
1 parent 814efe7 commit 7025d32
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions lib/campfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,52 +150,54 @@ Campfire.Room.prototype.listen = function(callback) {

campfire.http.request(options, function(response) {
response.setEncoding('utf8');
response.on('data', function(chunk) {
if (chunk.trim() == '') {
response.on('data', function(data) {
if (!data.trim()) {
return;
}

chunk = chunk.split("\r");
var chunks = data.split("\r");

for (var i = 0; i < chunk.length; ++i) {
if (chunk[i].trim() != '') {
for (var i = 0; i < chunks.length; ++i) {
var chunk = chunks[i].trim();

if (chunk) {
try {
callback(JSON.parse(chunk[i]));
callback(JSON.parse(chunk));
} catch(e) {}
}
}
});
}).end();
},
};

Campfire.Room.prototype.speak = function(text, callback) {
this.message(text, 'TextMessage', callback);
Campfire.Room.prototype.lock = function(callback) {
this.post('/lock', '', callback);
};

Campfire.Room.prototype.message = function(text, type, callback) {
this.post('/speak', { message : { body : text, type : type } }, callback);
};

Campfire.Room.prototype.paste = function(text, callback) {
this.message(text, 'PasteMessage', callback);
};

Campfire.Room.prototype.show = function(callback) {
this.post('', '', callback);
};

Campfire.Room.prototype.sound = function(text, callback) {
this.message(text, 'SoundMessage', callback);
},

Campfire.Room.prototype.message = function(text, type, callback) {
this.post('/speak', { message : { body : text, type : type } }, callback);
};

Campfire.Room.prototype.lock = function(callback) {
this.post('/lock', '', callback);
Campfire.Room.prototype.speak = function(text, callback) {
this.message(text, 'TextMessage', callback);
};

Campfire.Room.prototype.unlock = function(callback) {
this.post('/unlock', '', callback);
};

Campfire.Room.prototype.show = function(callback) {
this.post('', '', callback);
};

Campfire.Room.prototype.get = function(path, callback) {
this.campfire.get(this.path + path, callback);
};
Expand Down

0 comments on commit 7025d32

Please sign in to comment.