diff --git a/lib/PacketQueue.js b/lib/PacketQueue.js index b3afa23..9583d5c 100644 --- a/lib/PacketQueue.js +++ b/lib/PacketQueue.js @@ -13,6 +13,8 @@ var util = require('util'); var events = require('events'); +var jute = require('./jute'); + function PacketQueue() { events.EventEmitter.call(this); @@ -28,7 +30,14 @@ PacketQueue.prototype.push = function (packet) { throw new Error('packet must be a valid object.'); } - this.queue.push(packet); + if (packet.request.header.type === jute.OP_CODES.AUTH && + packet.request.header.xid === jute.XID_AUTHENTICATION) { + // let auth request go first + this.queue.unshift(packet); + } else { + // otherwise go last + this.queue.push(packet); + } this.emit('readable'); };