Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support for batching APNS feedback and supporting error callbacks per notification #73

Closed
wants to merge 4 commits into from

2 participants

@rwtombaugh

No description provided.

Randall Tomb... added some commits
@argon
Owner

Merged into v1.2.5, Thanks!

@argon argon closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 10, 2012
  1. fix for pfx file support

    Randall Tombaugh authored
Commits on Oct 16, 2012
  1. Added batched feedback feature.

    Randall Tombaugh authored
  2. Added support for per notification error callbacks.

    Randall Tombaugh authored
Commits on Dec 19, 2012
  1. Updating readme.

    Randall Tombaugh authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 7 deletions.
  1. +1 −0  README.md
  2. +4 −2 lib/connection.js
  3. +19 −5 lib/feedback.js
View
1  README.md
@@ -109,6 +109,7 @@ Using the `Feedback` object it is possible to periodically query the server for
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 */
};
View
6 lib/connection.js
@@ -100,7 +100,7 @@ Connection.prototype.initialize = function () {
this.deferredInitialize.reject(err);
return;
}
- this.pfxData = data.toString();
+ this.pfxData = data;
this.checkInitialized();
}.bind(this));
}
@@ -333,7 +333,9 @@ Connection.prototype.handleTransmissionError = function (data) {
*/
Connection.prototype.raiseError = function(errorCode, notification) {
debug("Raising error:", errorCode, notification);
- if (typeof this.options.errorCallback == 'function') {
+ if (notification && typeof notification.errorCallback == 'function' ) {
+ notification.errorCallback(errorCode);
+ } else if (typeof this.options.errorCallback == 'function') {
this.options.errorCallback(errorCode, notification);
}
};
View
24 lib/feedback.js
@@ -29,7 +29,8 @@ if(process.env.DEBUG) {
* @config {String} [passphrase] The passphrase for the connection key, if required
* @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
* @config {Number} [interval=3600] Interval to automatically connect to the Feedback service.
*/
@@ -48,6 +49,7 @@ function Feedback(options) {
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 */
interval: 3600, /* interval in seconds to connect to feedback service */
};
@@ -96,12 +98,12 @@ Feedback.prototype.initialize = function () {
this.pfxData = this.options.pfxData;
}
else {
- fx.readFile(this.options.pfx, function (err, data) {
+ fs.readFile(this.options.pfx, function (err, data) {
if (err) {
this.deferredInitialize.reject(err);
return;
}
- this.pfxData = data.toString();
+ this.pfxData = data;
this.checkInitialized();
}.bind(this));
}
@@ -175,6 +177,7 @@ Feedback.prototype.connect = function () {
}.bind(this));
this.readBuffer = new Buffer(0);
+ this.feedbackData = [];
this.socket.on('data', this.receive.bind(this));
this.socket.on("error", this.destroyConnection.bind(this));
this.socket.once('close', this.resetConnection.bind(this));
@@ -210,9 +213,13 @@ Feedback.prototype.receive = function (data) {
this.readBuffer.copy(token, 0, 6, 6 + tokenLength);
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 });
}
this.readBuffer = this.readBuffer.slice(6 + tokenLength);
}
@@ -236,6 +243,13 @@ Feedback.prototype.resetConnection = function () {
if (this.socket) {
this.socket.removeAllListeners();
}
+
+ 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()) {
debug("Connection error occurred before TLS Handshake");
Something went wrong with that request. Please try again.