Notifications have a configurable number of retries.

This commit is contained in:
Andrew Naylor 2013-07-21 00:13:29 +01:00
Родитель f47993e3a1
Коммит 696e8dce6c
4 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -182,6 +182,10 @@ As of version 1.2.0 it is possible to use a set of methods provided by Notificat
A `Notification` enapsulates the data to be compiled down to JSON and pushed to a device. See the [payload documentation][pl] for more details. At present the total length of the payload accepted by Apple is 256 bytes.
### notification.retryLimit
The maximum number of retries which should be performed when sending a notification if an error occurs. A value of 0 will only allow one attempt at sending (0 retries). Set to -1 to disable (default).
### notification.expiry
The UNIX timestamp representing when the notification should expire. This does not contribute to the 256 byte payload size limit.

Просмотреть файл

@ -400,6 +400,12 @@ Connection.prototype.setCacheLength = function(newLength) {
* @private
*/
Connection.prototype.bufferNotification = function (notification) {
if (notification.retryLimit === 0) {
this.raiseError(Errors['retryCountExceeded'], notification);
this.emit('transmissionError', Errors['retryCountExceeded'], notification.notification, notification.recipient);
return;
}
notification.retryLimit -= 1;
this.notificationBuffer.push(notification);
};
@ -431,7 +437,7 @@ Connection.prototype.prepareNotification = function (notification, device) {
return;
}
}
this.bufferNotification( { "notification": notification, "recipient": recipient } );
this.bufferNotification( { "notification": notification, "recipient": recipient, "retryLimit": notification.retryLimit } );
};
/**

Просмотреть файл

@ -14,7 +14,8 @@ var Errors = {
'invalidPayloadSize': 7,
'invalidToken': 8,
'apnsShutdown': 10,
'none': 255
'none': 255,
'retryLimitExceeded': 512
};
module.exports = Errors;

Просмотреть файл

@ -9,6 +9,8 @@ function Notification (payload) {
this.expiry = 0;
this.identifier = 0;
this.retryLimit = -1;
/** @deprecated since v1.3.0 used connection#pushNotification instead which accepts device token separately **/
this.device = undefined;