Comparing version 1.2.0 to 1.2.1
@@ -7,2 +7,9 @@ var Errors = require('./errors'); | ||
var util = require('./util'); | ||
try { | ||
var debug = require('debug')('apn'); | ||
} | ||
catch (e) { | ||
console.log("Notice: Unable to load 'debug' module", e); | ||
var debug = function() {}; | ||
} | ||
@@ -74,2 +81,3 @@ /** | ||
debug("Initialising module"); | ||
this.deferredInitialize = q.defer(); | ||
@@ -118,2 +126,3 @@ | ||
debug("Initialising connection"); | ||
this.deferredConnection = q.defer(); | ||
@@ -146,3 +155,3 @@ this.initialize().then(function () { | ||
this.socketDrained(); | ||
debug("Connection established"); | ||
this.deferredConnection.resolve(); | ||
@@ -157,3 +166,5 @@ }.bind(this)); | ||
}.bind(this)).fail(function (error) { | ||
this.deferredConnection.reject(error); | ||
debug("Module initialisation error:", error); | ||
this.deferredConnection.reject(error); | ||
this.deferredConnection = null; | ||
}.bind(this)); | ||
@@ -168,6 +179,9 @@ | ||
Connection.prototype.socketDrained = function() { | ||
debug("Socket drained"); | ||
if (this.socket && (this.socket.socket.bufferSize != 0 || !this.socket.writable)) { | ||
return; | ||
} | ||
debug("Socket writeable"); | ||
if (this.notificationBuffer.length > 0) { | ||
debug("Sending notification from buffer"); | ||
this.sendNotification(this.notificationBuffer.shift()); | ||
@@ -181,4 +195,5 @@ } | ||
Connection.prototype.destroyConnection = function() { | ||
debug("Destroying connection"); | ||
if (this.socket) { | ||
this.socket.destroySoon(); | ||
this.socket.destroy(); | ||
} | ||
@@ -191,2 +206,3 @@ }; | ||
Connection.prototype.restartConnection = function() { | ||
debug("Restarting connection"); | ||
if (this.socket) { | ||
@@ -197,2 +213,3 @@ this.socket.removeAllListeners(); | ||
if(!this.deferredConnection.promise.isResolved()) { | ||
debug("Connection error occurred before TLS Handshake"); | ||
this.deferredConnection.reject(new Error("Unable to connect")); | ||
@@ -209,3 +226,4 @@ } | ||
if (this.notificationBuffer.length) { | ||
this.connect(); | ||
debug("Notification queue has %d items, resending the first", this.notificationBuffer.length); | ||
this.sendNotification(this.notificationBuffer.shift()); | ||
} | ||
@@ -227,2 +245,3 @@ }; | ||
if (this.cachedNotifications.length > this.options.cacheLength) { | ||
debug("Clearing notification %d from the cache", this.cachedNotifications[0]['_uid']); | ||
this.cachedNotifications.shift(); | ||
@@ -247,2 +266,4 @@ } | ||
debug("Notification %d caused an error: %d", identifier, errorCode); | ||
while (this.cachedNotifications.length) { | ||
@@ -257,3 +278,2 @@ notification = this.cachedNotifications.shift(); | ||
// If we haven't found a notification that caused the error then all the notifications must be resent. We should also raise a warning that the cache length isn't sufficient. | ||
if (foundNotification) { | ||
@@ -271,2 +291,3 @@ while (temporaryCache.length) { | ||
var count = this.cachedNotifications.length; | ||
debug("Buffering %d notifications", count); | ||
for (var i = 0; i < count; ++i) { | ||
@@ -285,2 +306,3 @@ notification = this.cachedNotifications.shift(); | ||
Connection.prototype.raiseError = function(errorCode, notification) { | ||
debug("Raising error: %d", errorCode, notification); | ||
if (typeof this.options.errorCallback == 'function') { | ||
@@ -297,3 +319,5 @@ this.options.errorCallback(errorCode, notification); | ||
this.connect().then(function() { | ||
debug("Sending notification"); | ||
if (this.socket.socket.bufferSize !== 0 || !this.socket.writable) { | ||
debug("Buffering notification"); | ||
this.bufferNotification(notification); | ||
@@ -358,3 +382,5 @@ return; | ||
this.socket.write(data); | ||
if(this.socket.write(data)) { | ||
this.socketDrained(); | ||
} | ||
}.bind(this)).fail(function (error) { | ||
@@ -361,0 +387,0 @@ this.raiseError(error, notification); |
@@ -8,2 +8,9 @@ var Device = require('./device'); | ||
var util = require('./util'); | ||
try { | ||
var debug = require('debug')('apnfb'); | ||
} | ||
catch (e) { | ||
console.log("Notice: Unable to load 'debug' module", e); | ||
var debug = function() {}; | ||
} | ||
@@ -76,2 +83,4 @@ /** | ||
} | ||
debug("Initialising module"); | ||
this.deferredInitialize = q.defer(); | ||
@@ -119,2 +128,4 @@ | ||
} | ||
debug("Initialising connection"); | ||
this.deferredConnection = q.defer(); | ||
@@ -139,2 +150,3 @@ this.initialize().then(function() { | ||
debug("Connection established"); | ||
this.deferredConnection.resolve(); | ||
@@ -148,2 +160,3 @@ }.bind(this)); | ||
}.bind(this)).fail(function (error) { | ||
debug("Module initialisation error:", error); | ||
this.deferredConnection.reject(error); | ||
@@ -164,2 +177,3 @@ this.deferredConnection = null; | ||
debug("Received packet of length: %d", data.length); | ||
var newBuffer = new Buffer(this.readBuffer.length + data.length); | ||
@@ -178,3 +192,5 @@ this.readBuffer.copy(newBuffer); | ||
debug("Parsed device token: %s, timestamp: %d", token.toString("hex"), time); | ||
if (typeof this.options.feedback == 'function') { | ||
debug("Calling feedback method for device"); | ||
this.options.feedback(time, new Device(token)); | ||
@@ -190,2 +206,3 @@ } | ||
Feedback.prototype.destroyConnection = function () { | ||
debug("Destroying connection"); | ||
if (this.socket) { | ||
@@ -200,5 +217,12 @@ this.socket.destroySoon(); | ||
Feedback.prototype.resetConnection = function () { | ||
debug("Resetting connection"); | ||
if (this.socket) { | ||
this.socket.removeAllListeners(); | ||
} | ||
if(!this.deferredConnection.promise.isResolved() { | ||
debug("Connection error occurred before TLS Handshake"); | ||
this.deferredConnection.reject(new Error("Unable to connect")); | ||
} | ||
this.socket = null; | ||
@@ -212,4 +236,6 @@ this.deferredConnection = null; | ||
Feedback.prototype.start = function () { | ||
debug("Starting feedback service"); | ||
this.cancel(); | ||
if (this.options.interval > 0) { | ||
debug("Feedback service interval set at: %d", this.options.interval); | ||
this.interval = setInterval(this.request.bind(this), this.options.interval * 1000); | ||
@@ -224,2 +250,3 @@ } | ||
Feedback.prototype.request = function () { | ||
debug("Performing feedback request"); | ||
this.connect().fail(function (error) { | ||
@@ -236,2 +263,3 @@ if(typeof this.options.errorCallback == "function") { | ||
Feedback.prototype.cancel = function () { | ||
debug("Cancelling feedback interval"); | ||
if (this.interval !== undefined) { | ||
@@ -238,0 +266,0 @@ clearInterval(this.interval); |
@@ -36,3 +36,3 @@ /** | ||
notification.alert = this.alert; | ||
notification.badget = this.badge; | ||
notification.badge = this.badge; | ||
notification.sound = this.sound; | ||
@@ -39,0 +39,0 @@ notification.newsstandAvailable = this.newsstandAvailable; |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -65,3 +65,3 @@ #node-apn | ||
note.expiry = 60; | ||
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now. | ||
note.badge = 3; | ||
@@ -139,3 +139,3 @@ note.sound = "ping.aiff"; | ||
Contributors: [Ian Babrou][bobrik], [dgthistle][dgthistle], [Keith Larsen][keithnlarsen], [Mike P][mypark] | ||
Contributors: [Ian Babrou][bobrik], [dgthistle][dgthistle], [Keith Larsen][keithnlarsen], [Mike P][mypark], [Greg Bergé][neoziro] | ||
@@ -170,2 +170,3 @@ ## License | ||
[mypark]: https://github.com/mypark | ||
[neoziro]: https://github.com/neoziro | ||
[q]: https://github.com/kriskowal/q | ||
@@ -175,2 +176,7 @@ | ||
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: | ||
@@ -177,0 +183,0 @@ |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40805
779
252
2
1