Skip to content

Commit 832924d

Browse files
committed
Adds support for retrying on next provider
1 parent 6c0bbc5 commit 832924d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

spec/ParsePushAdapter.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ describe('ParsePushAdapter', () => {
398398
});
399399

400400
// Xited till we can retry on other connections
401-
xit('reports properly select connection', (done) => {
401+
it('reports properly select connection', (done) => {
402402
var pushConfig = {
403403
ios: [
404404
{
@@ -441,7 +441,7 @@ describe('ParsePushAdapter', () => {
441441
expect(typeof device.deviceToken).toBe('string');
442442
expect(result.transmitted).toBe(true);
443443
done();
444-
}).catch((err) => {
444+
}).catch((err) => {
445445
fail('Should not fail');
446446
done();
447447
})

src/APNS.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,40 @@ export class APNS {
9696
}
9797

9898
let notification = APNS._generateNotification(coreData, expirationTime, appIdentifier);
99-
let promise = providers[0]
100-
.send(notification, devices.map(device => device.deviceToken))
101-
.then(this._handlePromise.bind(this));
102-
allPromises.push(promise);
99+
const deviceIds = devices.map(device => device.deviceToken);
100+
let promise = this.sendThroughProvider(notification, deviceIds, providers);
101+
allPromises.push(promise.then(this._handlePromise.bind(this)));
103102
}
104103

105-
return Promise.all(allPromises).then((results) => {
104+
return Promise.all(allPromises).then((results) => {
106105
// flatten all
107106
return [].concat.apply([], results);
108107
});
109108
}
110109

110+
sendThroughProvider(notification, devices, providers) {
111+
return providers[0]
112+
.send(notification, devices)
113+
.then((response) => {
114+
if (response.failed
115+
&& response.failed.length > 0
116+
&& providers && providers.length > 1) {
117+
let devices = response.failed.map((failure) => { return failure.device; });
118+
// Reset the failures as we'll try next connection
119+
response.failed = [];
120+
return this.sendThroughProvider(notification,
121+
devices,
122+
providers.slice(1, providers.length)).then((retryResponse) => {
123+
response.failed = response.failed.concat(retryResponse.failed);
124+
response.sent = response.sent.concat(retryResponse.sent);
125+
return response;
126+
});
127+
} else {
128+
return response;
129+
}
130+
});
131+
}
132+
111133
static _validateAPNArgs(apnsArgs) {
112134
if (apnsArgs.topic) {
113135
return true;

0 commit comments

Comments
 (0)