Comparing version 1.2.6 to 1.3.0
@@ -9,2 +9,3 @@ var Errors = require('./errors'); | ||
var util = require('./util'); | ||
var Device = require('./device'); | ||
var events = require('events'); | ||
@@ -38,6 +39,9 @@ var debug = function() {}; | ||
* @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=100] Number of notifications to cache for error purposes (See Readme) | ||
* @config {Function} [errorCallback] A callback which accepts 2 parameters (err, notification). Use `transmissionError` event instead. | ||
* @config {Number} [cacheLength=100] Number of notifications to cache for error purposes (See doc/apn.markdown) | ||
* @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} [maxConnections=1] The maximum number of connections to create for sending messages. | ||
* @config {Number} [connectionTimeout=0] The duration the socket should stay alive with no activity in milliseconds. 0 = Disabled. | ||
* @config {Boolean} [buffersNotifications=true] Whether to buffer notifications and resend them after failure. | ||
* @config {Boolean} [fastMode=false] Whether to aggresively empty the notification buffer while connected. | ||
*/ | ||
@@ -61,23 +65,23 @@ function Connection (options) { | ||
enhanced: true, | ||
errorCallback: undefined, | ||
cacheLength: 100, | ||
autoAdjustCache: true, | ||
connectionTimeout: 0 | ||
maxConnections: 1, | ||
connectionTimeout: 0, | ||
buffersNotifications: true | ||
}; | ||
util.extend(this.options, options); | ||
this.certData = null; | ||
this.keyData = null; | ||
this.pfxData = null; | ||
this.deferredInitialize = null; | ||
this.deferredConnection = null; | ||
this.currentId = 0; | ||
this.cachedNotifications = []; | ||
this.sockets = []; | ||
this.notificationBuffer = []; | ||
events.EventEmitter.call(this); | ||
}; | ||
} | ||
@@ -103,7 +107,7 @@ sysu.inherits(Connection, events.EventEmitter); | ||
} | ||
debug("Initialising module"); | ||
this.deferredInitialize = q.defer(); | ||
if(this.options.pfx != null || this.options.pfxData != null) { | ||
if(this.options.pfx !== null || this.options.pfxData !== null) { | ||
if(this.options.pfxData) { | ||
@@ -137,3 +141,3 @@ this.pfxData = this.options.pfxData; | ||
} | ||
if (this.options.keyData) { | ||
@@ -153,3 +157,3 @@ this.keyData = this.options.keyData; | ||
} | ||
this.checkInitialized(); | ||
@@ -160,3 +164,3 @@ return this.deferredInitialize.promise; | ||
/** | ||
* You should never need to call this method, initialisation and connection is handled by {@link Connection#sendNotification} | ||
* You should never need to call this method, initialisation and connection is handled by {@link Connection#pushNotification} | ||
* @private | ||
@@ -168,3 +172,3 @@ */ | ||
} | ||
debug("Initialising connection"); | ||
@@ -174,3 +178,3 @@ this.deferredConnection = q.defer(); | ||
var socketOptions = {}; | ||
if(this.pfxData) { | ||
@@ -186,2 +190,5 @@ socketOptions.pfx = this.pfxData; | ||
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized; | ||
// We pass in our own Stream to delay connection until we have attached the | ||
// event listeners below. | ||
socketOptions.socket = new net.Stream(); | ||
@@ -195,18 +202,20 @@ | ||
debug("Connection established"); | ||
this.emit('connected'); | ||
this.emit('connected', this.sockets.length + 1); | ||
this.deferredConnection.resolve(); | ||
}.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.once("close", this.restartConnection.bind(this)); | ||
this.socket.on("error", this.errorOccurred.bind(this, this.socket)); | ||
this.socket.on("timeout", this.socketTimeout.bind(this, this.socket)); | ||
this.socket.on("data", this.handleTransmissionError.bind(this, this.socket)); | ||
this.socket.on("drain", this.socketDrained.bind(this, this.socket, true)); | ||
this.socket.on("clientError", this.errorOccurred.bind(this, this.socket)); | ||
this.socket.once("close", this.socketClosed.bind(this, this.socket)); | ||
this.socket.socket.connect(this.options['port'], this.options['gateway']); | ||
// The actual connection is delayed until after all the event listeners have | ||
// been attached. | ||
socketOptions.socket.connect(this.options['port'], this.options['gateway']); | ||
}.bind(this)).fail(function (error) { | ||
@@ -218,3 +227,3 @@ debug("Module initialisation error:", error); | ||
}.bind(this)); | ||
return this.deferredConnection.promise; | ||
@@ -226,6 +235,71 @@ }; | ||
*/ | ||
Connection.prototype.errorOccurred = function(err) { | ||
Connection.prototype.createConnection = function() { | ||
this.connect().then(function () { | ||
this.socket.currentId = 0; | ||
this.socket.cachedNotifications = []; | ||
this.deferredConnection = null; | ||
this.sockets.push(this.socket); | ||
this.socket = undefined; | ||
this.serviceBuffer(); | ||
}.bind(this)).fail(function (err) { | ||
this.deferredConnection = null; | ||
this.socket = undefined; | ||
this.serviceBuffer(); | ||
}.bind(this)); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Connection.prototype.initialisingConnection = function() { | ||
if(this.deferredConnection !== null) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Connection.prototype.serviceBuffer = function() { | ||
var socket = null; | ||
var repeat = false; | ||
if(this.options.fastMode) { | ||
repeat = true; | ||
} | ||
do { | ||
socket = null; | ||
if (this.notificationBuffer.length === 0) return; | ||
for (var i = this.sockets.length - 1; i >= 0; i--) { | ||
if(this.socketAvailable(this.sockets[i])) { | ||
socket = this.sockets[i]; | ||
break; | ||
} | ||
} | ||
if (socket !== null) { | ||
debug("Transmitting notification from buffer"); | ||
if(this.transmitNotification(socket, this.notificationBuffer.shift())) { | ||
this.socketDrained(socket, !repeat); | ||
} | ||
} | ||
else if (!this.initialisingConnection() && this.sockets.length < this.options.maxConnections) { | ||
this.createConnection(); | ||
repeat = false; | ||
} | ||
else { | ||
repeat = false; | ||
} | ||
} while(repeat); | ||
debug("%d left to send", this.notificationBuffer.length); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Connection.prototype.errorOccurred = function(socket, err) { | ||
debug("Socket error occurred", err); | ||
this.emit('socketError', err); | ||
if(!this.deferredConnection.promise.isResolved()) { | ||
if(this.deferredConnection && this.deferredConnection.promise.isPending()) { | ||
this.deferredConnection.reject(err); | ||
@@ -236,3 +310,3 @@ } | ||
} | ||
this.destroyConnection(); | ||
this.destroyConnection(socket); | ||
}; | ||
@@ -243,16 +317,33 @@ | ||
*/ | ||
Connection.prototype.socketDrained = function() { | ||
Connection.prototype.socketAvailable = function(socket) { | ||
if (!socket || !socket.writable || socket.busy) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Connection.prototype.socketDrained = function(socket, serviceBuffer) { | ||
debug("Socket drained"); | ||
socket.busy = false; | ||
if(this.options.enhanced) { | ||
var notification = this.cachedNotifications[this.cachedNotifications.length - 1]; | ||
this.emit('transmitted', notification); | ||
var notification = socket.cachedNotifications[socket.cachedNotifications.length - 1]; | ||
this.emit('transmitted', notification.notification, notification.recipient); | ||
} | ||
if (this.socket && (this.socket.socket.bufferSize != 0 || !this.socket.writable)) { | ||
return; | ||
if(serviceBuffer === true && !this.runningOnNextTick) { | ||
// There is a possibility that this could add multiple invocations to the | ||
// call stack unnecessarily. It will be resolved within one event loop but | ||
// should be mitigated if possible, this.nextTick aims to solve this, | ||
// ensuring "serviceBuffer" is only called once per loop. | ||
var nextRun = function() { this.runningOnNextTick = false; this.serviceBuffer(); }.bind(this); | ||
if('function' === typeof setImmediate) { | ||
setImmediate(nextRun); | ||
} | ||
else { | ||
process.nextTick(nextRun); | ||
} | ||
this.runningOnNextTick = true; | ||
} | ||
debug("Socket writeable"); | ||
if (this.notificationBuffer.length > 0) { | ||
debug("Sending notification from buffer"); | ||
this.sendNotification(this.notificationBuffer.shift()); | ||
} | ||
}; | ||
@@ -263,6 +354,6 @@ | ||
*/ | ||
Connection.prototype.socketTimeout = function() { | ||
debug("Socket timeout"); | ||
this.emit('timeout'); | ||
this.socket.end(); | ||
Connection.prototype.socketTimeout = function(socket) { | ||
debug("Socket timeout"); | ||
this.emit('timeout'); | ||
socket.end(); | ||
}; | ||
@@ -273,6 +364,6 @@ | ||
*/ | ||
Connection.prototype.destroyConnection = function() { | ||
Connection.prototype.destroyConnection = function(socket) { | ||
debug("Destroying connection"); | ||
if (this.socket) { | ||
this.socket.destroy(); | ||
if (socket) { | ||
socket.destroy(); | ||
} | ||
@@ -284,22 +375,19 @@ }; | ||
*/ | ||
Connection.prototype.restartConnection = function() { | ||
debug("Restarting connection"); | ||
if (this.socket) { | ||
this.socket.removeAllListeners(); | ||
} | ||
if(!this.deferredConnection.promise.isResolved()) { | ||
Connection.prototype.socketClosed = function(socket) { | ||
debug("Socket closed"); | ||
if (socket === this.socket && !this.deferredConnection.promise.isPending()) { | ||
debug("Connection error occurred before TLS Handshake"); | ||
this.deferredConnection.reject(new Error("Unable to connect")); | ||
} | ||
else { | ||
var index = this.sockets.indexOf(socket); | ||
if (index > -1) { | ||
this.sockets.splice(index, 1); | ||
} | ||
this.emit('disconnected'); | ||
this.socket = undefined; | ||
this.deferredConnection = undefined; | ||
if (this.notificationBuffer.length) { | ||
debug("Notification queue has %d items, resending the first", this.notificationBuffer.length); | ||
this.sendNotification(this.notificationBuffer.shift()); | ||
this.emit('disconnected', this.sockets.length); | ||
} | ||
this.serviceBuffer(); | ||
}; | ||
@@ -317,7 +405,7 @@ | ||
*/ | ||
Connection.prototype.cacheNotification = function (notification) { | ||
this.cachedNotifications.push(notification); | ||
if (this.cachedNotifications.length > this.options.cacheLength) { | ||
debug("Clearing notification %d from the cache", this.cachedNotifications[0]['_uid']); | ||
this.cachedNotifications.shift(); | ||
Connection.prototype.cacheNotification = function (socket, notification) { | ||
socket.cachedNotifications.push(notification); | ||
if (socket.cachedNotifications.length > this.options.cacheLength) { | ||
debug("Clearing notification %d from the cache", socket.cachedNotifications[0]['_uid']); | ||
socket.cachedNotifications.shift(); | ||
} | ||
@@ -329,3 +417,4 @@ }; | ||
*/ | ||
Connection.prototype.handleTransmissionError = function (data) { | ||
Connection.prototype.handleTransmissionError = function (socket, data) { | ||
socket.destroy(); | ||
if (data[0] == 8) { | ||
@@ -335,13 +424,13 @@ if (!this.options.enhanced) { | ||
} | ||
var errorCode = data[1]; | ||
var identifier = data.readUInt32BE(2); | ||
var notification = undefined; | ||
var notification = null; | ||
var foundNotification = false; | ||
var temporaryCache = []; | ||
debug("Notification %d caused an error: %d", identifier, errorCode); | ||
while (this.cachedNotifications.length) { | ||
notification = this.cachedNotifications.shift(); | ||
while (socket.cachedNotifications.length) { | ||
notification = socket.cachedNotifications.shift(); | ||
if (notification['_uid'] == identifier) { | ||
@@ -353,3 +442,3 @@ foundNotification = true; | ||
} | ||
if (foundNotification) { | ||
@@ -359,10 +448,10 @@ while (temporaryCache.length) { | ||
} | ||
this.emit('transmissionError', errorCode, notification); | ||
this.raiseError(errorCode, notification); | ||
this.emit('transmissionError', errorCode, notification.notification, notification.recipient); | ||
this.raiseError(errorCode, notification.notification, notification.recipient); | ||
} | ||
else { | ||
this.cachedNotifications = temporaryCache; | ||
socket.cachedNotifications = temporaryCache; | ||
if(this.cachedNotifications.length > 0) { | ||
var differentialSize = this.cachedNotifications[0]['_uid'] - notification['_uid'] | ||
if(socket.cachedNotifications.length > 0) { | ||
var differentialSize = socket.cachedNotifications[0]['_uid'] - identifier; | ||
this.emit('cacheTooSmall', differentialSize); | ||
@@ -374,11 +463,13 @@ if(this.options.autoAdjustCache) { | ||
this.emit('transmissionError', Errors["none"], null); | ||
this.emit('transmissionError', errorCode, null); | ||
this.raiseError(errorCode, null); | ||
} | ||
var count = this.cachedNotifications.length; | ||
debug("Buffering %d notifications", count); | ||
for (var i = 0; i < count; ++i) { | ||
notification = this.cachedNotifications.shift(); | ||
this.bufferNotification(notification); | ||
var count = socket.cachedNotifications.length; | ||
if(this.options.buffersNotifications) { | ||
debug("Buffering %d notifications for resending", count); | ||
for (var i = 0; i < count; ++i) { | ||
notification = socket.cachedNotifications.shift(); | ||
this.bufferNotification(notification); | ||
} | ||
} | ||
@@ -391,4 +482,4 @@ } | ||
*/ | ||
Connection.prototype.raiseError = function(errorCode, notification) { | ||
debug("Raising error:", errorCode, notification); | ||
Connection.prototype.raiseError = function(errorCode, notification, recipient) { | ||
debug("Raising error:", errorCode, notification, recipient); | ||
@@ -400,5 +491,5 @@ if(errorCode instanceof Error) { | ||
if (notification && typeof notification.errorCallback == 'function' ) { | ||
notification.errorCallback(errorCode); | ||
notification.errorCallback(errorCode, recipient); | ||
} else if (typeof this.options.errorCallback == 'function') { | ||
this.options.errorCallback(errorCode, notification); | ||
this.options.errorCallback(errorCode, notification, recipient); | ||
} | ||
@@ -408,10 +499,14 @@ }; | ||
/** | ||
* Send a notification to the APN service | ||
* @param {Notification} notification The notification object to be sent | ||
* @private | ||
* @return {Boolean} Write completed, returns true if socketDrained should be called by the caller of this method. | ||
*/ | ||
Connection.prototype.sendNotification = function (notification) { | ||
var token = notification.device.token; | ||
var encoding = notification.encoding || 'utf8'; | ||
var message = JSON.stringify(notification); | ||
Connection.prototype.transmitNotification = function(socket, notification) { | ||
if (!this.socketAvailable(socket)) { | ||
this.bufferNotification(notification); | ||
return; | ||
} | ||
var token = notification.recipient.token | ||
var encoding = notification.notification.encoding || 'utf8'; | ||
var message = notification.notification.compile(); | ||
var messageLength = Buffer.byteLength(message, encoding); | ||
@@ -421,71 +516,103 @@ var position = 0; | ||
if (token === undefined) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['missingDeviceToken'], notification); | ||
}.bind(this)); | ||
return Errors['missingDeviceToken']; | ||
notification._uid = socket.currentId++; | ||
if (socket.currentId > 0xffffffff) { | ||
socket.currentId = 0; | ||
} | ||
if (messageLength > 255) { | ||
if (this.options.enhanced) { | ||
data = new Buffer(1 + 4 + 4 + 2 + token.length + 2 + messageLength); | ||
// Command | ||
data[position] = 1; | ||
position++; | ||
// Identifier | ||
data.writeUInt32BE(notification._uid, position); | ||
position += 4; | ||
// Expiry | ||
data.writeUInt32BE(notification.notification.expiry, position); | ||
position += 4; | ||
this.cacheNotification(socket, notification); | ||
} | ||
else { | ||
data = new Buffer(1 + 2 + token.length + 2 + messageLength); | ||
//Command | ||
data[position] = 0; | ||
position++; | ||
} | ||
// Token Length | ||
data.writeUInt16BE(token.length, position); | ||
position += 2; | ||
// Device Token | ||
position += token.copy(data, position, 0); | ||
// Payload Length | ||
data.writeUInt16BE(messageLength, position); | ||
position += 2; | ||
//Payload | ||
position += data.write(message, position, encoding); | ||
socket.busy = true; | ||
return socket.write(data); | ||
}; | ||
Connection.prototype.validNotification = function (notification, recipient) { | ||
var encoding = notification.encoding || 'utf8'; | ||
var message = notification.compile(); | ||
var messageLength = Buffer.byteLength(message, encoding); | ||
if (messageLength > 256) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['invalidPayloadSize'], notification); | ||
this.raiseError(Errors['invalidPayloadSize'], notification, recipient); | ||
this.emit('transmissionError', Errors['invalidPayloadSize'], notification, recipient); | ||
}.bind(this)); | ||
return Errors['invalidPayloadSize']; | ||
return false; | ||
} | ||
return true; | ||
}; | ||
this.connect().then(function() { | ||
debug("Sending notification"); | ||
if (!this.socket || this.socket.socket.bufferSize !== 0 || !this.socket.writable) { | ||
this.bufferNotification(notification); | ||
return; | ||
/** | ||
* Queue a notification for delivery to recipients | ||
* @param {Notification} notification The Notification object to be sent | ||
* @param {Device|String|Buffer|Device[]|String[]|Buffer[]} recipient The token(s) for devices the notification should be delivered to. | ||
* @since v1.3.0 | ||
*/ | ||
Connection.prototype.pushNotification = function (notification, recipient) { | ||
if (!this.validNotification(notification, recipient)) { | ||
return; | ||
} | ||
if (sysu.isArray(recipient)) { | ||
for (var i = recipient.length - 1; i >= 0; i--) { | ||
var device = recipient[i]; | ||
if (!(device instanceof Device)) { | ||
device = new Device(device); | ||
} | ||
this.bufferNotification({ "notification": notification, "recipient": device }); | ||
} | ||
notification._uid = this.currentId++; | ||
if (this.currentId > 0xffffffff) { | ||
this.currentId = 0; | ||
} | ||
else { | ||
if (recipient === undefined) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['missingDeviceToken'], notification); | ||
this.emit('transmissionError', Errors['missingDeviceToken'], notification); | ||
}.bind(this)); | ||
return Errors['missingDeviceToken']; | ||
} | ||
if (this.options.enhanced) { | ||
data = new Buffer(1 + 4 + 4 + 2 + token.length + 2 + messageLength); | ||
// Command | ||
data[position] = 1; | ||
position++; | ||
// Identifier | ||
data.writeUInt32BE(notification._uid, position); | ||
position += 4; | ||
// Expiry | ||
data.writeUInt32BE(notification.expiry, position); | ||
position += 4; | ||
this.cacheNotification(notification); | ||
var device = recipient; | ||
if (!(device instanceof Device)) { | ||
device = new Device(device); | ||
} | ||
else { | ||
data = new Buffer(1 + 2 + token.length + 2 + messageLength); | ||
//Command | ||
data[position] = 0; | ||
position++; | ||
} | ||
// Token Length | ||
data.writeUInt16BE(token.length, position); | ||
position += 2; | ||
// Device Token | ||
position += token.copy(data, position, 0); | ||
// Payload Length | ||
data.writeUInt16BE(messageLength, position); | ||
position += 2; | ||
//Payload | ||
position += data.write(message, position, encoding); | ||
this.bufferNotification({"notification":notification, "recipient":device }); | ||
} | ||
if(this.socket.write(data)) { | ||
this.socketDrained(); | ||
} | ||
}.bind(this)).fail(function (error) { | ||
this.bufferNotification(notification); | ||
this.raiseError(error, notification); | ||
}.bind(this)); | ||
this.serviceBuffer(); | ||
}; | ||
return 0; | ||
/** | ||
* Send a notification to the APN service | ||
* @param {Notification} notification The notification object to be sent | ||
* @deprecated Since v1.3.0, use pushNotification instead | ||
*/ | ||
Connection.prototype.sendNotification = function (notification) { | ||
return this.pushNotification(notification, notification.device); | ||
}; | ||
module.exports = Connection; |
@@ -7,7 +7,15 @@ /** | ||
function Device(deviceToken) { | ||
if (!(this instanceof Device)) { | ||
return new Device(deviceToken); | ||
} | ||
if(typeof deviceToken == "string") { | ||
this.token = new Buffer(deviceToken.replace(/\s/g, ""), "hex"); | ||
this.token = new Buffer(deviceToken.replace(/[^0-9a-f]/gi, ""), "hex"); | ||
} | ||
else if(Buffer.isBuffer(deviceToken)) { | ||
this.token = new Buffer(deviceToken.length); | ||
deviceToken.copy(this.token); | ||
} | ||
else { | ||
this.token = deviceToken; | ||
return null; | ||
} | ||
@@ -22,4 +30,4 @@ }; | ||
return this.token.toString("hex"); | ||
} | ||
}; | ||
module.exports = Device; |
@@ -7,3 +7,5 @@ var Device = require('./device'); | ||
var tls = require('tls'); | ||
var sysu = require('util'); | ||
var util = require('./util'); | ||
var events = require('events'); | ||
var debug = function() {}; | ||
@@ -33,5 +35,5 @@ if(process.env.DEBUG) { | ||
* @config {Number} [port=2195] Feedback server port | ||
* @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 | ||
* @config {Function} [feedback] Deprecated ** 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=true] If true, the feedback callback will only be called once per connection with an array of timestamp and device token tuples. | ||
* @config {Function} [errorCallback] Deprecated ** Callback which will capture connection errors | ||
* @config {Number} [interval=3600] Interval to automatically connect to the Feedback service. | ||
@@ -52,28 +54,39 @@ */ | ||
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. */ | ||
rejectUnauthorized: true, /* Set this to false incase using a local proxy, reject otherwise */ | ||
feedback: false, /* **Deprecated**: Use `feedback` event instead, enable feedback service, set to callback */ | ||
batchFeedback: true, /* If the feedback callback should only be called once per connection. */ | ||
errorCallback: false, /* error handler to catch connection exceptions */ | ||
interval: 3600, /* interval in seconds to connect to feedback service */ | ||
interval: 3600 /* interval in seconds to connect to feedback service */ | ||
}; | ||
util.extend(this.options, options); | ||
this.certData = null; | ||
this.keyData = null; | ||
this.pfxData = null; | ||
this.deferredInitialize = null; | ||
this.deferredConnection = null; | ||
this.readBuffer = null; | ||
this.interval = null; | ||
events.EventEmitter.call(this); | ||
if (typeof this.options.errorCallback == 'function') { | ||
this.on('error', this.options.errorCallback); | ||
} | ||
if (typeof this.options.feedback != 'function') { | ||
throw new Error(-1, 'A callback function must be specified'); | ||
} | ||
else { | ||
this.on('feedback', this.options.feedback); | ||
} | ||
this.start(); | ||
}; | ||
} | ||
sysu.inherits(Feedback, events.EventEmitter); | ||
/** | ||
@@ -95,7 +108,7 @@ * @private | ||
} | ||
debug("Initialising module"); | ||
this.deferredInitialize = q.defer(); | ||
if (this.options.pfx != null || this.options.pfxData != null) { | ||
if (this.options.pfx !== null || this.options.pfxData !== null) { | ||
if (this.options.pfxData) { | ||
@@ -129,3 +142,3 @@ this.pfxData = this.options.pfxData; | ||
} | ||
if (this.options.keyData) { | ||
@@ -145,3 +158,3 @@ this.keyData = this.options.keyData; | ||
} | ||
this.checkInitialized(); | ||
@@ -159,3 +172,3 @@ return this.deferredInitialize.promise; | ||
} | ||
debug("Initialising connection"); | ||
@@ -165,4 +178,4 @@ this.deferredConnection = q.defer(); | ||
var socketOptions = {}; | ||
if (this.pfxData != null) { | ||
if (this.pfxData !== null) { | ||
socketOptions.pfx = this.pfxData; | ||
@@ -177,3 +190,3 @@ } | ||
socketOptions.rejectUnauthorized = this.options.rejectUnauthorized; | ||
this.socket = tls.connect( | ||
@@ -187,3 +200,3 @@ this.options['port'], | ||
}.bind(this)); | ||
this.readBuffer = new Buffer(0); | ||
@@ -199,3 +212,3 @@ this.feedbackData = []; | ||
}.bind(this)); | ||
return this.deferredConnection.promise; | ||
@@ -225,9 +238,8 @@ }; | ||
this.readBuffer.copy(token, 0, 6, 6 + tokenLength); | ||
debug("Parsed device token: %s, timestamp: %d", token.toString("hex"), time); | ||
var device = new Device(token); | ||
if (!this.options.batchFeedback && | ||
typeof this.options.feedback == 'function') { | ||
debug("Calling feedback method for device"); | ||
this.options.feedback(time, device); | ||
if (!this.options.batchFeedback) { | ||
debug("Emitting feedback event"); | ||
this.emit('feedback', time, device); | ||
} else { | ||
@@ -238,3 +250,3 @@ this.feedbackData.push({ time: time, device: device }); | ||
} | ||
} | ||
}; | ||
@@ -244,4 +256,7 @@ /** | ||
*/ | ||
Feedback.prototype.destroyConnection = function () { | ||
Feedback.prototype.destroyConnection = function (err) { | ||
debug("Destroying connection"); | ||
if(err) { | ||
this.emit('error', err); | ||
} | ||
if (this.socket) { | ||
@@ -257,18 +272,14 @@ this.socket.destroySoon(); | ||
debug("Resetting connection"); | ||
if (this.socket) { | ||
this.socket.removeAllListeners(); | ||
if (this.options.batchFeedback && this.feedbackData.length > 0) { | ||
debug("Emitting all feedback tokens"); | ||
this.emit('feedback', this.feedbackData); | ||
this.feedbackData = []; | ||
} | ||
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 = []; | ||
} | ||
if(!this.deferredConnection.promise.isResolved()) { | ||
if(this.deferredConnection.promise.isPending()) { | ||
debug("Connection error occurred before TLS Handshake"); | ||
this.deferredConnection.reject(new Error("Unable to connect")); | ||
} | ||
this.socket = null; | ||
@@ -297,5 +308,3 @@ this.deferredConnection = null; | ||
this.connect().fail(function (error) { | ||
if(typeof this.options.errorCallback == "function") { | ||
this.options.errorCallback(error); | ||
} | ||
this.emit('error', error); | ||
}.bind(this)); | ||
@@ -302,0 +311,0 @@ }; |
@@ -5,10 +5,12 @@ /** | ||
*/ | ||
function Notification () { | ||
function Notification (payload) { | ||
this.encoding = 'utf8'; | ||
this.payload = {}; | ||
this.payload = payload || {}; | ||
this.expiry = 0; | ||
this.identifier = 0; | ||
this.device; | ||
/** @deprecated since v1.3.0 used connection#pushNotification instead which accepts device token separately **/ | ||
this.device = undefined; | ||
this.alert = undefined; | ||
@@ -19,2 +21,6 @@ this.badge = undefined; | ||
this.newsstandAvailable = undefined; | ||
this.mdm = undefined; | ||
this.compiled = false; | ||
}; | ||
@@ -27,2 +33,3 @@ | ||
* @since v1.2.0 | ||
* @deprecated Since v1.3.0, notifications are not tied to a device so do not need cloning. | ||
*/ | ||
@@ -44,4 +51,4 @@ Notification.prototype.clone = function (device) { | ||
return notification | ||
} | ||
return notification; | ||
}; | ||
@@ -62,3 +69,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -74,3 +81,3 @@ /** | ||
this.alert['action-loc-key'] = key; | ||
} | ||
}; | ||
@@ -87,6 +94,6 @@ /** | ||
delete this.alert["loc-key"]; | ||
return | ||
return; | ||
} | ||
this.alert['loc-key'] = key; | ||
} | ||
}; | ||
@@ -103,6 +110,6 @@ /** | ||
delete this.alert["loc-args"]; | ||
return | ||
return; | ||
} | ||
this.alert['loc-args'] = args; | ||
} | ||
}; | ||
@@ -119,6 +126,6 @@ /** | ||
delete this.alert["launch-image"]; | ||
return | ||
return; | ||
} | ||
this.alert["launch-image"] = image; | ||
} | ||
}; | ||
@@ -139,7 +146,6 @@ | ||
} | ||
} | ||
}; | ||
/** | ||
* @returns {Number} Byte length of the notification payload | ||
* @private | ||
* @since v1.2.0 | ||
@@ -149,3 +155,3 @@ */ | ||
return Buffer.byteLength(JSON.stringify(this), this.encoding || 'utf8'); | ||
} | ||
}; | ||
@@ -162,2 +168,3 @@ /** | ||
} | ||
var length; | ||
if(typeof this.alert == "string") { | ||
@@ -168,3 +175,3 @@ var length = Buffer.byteLength(this.alert, this.encoding || 'utf8'); | ||
} | ||
this.alert = this.alert.substring(0, length - tooLong); | ||
this.alert = this.truncateStringToBytes(this.alert, length - tooLong); | ||
return tooLong; | ||
@@ -177,6 +184,33 @@ } | ||
} | ||
this.alert.body = this.alert.body.substring(0, length - tooLong); | ||
this.alert.body = this.truncateStringToBytes(this.alert.body, length - tooLong); | ||
return tooLong; | ||
} | ||
return -tooLong; | ||
}; | ||
/** | ||
* Compile a notification down to its JSON format. Compilation is final, changes made to the notification after this method is called will not be reflected in further calls. | ||
* @returns {String} JSON payload for the notification. | ||
* @since v1.3.0 | ||
*/ | ||
Notification.prototype.compile = function () { | ||
if(this.compiled) { | ||
return this.compiledPayload; | ||
} | ||
this.compiledPayload = JSON.stringify(this); | ||
this.compiled = true; | ||
return this.compiledPayload; | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Notification.prototype.truncateStringToBytes = function(string, bytes) { | ||
var truncated = string.substring(0, bytes); | ||
while (Buffer.byteLength(truncated, this.encoding || 'utf8') > bytes) { | ||
truncated = truncated.substring(0, truncated.length - 1); | ||
} | ||
return truncated; | ||
} | ||
@@ -183,0 +217,0 @@ |
@@ -9,4 +9,4 @@ var extend = function(target) { | ||
}); | ||
} | ||
}; | ||
module.exports.extend = extend; |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.2.6", | ||
"version": "1.3.0", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -9,3 +9,3 @@ "contributors": [ | ||
], | ||
"keywords": ["apple", "push", "push notifications", "iOS", "apns"], | ||
"keywords": ["apple", "push", "push notifications", "iOS", "apns", "notifications"], | ||
"main": "index.js", | ||
@@ -21,3 +21,3 @@ "bugs": { | ||
"dependencies": { | ||
"q": "0.8.x" | ||
"q": "0.9.x" | ||
}, | ||
@@ -24,0 +24,0 @@ "engines": { "node": ">= 0.6.6" }, |
249
README.md
@@ -7,6 +7,8 @@ #node-apn | ||
- Maintains a connection to the server to maximise notification batching | ||
- Enhanced binary interface support with error handling | ||
- Fast | ||
- Maintains a connection to the server to maximise notification batching and throughput. | ||
- Enhanced binary interface support, with error handling | ||
- Automatically sends unsent notifications if an error occurs | ||
- Feedback service support | ||
- Complies with all best practises laid out by Apple | ||
@@ -24,6 +26,9 @@ ## Installation | ||
## Usage | ||
## Quick Start | ||
This is intended as a brief introduction, please refer to the documentation in `doc/` for more details. | ||
### Load in the module | ||
var apns = require('apn'); | ||
var apn = require('apn'); | ||
@@ -38,24 +43,9 @@ ### Exported Objects | ||
### Connecting | ||
Create a new connection to the gateway server using a dictionary of options. The defaults are listed below: | ||
Create a new connection to the APN gateway server using a dictionary of options. If you name your certificate and key files appropriately (`cert.pem` and `key.pem`) then the defaults should be suitable to get you up and running, the only thing you'll need to change is the `gateway` if you're in the sandbox environment. | ||
var options = { | ||
cert: 'cert.pem', /* Certificate file path */ | ||
certData: null, /* String or Buffer containing certificate data, if supplied uses this instead of cert file path */ | ||
key: 'key.pem', /* Key file path */ | ||
keyData: null, /* String or Buffer containing key data, as certData */ | ||
passphrase: null, /* A passphrase for the Key file */ | ||
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. */ | ||
}; | ||
```javascript | ||
var options = { "gateway": "gateway.sandbox.push.apple.com" }; | ||
var apnsConnection = new apns.Connection(options); | ||
var apnConnection = new apn.Connection(options); | ||
``` | ||
@@ -67,7 +57,7 @@ **Important:** In a development environment you must set `gateway` to `gateway.sandbox.push.apple.com`. | ||
var myDevice = new apns.Device(token); | ||
var myDevice = new apn.Device(token); | ||
Next, create a notification object and set parameters. See the [payload documentation][pl] for more details. | ||
var note = new apns.Notification(); | ||
var note = new apn.Notification(); | ||
@@ -79,8 +69,7 @@ note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now. | ||
note.payload = {'messageFrom': 'Caroline'}; | ||
note.device = myDevice; | ||
apnsConnection.sendNotification(note); | ||
apnConnection.pushNotification(note, myDevice); | ||
As of version 1.2.0 it is also possible to use a set of methods provided by Notification object (`setAlertText`, `setActionLocKey`, `setLocKey`, `setLocArgs`, `setLaunchImage`) to aid the creation of the alert parameters. For applications which provide Newsstand capability there is a new boolean parameter `note.newsstandAvailable` to specify `content-available` in the payload. | ||
The above options will compile the following dictionary to send to the device: | ||
@@ -90,42 +79,4 @@ | ||
**\*N.B.:** If you wish to send notifications containing emoji or other multi-byte characters you will need to set `note.encoding = 'ucs2'`. This tells node to send the message with 16bit characters, however it also means your message payload will be limited to 127 characters. | ||
### Handling Errors | ||
**\*N.B.:** If you wish to send notifications containing emoji or other multi-byte characters you will need to set `note.encoding = 'ucs2'`. This tells node to send the message with 16bit characters, however it also means your message payload will be limited to 128 characters. | ||
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. | ||
`errorCallback` will be called in 3 situations with the parameters shown. | ||
1. The notification has been rejected by Apple (or determined to have an invalid device token or payload before sending) for one of the reasons shown in Table 5-1 [here][errors] `errorCallback(errorCode, notification)` | ||
1. A notification has been rejected by Apple but it has been removed from the cache so it is not possible to identify which. In this case subsequent notifications may be lost. **If this happens you should consider increasing your `cacheLength` value to prevent data loss** `errorCallback(255, null)` | ||
1. A connection error has occurred before the notification can be sent. `errorCallback(Error object, notification)` | ||
**\*N.B.:** The `cacheLength` option for the connection specifies the number of sent notifications which will be cached, on a FIFO basis for error handling purposes. If `cacheLength` is not set to a large enough value, then in high volume environments, a notification - possibly including some subsequent notifications - may be removed from the cache before Apple returns an error associated with it. In this case the `errorCallback` will still be called, but with a `null` notification and error code 255. If this happens you should consider increasing `cacheLength` to prevent losing notifications. All the notifications still residing in the cache will be resent automatically. | ||
### 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 | ||
@@ -135,23 +86,19 @@ | ||
Using the `Feedback` object it is possible to periodically query the server for the list. You should provide a function `feedback` which will accept two arguments, the `time` returned by the server (epoch time) and a `Buffer` object containing the device token. You can also set the query interval in seconds. The default options are shown below. | ||
Using the `Feedback` object it is possible to periodically query the server for the list. Many of the options are similar to that of `Connection`. | ||
Attach a listener to the `feedback` event to receive the output as two arguments, the `time` returned by the server (epoch time) and a `Buffer` object containing the device token - this event will be emitted for each device separately. Alternatively you can enable the `batchFeedback` option and the `feedback` event will provide an array of objects containing `time` and `device` properties. | ||
var options = { | ||
cert: 'cert.pem', /* Certificate file */ | ||
certData: null, /* Certificate file contents (String|Buffer) */ | ||
key: 'key.pem', /* Key file */ | ||
keyData: null, /* Key file contents (String|Buffer) */ | ||
passphrase: null, /* A passphrase for the Key file */ | ||
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 */ | ||
"batchFeedback": true, | ||
"interval": 300 | ||
}; | ||
var feedback = new apns.Feedback(options); | ||
var feedback = new apn.Feedback(options); | ||
feedback.on("feedback", function(devices) { | ||
devices.forEach(function(item) { | ||
// Do something with item.device and item.time; | ||
}); | ||
}); | ||
This will automatically start a timer to check with Apple every `interval` seconds. You can cancel the interval by calling `feedback.cancel()`. If you do not wish to have the service automatically queried then set `interval` to 0 and use `feedback.start()`. | ||
By specifying a time interval (in seconds) `Feedback` will periodically query the service without further intervention. | ||
@@ -173,3 +120,3 @@ **Important:** In a development environment you must set `address` to `feedback.sandbox.push.apple.com`. | ||
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. | ||
It is also possible to supply a PFX (PFX/PKCS12) package containing your certificate, key and any relevant CA certificates. The method to accomplish this is left as an exercise to the reader. It should be possible to select the relevant items in "Keychain Access" and use the export option with ".p12" format. | ||
@@ -182,2 +129,12 @@ ## Debugging | ||
You are encouraged to read the extremely informative [Troubleshooting Push Notifications][tn2265] Tech Note in the first instance, in case your query is answered there. | ||
If you experience any difficulties please create an Issue on GitHub and if possible include a log of the debug output around the time the problem manifests itself. If the problem is reproducible sample code is also extremely helpful. | ||
## Resources | ||
* [Local and Push Notification Programming Guide: Apple Push Notification Service][pl] | ||
* [Apple Technical Note: Troubleshooting Push Notifications][tn2265] | ||
* [List of Projects, Applications and Companies Using Node-apn][pacapn] | ||
## Credits | ||
@@ -209,6 +166,8 @@ | ||
[pl]: https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW1 "Local and Push Notification Programming Guide: Apple Push Notification Service" | ||
[fs]:https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3 "Communicating With APS" | ||
[fs]: https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW3 "Communicating With APS" | ||
[tn2265]: http://developer.apple.com/library/ios/#technotes/tn2265/_index.html "Troubleshooting Push Notifications" | ||
[pacapn]:https://github.com/argon/node-apn/wiki/Projects,-Applications,-and-Companies-Using-Node-apn "List of Projects, Applications and Companies Using Node-apn" | ||
[andrewnaylor]: http://andrewnaylor.co.uk | ||
[bnoordhuis]: http://bnoordhuis.nl | ||
[npm]: https://github.com/isaacs/npm | ||
[npm]: https://npmjs.org | ||
[bobrik]: http://bobrik.name | ||
@@ -225,118 +184,4 @@ [dgthistle]: https://github.com/dgthistle | ||
[mgcrea]: https://github.com/mgcrea | ||
[porsager]: https://porsager | ||
[porsager]: https://github.com/porsager | ||
[q]: https://github.com/kriskowal/q | ||
## Changelog | ||
1.2.6: | ||
* Added mdm support. | ||
* Constrained 'q' module to 0.8.x because 0.9.0 is API incompatible. | ||
* Fixed a `trim()` bug when compiling notification. | ||
* ***NOTICE:*** v1.3.0 which will be released soon will break some API compatibility with error handling and there will be a new sending API (the legacy sending API will remain) | ||
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: | ||
* Fixed some typos in the feedback methods | ||
* Added some debug messages available during development, see debug section above. | ||
1.2.3: | ||
* Added some more error handling to the connection methods. | ||
* Fixed a problem where an error handler was not bound to the correct context and wouldn't fire. | ||
1.2.2: | ||
* Fixes issue #47, Syntax Error in feedback.js | ||
1.2.1: | ||
* Earlier versions had some incorrect logic in the handling of reconnection. This should be fixed now | ||
* Issue #46 ```.clone()``` did not set the badge property correctly. | ||
1.2.0: | ||
* Complete rewrite of the connection handling. | ||
* [q][q] is now required. | ||
* Change in the error handling logic. When a notification errors and it cannot be found in the cache, then all notifications in the cache will be resent instead of being discarded. | ||
* `errorCallback` will also be invoked for connection errors. | ||
* New methods on `Notification` to aid settings the alert properties. | ||
* `content-available` can now be set for Newsstand applications by setting the `newsstandAvailable` property on the Notification object. | ||
* `Notification` objects now have a `.clone(device)` method to assist you in sending the same notification to multiple devices. | ||
* Included some js-doc tags in the source. | ||
* Device object now provides a `.toString()` method to return the hex representation of the device token. | ||
* Fixes #23, #28, #32, #34, #35, #40, #42 | ||
1.1.7: | ||
* Fixes a problem with sockets being closed on transmission error causing EPIPE errors in node. | ||
* Issues #29, #30 | ||
1.1.6: | ||
* Fixes a regression from v1.1.5 causing connections to stall and messages to not be sent. | ||
1.1.5: | ||
* Feature: Certificate and Key data can be passed directly when creating a new connection instead of providing a file name on disk. (See: `certData` and `keyData` options) | ||
* Deliver whole write buffer if the socket is ready. | ||
* Fixed some global memory leaks. | ||
* Tidied up some code formatting glitches flagged by jslint | ||
* Fixes #16, #17, #18, #19, #20 | ||
1.1.4: | ||
* Fixes #15: Sending unified emoji via apn; Added encoding parameter when sending notification | ||
1.1.3: | ||
* Fixes #11,#12,#13,#14: Ensure delivery of notifications to Apple even under heavy load. | ||
1.1.2: | ||
* Fixes #9, Addresses an issue if the socket disconnects with queued notifications it would be reinitialised before its teardown is completed leaving the system in an undefined state. | ||
1.1.1: | ||
* Fixes issue #6 where a socket emitting an error could bring down the whole node instance as the exception is uncaught. | ||
1.1.0: | ||
* First shot at node-0.4.0 compatibility with new tls API. | ||
* Fixed a bug with parsing device token which could cause an out-of-bounds error. | ||
1.0.4: | ||
* The 1.0.x tree is now a maintenance branch as the TLS API used has been deprecated as of node 0.4.0 | ||
* Changed package.json to specify the inoperability of this version with node > 0.4.0 | ||
1.0.3: | ||
* Fixes a typo in the documentation in this very file | ||
1.0.2: | ||
* Fixes critical issue with error callback not firing (Issue #1) | ||
1.0.1: | ||
* Moved some object methods into the prototype to save memory | ||
* Tidied up some connecting code | ||
* Introduced an `index.js` to make module loading tidier | ||
* Fixed a couple of typos. | ||
1.0.0: | ||
* Well I created a module; Version 0.0.0 had no code, and now it does, and it works, so that's pretty neat, right? |
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
16
1070
0
0
74889
177