diff --git a/lib/cam.js b/lib/cam.js index 643692e1..b981d3aa 100644 --- a/lib/cam.js +++ b/lib/cam.js @@ -83,6 +83,7 @@ var Cam = function(options, callback) { this.preserveAddress = options.preserveAddress || false; this.events = {}; + this.events.timeout = options.eventsTimeout || this.timeout; setImmediate(function() { this.connect(callback); }.bind(this)); @@ -184,7 +185,7 @@ Cam.prototype._request = function(options, callback) { , path: options.service ? (this.uri[options.service] ? this.uri[options.service].path : options.service) : this.path - , timeout: this.timeout + , timeout: options.timeout || this.timeout }; reqOptions.headers = { 'Content-Type': 'application/soap+xml' @@ -215,7 +216,7 @@ Cam.prototype._request = function(options, callback) { }); }); - req.setTimeout(this.timeout, function() { + req.setTimeout(options.timeout || this.timeout, function() { if (callbackExecuted === true) { return; } else { diff --git a/lib/events.js b/lib/events.js index 8b266f7b..c0dc3b20 100644 --- a/lib/events.js +++ b/lib/events.js @@ -206,12 +206,13 @@ module.exports = function(Cam) { sendXml += '' + '' + '' + - 'PT5S' + // pull timeout must be shorter than Socket timeout or we will get a socket error when there are no new events + 'PT' + ((options.timeout || 5000) / 1000) + 'S' + '' + (options.messageLimit || 10) + '' + '' + this._envelopeFooter() this._request({ url: urlAddress, + timeout: !isNaN(options.timeout) ? options.timeout + 5000 : 10000, // Socket timeout must be longer than pull timeout or we will get a socket error when there are no new events body: sendXml }, function(err, res, xml) { if (!err) { @@ -310,6 +311,7 @@ module.exports = function(Cam) { if (this.listeners('event').length) { // check for event listeners, if zero, stop pulling this.pullMessages({ messageLimit: this.events.messageLimit + , timeout: this.events.timeout }, function(err, data, xml) { if (!err) { if (data.notificationMessage) {