Skip to content

Commit

Permalink
Can parse queues of messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
adngdb committed May 24, 2011
1 parent 3852d1b commit 3dd83b5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/message-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ function MessageParser(engine) {
MessageParser.prototype = {

parse: function(message, clientId) {
var user = this.engine.getUser(clientId);
if (user != null) {
var user = null;

if (clientId._client) {
user = clientId;
}
else {
user = this.engine.getUser(clientId);
}

if (user) {
var obj = JSON.parse(message);

switch (obj.type) {
Expand All @@ -30,6 +38,9 @@ MessageParser.prototype = {
case "data":
this.parseData(obj.data, user);
break;
case "queue":
this.parseQueue(obj.data, user);
break;
default:
throw "Warning - MessageParser.parse - Unknown message type: " + obj.type; // TODO: using an object of type Exception
}
Expand Down Expand Up @@ -109,6 +120,18 @@ MessageParser.prototype = {
return this;
},

parseQueue: function(data, user) {
var i = 0
,ln = data.length
;

for (; i < ln; i++) {
this.parse(data[i], user);
}

return this;
},

}

module.exports = MessageParser;

0 comments on commit 3dd83b5

Please sign in to comment.