Comparing version 0.2.5 to 0.2.6
153
lib/nats.js
@@ -20,3 +20,3 @@ /*! | ||
var VERSION = '0.2.5', | ||
var VERSION = '0.2.6', | ||
@@ -66,5 +66,5 @@ DEFAULT_PORT = 4222, | ||
Q_SUB = /^([^\.\*>\s]+|>$|\*)(\.([^\.\*>\s]+|>$|\*))*$/, | ||
Q_SUB_NO_WC = /^([^\.\*>\s]+)(\.([^\.\*>\s]+))*$/; | ||
Q_SUB_NO_WC = /^([^\.\*>\s]+)(\.([^\.\*>\s]+))*$/, | ||
FLUSH_THRESHOLD = 65536, | ||
FLUSH_THRESHOLD = 65536; | ||
@@ -100,3 +100,3 @@ /** | ||
hexRand(0x1000000)); | ||
} | ||
}; | ||
@@ -129,3 +129,3 @@ /** | ||
return new Client(opts); | ||
} | ||
}; | ||
@@ -206,3 +206,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -264,3 +264,3 @@ /** | ||
if (client.closed === true || | ||
client.reconnects >= client.options.maxReconnectAttempts) { | ||
client.reconnects >= client.options.maxReconnectAttempts) { | ||
client.emit('close'); | ||
@@ -281,21 +281,21 @@ } else { | ||
case AWAITING_CONTROL: | ||
if (m = MSG.exec(client.inbound)) { | ||
if ((m = MSG.exec(client.inbound)) != null) { | ||
client.payload = { | ||
subj : m[1], | ||
sid : m[2], | ||
reply : m[4], | ||
size : parseInt(m[5], 10) | ||
} | ||
subj : m[1], | ||
sid : m[2], | ||
reply : m[4], | ||
size : parseInt(m[5], 10) | ||
}; | ||
client.pstate = AWAITING_MSG_PAYLOAD; | ||
} else if (m = OK.exec(client.inbound)) { | ||
} else if ((m = OK.exec(client.inbound)) != null) { | ||
// Ignore for now.. | ||
} else if (m = ERR.exec(client.inbound)) { | ||
} else if ((m = ERR.exec(client.inbound)) != null) { | ||
client.emit('error', m[1]); | ||
} else if (m = PONG.exec(client.inbound)) { | ||
var cb = client.pongs.shift() | ||
if (cb) cb(); | ||
} else if (m = PING.exec(client.inbound)) { | ||
this.send_command(PONG_RESPONSE); | ||
} else if (m = INFO.exec(client.inbound)) { | ||
// Nothing for now.. | ||
} else if ((m = PONG.exec(client.inbound)) != null) { | ||
var cb = client.pongs.shift(); | ||
if (cb) { cb(); } // FIXME: Should we check for exceptions? | ||
} else if ((m = PING.exec(client.inbound)) != null) { | ||
client.sendCommand(PONG_RESPONSE); | ||
} else if ((m = INFO.exec(client.inbound)) != null) { | ||
// Ignore for now.. | ||
} else { | ||
@@ -311,9 +311,9 @@ // FIXME, check line length for something weird. | ||
if (client.inbound.length < client.payload.size + CR_LF_LEN) { | ||
return; | ||
} | ||
return; | ||
} | ||
// FIXME, may be inefficient. | ||
// FIXME, may be inefficient. | ||
client.payload.msg = client.inbound.slice(0, client.payload.size).toString(); | ||
if (client.inbound.length == client.payload.size + CR_LF_LEN) { | ||
if (client.inbound.length === client.payload.size + CR_LF_LEN) { | ||
client.inbound = null; | ||
@@ -347,3 +347,3 @@ } else { | ||
this.sendCommand(CONNECT + SPC + JSON.stringify(cs) + CR_LF); | ||
} | ||
}; | ||
@@ -362,3 +362,3 @@ /** | ||
this.reconnecting = false; | ||
} | ||
}; | ||
@@ -381,3 +381,3 @@ /** | ||
this.pSize = 0; | ||
} | ||
}; | ||
@@ -402,3 +402,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -419,3 +419,3 @@ /** | ||
this.pSize = 0; | ||
} | ||
}; | ||
@@ -442,3 +442,3 @@ /** | ||
process.nextTick(function() { | ||
self.flushPending(); | ||
self.flushPending(); | ||
}); | ||
@@ -450,5 +450,4 @@ } else if (this.pSize > FLUSH_THRESHOLD) { | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -463,11 +462,13 @@ * Sends existing subscriptions to new server after reconnect. | ||
for(var sid in this.subs) { | ||
var sub = this.subs[sid]; | ||
if (sub.qgroup) { | ||
proto = [SUB, sub.subject, sub.qgroup, sid + CR_LF]; | ||
} else { | ||
proto = [SUB, sub.subject, sid + CR_LF]; | ||
if (this.subs.hasOwnProperty(sid)) { | ||
var sub = this.subs[sid]; | ||
if (sub.qgroup) { | ||
proto = [SUB, sub.subject, sub.qgroup, sid + CR_LF]; | ||
} else { | ||
proto = [SUB, sub.subject, sid + CR_LF]; | ||
} | ||
this.sendCommand(proto.join(SPC)); | ||
} | ||
this.sendCommand(proto.join(SPC)); | ||
} | ||
} | ||
}; | ||
@@ -492,11 +493,19 @@ /** | ||
// Check for auto-unsubscribe | ||
if (sub['max'] && sub.received > sub.max) { | ||
this.unsubscribe(this.payload.sid); | ||
} else if (sub.callback) { | ||
if (sub.max !== undefined) { | ||
if (sub.received === sub.max) { | ||
delete this.subs[this.payload.sid]; | ||
} else if (sub.received > sub.max) { | ||
this.unsubscribe(this.payload.sid); | ||
sub.callback = null; | ||
} | ||
} | ||
if (sub.callback) { | ||
sub.callback(this.payload.msg, this.payload.reply, this.payload.subj); | ||
} | ||
} | ||
this.pstate = AWAITING_CONTROL; | ||
this.payload = null; | ||
} | ||
}; | ||
@@ -516,3 +525,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -530,5 +539,7 @@ /** | ||
Client.prototype.publish = function(subject, msg, opt_reply, opt_callback) { | ||
if (!msg) msg = EMPTY; | ||
if (typeof msg == 'function') { | ||
if (opt_callback || opt_reply) throw(new Error("Message can't be a function")); | ||
if (!msg) { msg = EMPTY; } | ||
if (typeof msg === 'function') { | ||
if (opt_callback || opt_reply) { | ||
throw(new Error("Message can't be a function")); | ||
} | ||
opt_callback = msg; | ||
@@ -538,4 +549,6 @@ msg = EMPTY; | ||
} | ||
if (typeof opt_reply == 'function') { | ||
if (opt_callback) throw(new Error("Reply can't be a function")); | ||
if (typeof opt_reply === 'function') { | ||
if (opt_callback) { | ||
throw(new Error("Reply can't be a function")); | ||
} | ||
opt_callback = opt_reply; | ||
@@ -546,3 +559,3 @@ opt_reply = undefined; | ||
var proto = [PUB, subject]; | ||
var msg = [Buffer.byteLength(msg), CR_LF, msg, CR_LF]; | ||
var pmsg = [Buffer.byteLength(msg), CR_LF, msg, CR_LF]; | ||
@@ -553,3 +566,3 @@ if (opt_reply !== undefined) { | ||
this.sendCommand(proto.concat(msg.join(EMPTY)).join(SPC)); | ||
this.sendCommand(proto.concat(pmsg.join(EMPTY)).join(SPC)); | ||
@@ -559,3 +572,3 @@ if (opt_callback !== undefined) { | ||
} | ||
} | ||
}; | ||
@@ -575,15 +588,15 @@ /** | ||
var qgroup, max; | ||
if (typeof opts == 'function') { | ||
if (typeof opts === 'function') { | ||
callback = opts; | ||
opts = null; | ||
} else if (opts && typeof opts == 'object') { | ||
} else if (opts && typeof opts === 'object') { | ||
// FIXME, check exists, error otherwise.. | ||
qgroup = opts['queue']; | ||
max = opts['max']; | ||
qgroup = opts.queue; | ||
max = opts.max; | ||
} | ||
this.ssid += 1; | ||
this.subs[this.ssid] = { 'subject':subject, 'callback':callback, 'received':0 } | ||
this.subs[this.ssid] = { 'subject':subject, 'callback':callback, 'received':0 }; | ||
var proto; | ||
if (typeof qgroup == 'string') { | ||
if (typeof qgroup === 'string') { | ||
this.subs[this.ssid].qgroup = qgroup; | ||
@@ -600,3 +613,3 @@ proto = [SUB, subject, qgroup, this.ssid + CR_LF]; | ||
return this.ssid; | ||
} | ||
}; | ||
@@ -626,7 +639,7 @@ /** | ||
} | ||
sub['max'] = opt_max; | ||
if (sub['max'] === undefined || (sub.received >= sub.max)) { | ||
sub.max = opt_max; | ||
if (sub.max === undefined || (sub.received >= sub.max)) { | ||
delete this.subs[sid]; | ||
} | ||
} | ||
}; | ||
@@ -648,3 +661,3 @@ /** | ||
sub.timeout = setTimeout(function() { callback(sid); }, timeout); | ||
} | ||
}; | ||
@@ -662,3 +675,3 @@ /** | ||
Client.prototype.request = function(subject, opt_msg, opt_options, callback) { | ||
if (typeof opt_msg == 'function') { | ||
if (typeof opt_msg === 'function') { | ||
callback = opt_msg; | ||
@@ -668,3 +681,3 @@ opt_msg = EMPTY; | ||
} | ||
if (typeof opt_options == 'function') { | ||
if (typeof opt_options === 'function') { | ||
callback = opt_options; | ||
@@ -678,3 +691,3 @@ opt_options = null; | ||
this.publish(subject, opt_msg, inbox); | ||
} | ||
}; | ||
@@ -692,3 +705,3 @@ /** | ||
this.emit('reconnecting'); | ||
} | ||
}; | ||
@@ -705,2 +718,2 @@ /** | ||
setTimeout(function() { client.reconnect(); }, this.options.reconnectTimeWait); | ||
} | ||
}; |
{ | ||
"name": "nats", | ||
"description": "Node.js client for NATS, a lightweight messaging system", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "type" : "git", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24399
698