Comparing version 1.2.4 to 1.2.5
@@ -6,3 +6,6 @@ var Errors = require('./errors'); | ||
var tls = require('tls'); | ||
var net = require('net'); | ||
var sysu = require('util'); | ||
var util = require('./util'); | ||
var events = require('events'); | ||
var debug = function() {}; | ||
@@ -27,12 +30,19 @@ if(process.env.DEBUG) { | ||
* @config {Buffer|String} [keyData] The key data. If supplied will be used instead of loading from disk. | ||
* @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple. | ||
* @config {String} [pfx] File path for private key, certificate and CA certs in PFX or PKCS12 format. If supplied will be used instead of certificate and key above | ||
* @config {Buffer|String} [pfxData] PFX or PKCS12 format data containing the private key, certificate and CA certs. If supplied will be used instead of loading from disk. | ||
* @config {String} [passphrase] The passphrase for the connection key, if required | ||
* @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple | ||
* @config {String} [gateway="gateway.push.apple.com"] The gateway server to connect to. | ||
* @config {Number} [port=2195] Gateway port | ||
* @config {Boolean} [rejectUnauthorized=true] Reject Unauthorized property to be passed through to tls.connect() | ||
* @config {Boolean} [enhanced=true] Whether to use the enhanced notification format (recommended) | ||
* @config {Function} [errorCallback] A callback which accepts 2 parameters (err, notification). Recommended when using enhanced format. | ||
* @config {Number} [cacheLength] Number of notifications to cache for error purposes (See Readme) | ||
* @config {Number} [cacheLength=100] Number of notifications to cache for error purposes (See Readme) | ||
* @config {Boolean} [autoAdjustCache=false] Whether the cache should grow in response to messages being lost after errors. (Will still emit a 'cacheTooSmall' event) | ||
* @config {Number} [connectionTimeout=0] The duration the socket should stay alive with no activity in milliseconds. 0 = Disabled. | ||
*/ | ||
function Connection (options) { | ||
if(false === (this instanceof Connection)) { | ||
return new Connection(options); | ||
} | ||
this.options = { | ||
@@ -43,9 +53,14 @@ cert: 'cert.pem', | ||
keyData: null, | ||
ca: null, | ||
pfx: null, | ||
pfxData: null, | ||
passphrase: null, | ||
ca: null, | ||
gateway: 'gateway.push.apple.com', | ||
port: 2195, | ||
rejectUnauthorized: true, | ||
enhanced: true, | ||
errorCallback: undefined, | ||
cacheLength: 100 | ||
cacheLength: 100, | ||
autoAdjustCache: true, | ||
connectionTimeout: 0 | ||
}; | ||
@@ -57,2 +72,3 @@ | ||
this.keyData = null; | ||
this.pfxData = null; | ||
@@ -65,6 +81,8 @@ this.deferredInitialize = null; | ||
this.notificationBuffer = []; | ||
this.connectionTimeout = null; | ||
events.EventEmitter.call(this); | ||
}; | ||
sysu.inherits(Connection, events.EventEmitter); | ||
/** | ||
@@ -74,3 +92,3 @@ * @private | ||
Connection.prototype.checkInitialized = function () { | ||
if (this.keyData && this.certData) { | ||
if ((this.keyData && this.certData) || this.pfxData) { | ||
this.deferredInitialize.resolve(); | ||
@@ -92,30 +110,47 @@ } | ||
if (this.options.certData) { | ||
this.certData = this.options.certData; | ||
if(this.options.pfx != null || this.options.pfxData != null) { | ||
if(this.options.pfxData) { | ||
this.pfxData = this.options.pfxData; | ||
} | ||
else { | ||
fs.readFile(this.options.pfx, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.pfxData = data; | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
} | ||
else { | ||
fs.readFile(this.options.cert, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.certData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
if (this.options.certData) { | ||
this.certData = this.options.certData; | ||
} | ||
else { | ||
fs.readFile(this.options.cert, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.certData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
if (this.options.keyData) { | ||
this.keyData = this.options.keyData; | ||
} | ||
else { | ||
fs.readFile(this.options.key, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.keyData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
} | ||
if (this.options.keyData) { | ||
this.keyData = this.options.keyData; | ||
} | ||
else { | ||
fs.readFile(this.options.key, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.keyData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
this.checkInitialized(); | ||
@@ -139,7 +174,14 @@ return this.deferredInitialize.promise; | ||
socketOptions.key = this.keyData; | ||
socketOptions.cert = this.certData; | ||
if(this.pfxData) { | ||
socketOptions.pfx = this.pfxData; | ||
} | ||
else { | ||
socketOptions.key = this.keyData; | ||
socketOptions.cert = this.certData; | ||
socketOptions.ca = this.options.ca; | ||
} | ||
socketOptions.passphrase = this.options.passphrase; | ||
socketOptions.ca = this.options.ca; | ||
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized; | ||
socketOptions.socket = new net.Stream(); | ||
this.socket = tls.connect( | ||
@@ -150,27 +192,22 @@ this.options['port'], | ||
function () { | ||
if (!this.socket.authorized) { | ||
this.deferredConnection.reject(this.socket.authorizationError); | ||
return; | ||
} | ||
if (this.connectionTimeout) { | ||
clearTimeout(this.connectionTimeout); | ||
} | ||
if (this.options.connectionTimeout > 0) { | ||
this.connectionTimeout = setTimeout(this.destroyConnection.bind(this), this.options.connectionTimeout); | ||
} | ||
debug("Connection established"); | ||
this.emit('connected'); | ||
this.deferredConnection.resolve(); | ||
}.bind(this)); | ||
this.socket.on('data', this.handleTransmissionError.bind(this)); | ||
this.socket.setNoDelay(false); | ||
this.socket.setTimeout(this.options.connectionTimeout); | ||
this.socket.on("error", this.errorOccurred.bind(this)); | ||
this.socket.on("timeout", this.socketTimeout.bind(this)); | ||
this.socket.on("data", this.handleTransmissionError.bind(this)); | ||
this.socket.on("drain", this.socketDrained.bind(this)); | ||
this.socket.on('clientError', this.errorOccurred.bind(this)); | ||
this.socket.on("error", this.errorOccurred.bind(this)); | ||
this.socket.on("end", this.restartConnection.bind(this)); | ||
this.socket.once('close', this.restartConnection.bind(this)); | ||
this.socket.on("clientError", this.errorOccurred.bind(this)); | ||
this.socket.once("close", this.restartConnection.bind(this)); | ||
this.socket.socket.connect(this.options['port'], this.options['gateway']); | ||
}.bind(this)).fail(function (error) { | ||
debug("Module initialisation error:", error); | ||
this.emit('error', error); | ||
this.deferredConnection.reject(error); | ||
@@ -188,2 +225,3 @@ this.deferredConnection = null; | ||
debug("Socket error occurred", err); | ||
this.emit('socketError', err); | ||
if(!this.deferredConnection.promise.isResolved()) { | ||
@@ -203,2 +241,6 @@ this.deferredConnection.reject(err); | ||
debug("Socket drained"); | ||
if(this.options.enhanced) { | ||
var notification = this.cachedNotifications[this.cachedNotifications.length - 1]; | ||
this.emit('transmitted', notification); | ||
} | ||
if (this.socket && (this.socket.socket.bufferSize != 0 || !this.socket.writable)) { | ||
@@ -217,2 +259,11 @@ return; | ||
*/ | ||
Connection.prototype.socketTimeout = function() { | ||
debug("Socket timeout"); | ||
this.emit('timeout'); | ||
this.socket.end(); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Connection.prototype.destroyConnection = function() { | ||
@@ -238,2 +289,4 @@ debug("Destroying connection"); | ||
} | ||
this.emit('disconnected'); | ||
@@ -243,6 +296,2 @@ this.socket = undefined; | ||
if (this.connectionTimeout) { | ||
clearTimeout(this.connectionTimeout); | ||
} | ||
if (this.notificationBuffer.length) { | ||
@@ -302,2 +351,3 @@ debug("Notification queue has %d items, resending the first", this.notificationBuffer.length); | ||
} | ||
this.emit('transmissionError', errorCode, notification); | ||
this.raiseError(errorCode, notification); | ||
@@ -307,3 +357,13 @@ } | ||
this.cachedNotifications = temporaryCache; | ||
this.raiseError(Errors["none"], null); | ||
if(this.cachedNotifications.length > 0) { | ||
var differentialSize = this.cachedNotifications[0]['_uid'] - notification['_uid'] | ||
this.emit('cacheTooSmall', differentialSize); | ||
if(this.options.autoAdjustCache) { | ||
this.options.cacheLength += differentialSize * 2; | ||
} | ||
} | ||
this.emit('transmissionError', Errors["none"], null); | ||
this.raiseError(errorCode, null); | ||
} | ||
@@ -317,4 +377,2 @@ | ||
} | ||
this.destroyConnection(); | ||
} | ||
@@ -328,3 +386,10 @@ }; | ||
debug("Raising error:", errorCode, notification); | ||
if (typeof this.options.errorCallback == 'function') { | ||
if(errorCode instanceof Error) { | ||
debug("Error occurred with trace:", errorCode.stack); | ||
} | ||
if (notification && typeof notification.errorCallback == 'function' ) { | ||
notification.errorCallback(errorCode); | ||
} else if (typeof this.options.errorCallback == 'function') { | ||
this.options.errorCallback(errorCode, notification); | ||
@@ -339,27 +404,30 @@ } | ||
Connection.prototype.sendNotification = function (notification) { | ||
var token = notification.device.token; | ||
var encoding = notification.encoding || 'utf8'; | ||
var message = JSON.stringify(notification); | ||
var messageLength = Buffer.byteLength(message, encoding); | ||
var position = 0; | ||
var data; | ||
if (token === undefined) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['missingDeviceToken'], notification); | ||
}.bind(this)); | ||
return Errors['missingDeviceToken']; | ||
} | ||
if (messageLength > 255) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['invalidPayloadSize'], notification); | ||
}.bind(this)); | ||
return Errors['invalidPayloadSize']; | ||
} | ||
this.connect().then(function() { | ||
debug("Sending notification"); | ||
if (this.socket.socket.bufferSize !== 0 || !this.socket.writable) { | ||
debug("Buffering notification"); | ||
if (!this.socket || this.socket.socket.bufferSize !== 0 || !this.socket.writable) { | ||
this.bufferNotification(notification); | ||
return; | ||
} | ||
var token = notification.device.token; | ||
var encoding = notification.encoding || 'utf8'; | ||
var message = JSON.stringify(notification); | ||
var messageLength = Buffer.byteLength(message, encoding); | ||
var position = 0; | ||
var data; | ||
if (token === undefined) { | ||
this.raiseError(Errors['missingDeviceToken'], notification); | ||
return; | ||
} | ||
if (messageLength > 255) { | ||
this.raiseError(Errors['invalidPayloadSize'], notification); | ||
return; | ||
} | ||
notification._uid = this.currentId++; | ||
@@ -402,3 +470,3 @@ if (this.currentId > 0xffffffff) { | ||
position += data.write(message, position, encoding); | ||
if(this.socket.write(data)) { | ||
@@ -408,6 +476,9 @@ this.socketDrained(); | ||
}.bind(this)).fail(function (error) { | ||
this.bufferNotification(notification); | ||
this.raiseError(error, notification); | ||
}.bind(this)); | ||
return 0; | ||
}; | ||
module.exports = Connection; |
@@ -26,7 +26,10 @@ var Device = require('./device'); | ||
* @config {Buffer|String} [keyData] The key data. If supplied will be used instead of loading from disk. | ||
* @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple. | ||
* @config {String} [pfx] File path for private key, certificate and CA certs in PFX or PKCS12 format. If supplied will be used instead of certificate and key above | ||
* @config {Buffer|String} [pfxData] PFX or PKCS12 format data containing the private key, certificate and CA certs. If supplied will be used instead of loading from disk. | ||
* @config {String} [passphrase] The passphrase for the connection key, if required | ||
* @config {Buffer[]|String[]} [ca] An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. - You may need to use this as some environments don't include the CA used by Apple | ||
* @config {String} [address="feedback.push.apple.com"] The feedback server to connect to. | ||
* @config {Number} [port=2195] Feedback server port | ||
* @config {Function} [feedback] A callback which accepts 2 parameters (timestamp, {@link Device}). See: {@link <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3">Communicating with APS</a>. | ||
* @config {Function} [feedback] A callback which accepts 2 parameters (timestamp, {@link Device}) or an array of (timestamp, {@link Device}) object tuples, depending on the value of batchFeedback option. See: {@link <a href="https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3">Communicating with APS</a>. | ||
* @config {Boolean} [batchFeedback] If true, the feedback callback will only be called once per connection with an array of timestamp and device token tuples. | ||
* @config {Function} [errorCallback] Callback which will capture connection errors | ||
@@ -42,7 +45,11 @@ * @config {Number} [interval=3600] Interval to automatically connect to the Feedback service. | ||
keyData: null, /* Key data */ | ||
ca: null, /* Certificate Authority */ | ||
pfx: null, /* PFX File */ | ||
pfxData: null, /* PFX Data */ | ||
passphrase: null, /* Passphrase for key */ | ||
ca: null, /* Certificate Authority | ||
address: 'feedback.push.apple.com', /* feedback address */ | ||
port: 2196, /* feedback port */ | ||
rejectUnauthorized: true, /* Set this to false incase using a local proxy, reject otherwise */ | ||
feedback: false, /* enable feedback service, set to callback */ | ||
batchFeedback: false, /* If the feedback callback should only be called once per connection. */ | ||
errorCallback: false, /* error handler to catch connection exceptions */ | ||
@@ -56,2 +63,3 @@ interval: 3600, /* interval in seconds to connect to feedback service */ | ||
this.keyData = null; | ||
this.pfxData = null; | ||
@@ -75,3 +83,3 @@ this.deferredInitialize = null; | ||
Feedback.prototype.checkInitialized = function () { | ||
if (this.keyData && this.certData) { | ||
if ((this.keyData && this.certData) || this.pfxData) { | ||
this.deferredInitialize.resolve(); | ||
@@ -92,30 +100,47 @@ } | ||
if (this.options.certData) { | ||
this.certData = this.options.certData; | ||
if (this.options.pfx != null || this.options.pfxData != null) { | ||
if (this.options.pfxData) { | ||
this.pfxData = this.options.pfxData; | ||
} | ||
else { | ||
fs.readFile(this.options.pfx, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.pfxData = data; | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
} | ||
else { | ||
fs.readFile(this.options.cert, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.certData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
if (this.options.certData) { | ||
this.certData = this.options.certData; | ||
} | ||
else { | ||
fs.readFile(this.options.cert, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.certData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
if (this.options.keyData) { | ||
this.keyData = this.options.keyData; | ||
} | ||
else { | ||
fs.readFile(this.options.key, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.keyData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
} | ||
if (this.options.keyData) { | ||
this.keyData = this.options.keyData; | ||
} | ||
else { | ||
fs.readFile(this.options.key, function (err, data) { | ||
if (err) { | ||
this.deferredInitialize.reject(err); | ||
return; | ||
} | ||
this.keyData = data.toString(); | ||
this.checkInitialized(); | ||
}.bind(this)); | ||
} | ||
this.checkInitialized(); | ||
@@ -139,6 +164,12 @@ return this.deferredInitialize.promise; | ||
socketOptions.key = this.keyData; | ||
socketOptions.cert = this.certData; | ||
if (this.pfxData != null) { | ||
socketOptions.pfx = this.pfxData; | ||
} | ||
else { | ||
socketOptions.key = this.keyData; | ||
socketOptions.cert = this.certData; | ||
socketOptions.ca = this.options.ca; | ||
} | ||
socketOptions.passphrase = this.options.passphrase; | ||
socketOptions.ca = this.options.ca; | ||
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized; | ||
@@ -150,7 +181,2 @@ this.socket = tls.connect( | ||
function () { | ||
if (!this.socket.authorized) { | ||
this.deferredConnection.reject(this.socket.authorizationError); | ||
this.deferredConnection = null; | ||
} | ||
debug("Connection established"); | ||
@@ -161,2 +187,3 @@ this.deferredConnection.resolve(); | ||
this.readBuffer = new Buffer(0); | ||
this.feedbackData = []; | ||
this.socket.on('data', this.receive.bind(this)); | ||
@@ -197,5 +224,9 @@ this.socket.on("error", this.destroyConnection.bind(this)); | ||
debug("Parsed device token: %s, timestamp: %d", token.toString("hex"), time); | ||
if (typeof this.options.feedback == 'function') { | ||
var device = new Device(token); | ||
if (!this.options.batchFeedback && | ||
typeof this.options.feedback == 'function') { | ||
debug("Calling feedback method for device"); | ||
this.options.feedback(time, new Device(token)); | ||
this.options.feedback(time, device); | ||
} else { | ||
this.feedbackData.push({ time: time, device: device }); | ||
} | ||
@@ -224,2 +255,9 @@ this.readBuffer = this.readBuffer.slice(6 + tokenLength); | ||
} | ||
if (this.options.batchFeedback && | ||
typeof this.options.feedback == 'function') { | ||
debug("Calling feedback method for a batch of devices"); | ||
this.options.feedback(this.feedbackData); | ||
this.feedbackData = []; | ||
} | ||
@@ -226,0 +264,0 @@ if(!this.deferredConnection.promise.isResolved()) { |
var extend = function(target) { | ||
Array.prototype.slice.call(arguments, 1).forEach(function(source) { | ||
for (key in source) { | ||
for (var key in source) { | ||
if (source[key] !== undefined) { | ||
@@ -5,0 +5,0 @@ target[key] = source[key]; |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -45,7 +45,12 @@ #node-apn | ||
ca: null, /* String or Buffer of CA data to use for the TLS connection */ | ||
pfx: null, /* File path for private key, certificate and CA certs in PFX or PKCS12 format. If supplied will be used instead of certificate and key above */ | ||
pfxData: null, /* PFX or PKCS12 format data containing the private key, certificate and CA certs. If supplied will be used instead of loading from disk. */ | ||
gateway: 'gateway.push.apple.com',/* gateway address */ | ||
port: 2195, /* gateway port */ | ||
rejectUnauthorized: true, /* Value of rejectUnauthorized property to be passed through to tls.connect() */ | ||
enhanced: true, /* enable enhanced format */ | ||
errorCallback: undefined, /* Callback when error occurs function(err,notification) */ | ||
cacheLength: 100 /* Number of notifications to cache for error purposes */ | ||
autoAdjustCache: true, /* Whether the cache should grow in response to messages being lost after errors. */ | ||
connectionTimeout: 0 /* The duration the socket should stay alive with no activity in milliseconds. 0 = Disabled. */ | ||
}; | ||
@@ -85,4 +90,6 @@ | ||
If the enhanced binary interface is enabled and an error occurs - as defined in Apple's documentation - when sending a message, then subsequent messages will be automatically resent* and the connection will be re-established. If an `errorCallback` is also specified in the connection options then it will be invoked with 2 arguments `(err, notification)` | ||
If the enhanced binary interface is enabled and an error occurs - as defined in Apple's documentation - when sending a message, then subsequent messages will be automatically resent* and the connection will be re-established. If an `errorCallback` is also specified in the connection options then it will be invoked with 2 arguments `(err, notification)`. Alternatively it is possible to specify an error callback function on a notification-by-notification basis by setting the ```.errorCallback``` property on the notification object to the callback function before sending. | ||
**\*N.B.:** As of v1.2.5 a new events system has been implemented to provide more feedback to the application on the state of the connection. At present the ```errorCallback``` is still called in the following cases in addition to the new event system. It is strongly recommended that you migrate your application to use the new event system as the existing overloading of the ```errorCallback``` method will be deprecated and removed in future versions. | ||
If a notification fails to be sent because a connection error occurs then the `errorCallback` will be called for each notification waiting for the connection which failed. In this case the first parameter will be an Error object instead of an error number. | ||
@@ -98,2 +105,24 @@ | ||
### Events emitted by the connection | ||
The following events have been introduced as of v1.2.5 to allow closer monitoring and information about the internal processes in node-apn. If the events are not useful to you they can all be safely ignored (with the exception of ```error``` which indicates a failure to load the security credentials) and no action needs to be taken on your part when events are emitted. The ```disconnected``` event, for instance, is provided for informational purposes, the library will automatically re-establish the connection as necessary. The events are emitted by the connection itself so you should use ```apnsConnection.on('error', errorHandler)``` to attach listeners. | ||
####Events (arguments): | ||
- ```error (error)```: emitted when an error occurs during initialisation of the module, usually due to a problem with the keys and certificates. | ||
- ```transmitted (notification)```: emitted when a notification has been sent to Apple - not a guarantee that it has been accepted by Apple, an error relating to it make occur later on. A notification may also be sent several times if an earlier notification caused an error requiring retransmission. | ||
- ```timeout```: emitted when the connectionTimeout option has been specified and no activity has occurred on a socket for a specified duration. The socket will be closed immediately after this event. | ||
- ```connected```: emitted when the connection to Apple is successfully established. No action is required as the connection is managed internally. | ||
- ```disconnected```: emitted when the connection to Apple has been closed, this could be for numerous reasons, for example an error has occurred or the connection has timed out. No action is required. | ||
- ```socketError (error)```: emitted when the connection socket experiences an error. This is useful for debugging but no action should be necessary. | ||
- ```transmissionError (error code, notification)```: emitted when a message has been received from Apple stating that a notification was invalid. If we still have the notification in cache it will be passed as the second argument, otherwise null. | ||
- ```cacheTooSmall (difference)```: emitted when Apple returns a notification as invalid but the notification has been expunged from the cache - usually due to high throughput. The parameter estimates how many notifications have been lost. You should experiment with increasing the cache size or enabling ```autoAdjustCache``` if you see this frequently. Note: With ```autoAdjustCache``` enabled this event will still be emitted when an adjustment is triggered. | ||
### Setting up the feedback service | ||
@@ -112,5 +141,8 @@ | ||
ca: null, /* Certificate authority data to pass to the TLS connection */ | ||
pfx: null, /* File path for private key, certificate and CA certs in PFX or PKCS12 format. If supplied will be used instead of certificate and key above */ | ||
pfxData: null, /* PFX or PKCS12 format data containing the private key, certificate and CA certs. If supplied will be used instead of loading from disk. */ | ||
address: 'feedback.push.apple.com', /* feedback address */ | ||
port: 2196, /* feedback port */ | ||
feedback: false, /* enable feedback service, set to callback */ | ||
batchFeedback: false, /* if feedback should be called once per connection. */ | ||
interval: 3600 /* interval in seconds to connect to feedback service */ | ||
@@ -138,5 +170,7 @@ }; | ||
It is also possible to supply a PFX package containing your certificate, key and any relevant CA certificates. The method to accomplish this is left as an exercise to the reader. | ||
## Debugging | ||
If you experience difficulties sending notifications or using the feedback service you can enable debug messages within the library by running your application with `DEBUG=apn` or `DEBUG=apnfb`. | ||
If you experience difficulties sending notifications or using the feedback service you can enable debug messages within the library by running your application with `DEBUG=apn` or `DEBUG=apnfb` set as an environment variable. | ||
@@ -149,3 +183,3 @@ You will need the `debug` module which can be installed with `npm install debug`. | ||
Contributors: [Ian Babrou][bobrik], [dgthistle][dgthistle], [Keith Larsen][keithnlarsen], [Mike P][mypark], [Greg Bergé][neoziro], [Asad ur Rehman][AsadR] | ||
Thanks to: [Ian Babrou][bobrik], [dgthistle][dgthistle], [Keith Larsen][keithnlarsen], [Mike P][mypark], [Greg Bergé][neoziro], [Asad ur Rehman][AsadR], [Nebojsa Sabovic][nsabovic], [Alberto Gimeno][gimenete], [Randall Tombaugh][rwtombaugh] | ||
@@ -182,2 +216,5 @@ ## License | ||
[AsadR]: https://github.com/AsadR | ||
[nsabovic]: https://github.com/nsabovic | ||
[gimenete]: https://github.com/gimenete | ||
[rwtombaugh]: https://github.com/rwtombaugh | ||
[q]: https://github.com/kriskowal/q | ||
@@ -187,2 +224,14 @@ | ||
1.2.5: | ||
* Introduced a new event model. The connection class is now an event emitter which will emit events on connection state changes. This should largely replace the existing, somewhat inadequate error handling in previous versions. Please see the section above for more details or the message on commit d0a1d17961 | ||
* Fixed a bug relating to rejecting unauthorized hosts | ||
* Added support for PFX files instead of separate Certificate and Key Files | ||
* Added a batched feedback feature which can callback with an array of all devices instead of calling the method for each device separately | ||
* Added support for error callbacks on a per notification basis. | ||
* Changed the socket behaviour to enable the TCP Nagle algorithm as recommended by Apple | ||
* Fixed lots of small bugs around connection handling which should make high volume applications more stable. Node should no longer crash completely on EPIPE errors. | ||
* Added connection socket timeout after a period of inactivity, configured by ```options.connectionTimeout```. The socket will then be re-established automatically if further notifications are sent. | ||
* Added cache autoadjustment. If ```options.autoAdjustCache = true``` and a notification error occurs after the notification is purged from the cache the library will attempt to increase the cache size to prevent it happening in future. | ||
1.2.4: | ||
@@ -189,0 +238,0 @@ |
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
Network access
Supply chain riskThis module accesses the network.
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
53454
930
322
3