Comparing version 1.4.2 to 1.4.3
## Changelog | ||
1.4.3: | ||
* Added `shutdown` method to hint to node-apn that all connections should be terminated after notifications have been sent. (#134) | ||
* Fixed an exception thrown by an incorrect token length. (#133) | ||
1.4.2: | ||
@@ -4,0 +9,0 @@ |
@@ -87,2 +87,5 @@ var Errors = require('./errors'); | ||
// when true, we end all sockets after the pending notifications reach 0 | ||
this.shutdownPending = false; | ||
events.EventEmitter.call(this); | ||
@@ -103,3 +106,3 @@ } | ||
/** | ||
* 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, initialization and connection is handled by {@link Connection#sendNotification} | ||
* @private | ||
@@ -282,3 +285,3 @@ */ | ||
socket = null; | ||
if (this.notificationBuffer.length === 0) return; | ||
if (this.notificationBuffer.length === 0) break; | ||
for (var i = this.sockets.length - 1; i >= 0; i--) { | ||
@@ -305,2 +308,17 @@ if(this.socketAvailable(this.sockets[i])) { | ||
debug("%d left to send", this.notificationBuffer.length); | ||
if (this.notificationBuffer.length === 0 && this.shutdownPending) { | ||
debug("closing connections"); | ||
for (var i = this.sockets.length - 1; i >= 0; i--) { | ||
var socket = this.sockets[i]; | ||
if (!socket.busy) { | ||
// We delay before closing connections to ensure we don't miss any error packets from the service. | ||
setTimeout(socket.end.bind(socket), 2500); | ||
} | ||
} | ||
if (this.sockets.length == 0) { | ||
this.shutdownPending = false; | ||
} | ||
} | ||
}; | ||
@@ -615,4 +633,6 @@ | ||
// Each item has a 3 byte header: Type (1), Length (2) followed by data | ||
// The frame layout is hard coded for now as original dynamic system had a | ||
// significant performance penalty | ||
var frameLength = 3 + 32 + 3 + messageLength + 3 + 4; | ||
var frameLength = 3 + token.length + 3 + messageLength + 3 + 4; | ||
if(notification.notification.expiry > 0) { | ||
@@ -712,2 +732,10 @@ frameLength += 3 + 4; | ||
/** | ||
* End connections with APNS once we've finished sending all notifications | ||
*/ | ||
Connection.prototype.shutdown = function () { | ||
console.log("Shutdown pending"); | ||
this.shutdownPending = true; | ||
}; | ||
module.exports = Connection; |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
Sorry, the diff of this file is not supported yet
97746
18
1412