Comparing version 1.3.5 to 1.3.6
## Changelog | ||
1.3.6: | ||
* Resend notification if an error occurs before the socket drains (issue #100) | ||
* Perform more error checking on device tokens. (issue #90) | ||
1.3.5: | ||
@@ -4,0 +9,0 @@ |
@@ -293,3 +293,3 @@ var Errors = require('./errors'); | ||
debug("Socket error occurred", socket.socketId, err); | ||
if(socket.transmissionErrorOccurred && err.code == 'EPIPE') { | ||
@@ -307,2 +307,8 @@ debug("EPIPE occurred after a transmission error which we can ignore"); | ||
} | ||
if(socket.busy) { | ||
// A notification was in flight. It should be buffered for resending. | ||
this.bufferNotification(socket.cachedNotifications[socket.cachedNotifications.length - 1]); | ||
} | ||
this.destroyConnection(socket); | ||
@@ -405,2 +411,33 @@ }; | ||
*/ | ||
Connection.prototype.prepareNotification = function (notification, device) { | ||
var recipient = device; | ||
// If a device token hasn't been given then we should raise an error. | ||
if (recipient === undefined) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['missingDeviceToken'], notification); | ||
this.emit('transmissionError', Errors['missingDeviceToken'], notification); | ||
}.bind(this)); | ||
return; | ||
} | ||
// If we have been passed a token instead of a `Device` then we should convert. | ||
if (!(recipient instanceof Device)) { | ||
try { | ||
recipient = new Device(recipient); | ||
} | ||
catch (e) { | ||
// If an exception has been thrown it's down to an invalid token. | ||
process.nextTick(function () { | ||
this.raiseError(Errors['invalidToken'], notification, device); | ||
this.emit('transmissionError', Errors['invalidToken'], notification, device); | ||
}.bind(this)); | ||
return; | ||
} | ||
} | ||
this.bufferNotification( { "notification": notification, "recipient": recipient } ); | ||
}; | ||
/** | ||
* @private | ||
*/ | ||
Connection.prototype.cacheNotification = function (socket, notification) { | ||
@@ -576,22 +613,7 @@ socket.cachedNotifications.push(notification); | ||
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 }); | ||
this.prepareNotification(notification, recipient[i]); | ||
} | ||
} | ||
else { | ||
if (recipient === undefined) { | ||
process.nextTick(function () { | ||
this.raiseError(Errors['missingDeviceToken'], notification); | ||
this.emit('transmissionError', Errors['missingDeviceToken'], notification); | ||
}.bind(this)); | ||
return Errors['missingDeviceToken']; | ||
} | ||
var device = recipient; | ||
if (!(device instanceof Device)) { | ||
device = new Device(device); | ||
} | ||
this.bufferNotification({"notification":notification, "recipient":device }); | ||
this.prepareNotification(notification, recipient); | ||
} | ||
@@ -598,0 +620,0 @@ |
@@ -19,3 +19,3 @@ /** | ||
else { | ||
return null; | ||
throw new Error('Invalid Token Specified, must be a Buffer or valid hex String'); | ||
} | ||
@@ -22,0 +22,0 @@ } |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
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
101476
17
1242