Skip to content

Commit

Permalink
Merge pull request #1 from NUDelta/apn-pfx
Browse files Browse the repository at this point in the history
chore: Update to work with node-apn V2 and apn.pfx files
  • Loading branch information
youralien authored Jun 3, 2021
2 parents df45b9e + b771b67 commit 44d70b1
Show file tree
Hide file tree
Showing 9 changed files with 8,832 additions and 1,224 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stages:
- release

script:
- ./bin/lint-commit.sh
# - ./bin/lint-commit.sh
- npm test
- if [ "$TRAVIS_BRANCH" == "master" ]; then npm run semantic-release; fi

Expand Down
94 changes: 47 additions & 47 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
[email protected]
[email protected]
[email protected]_1
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]_1
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
nudelta2015:[email protected]
[email protected]
[email protected]
raix:[email protected]
raix:[email protected]
raix:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

<img alt="Gi-SoftWare" src="https://raw.githubusercontent.com/raix/push/master/docs/logo.png" width="20%" height="20%">

raix:push Push notifications
nudelta2015:push Push notifications
============================
[![Build Status](https://travis-ci.org/raix/push.svg?branch=master)](https://travis-ci.org/raix/push)
This is a fork of raix:push to support passing a pfx file to the node-apn


============================
[![Build Status](https://travis-ci.com/NUDelta/push.svg?branch=master)](https://travis-ci.com/NUDelta/push)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

> Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox) - One unified api on client and server.
Expand Down Expand Up @@ -113,7 +117,7 @@ Push.send({

## Install
```bash
$ meteor add raix:push
$ meteor add nudelta2015:push
$ meteor add cordova:[email protected]
$ meteor add cordova:[email protected]
# Note: you probably want to adjust the version numbers to the latest versions of the packages
Expand Down Expand Up @@ -187,11 +191,9 @@ For example in `Meteor.startup()` block of main.js
```js
Push.Configure({
apn: {
certData: Assets.getText('apnDevCert.pem'),
keyData: Assets.getText('apnDevKey.pem'),
pfx: 'path/to/your-single-p12-file.p12'
passphrase: 'xxxxxxxxx',
production: true,
//gateway: 'gateway.push.apple.com',
},
gcm: {
apiKey: 'xxxxxxx', // GCM/FCM server key
Expand Down
3 changes: 1 addition & 2 deletions docs/BASIC.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Server:
```js
Push.Configure({
apn: {
certData: Assets.getText('apnDevCert.pem'),
keyData: Assets.getText('apnDevKey.pem'),
pfx: 'path/to/your/pfx/or/single/p12/file'
passphrase: 'xxxxxxxxx',
production: true,
//gateway: 'gateway.push.apple.com',
Expand Down
118 changes: 50 additions & 68 deletions lib/server/push.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,7 @@ Push.Configure = function(options) {
//
// Warn about gateway configurations - it's more a guide
if (options.apn.gateway) {

if (options.apn.gateway === 'gateway.sandbox.push.apple.com') {
// Using the development sandbox
console.warn('WARNING: Push APN is in development mode');
} else if (options.apn.gateway === 'gateway.push.apple.com') {
// In production - but warn if we are running on localhost
if (/http:\/\/localhost/.test(Meteor.absoluteUrl())) {
console.warn('WARNING: Push APN is configured to production mode - but server is running' +
' from localhost');
}
} else {
// Warn about gateways we dont know about
console.warn('WARNING: Push APN unkown gateway "' + options.apn.gateway + '"');
}

console.warn('WARNING: Push APN "gateway" deprecated use the "production" flag instead.');
} else {
if (options.apn.production) {
if (/http:\/\/localhost/.test(Meteor.absoluteUrl())) {
Expand All @@ -135,19 +121,44 @@ Push.Configure = function(options) {

}

// Check certificate data
if (!options.apn.certData || !options.apn.certData.length) {
console.error('ERROR: Push server could not find certData');
if (options.apn.certData) {
console.warn('WARNING: Push APN config "certData" is deprecated use "cert".');
}
if (options.apn.keyData) {
console.warn('WARNING: Push APN config "keyData" is deprecated use "key".');
}

/**
if (!options.apn.token) {
// Check certificate data
if (!options.apn.cert || !options.apn.cert.length) {
console.error('ERROR: Push APN config could not find cert');
}
// Check key data
if (!options.apn.key || !options.apn.key.length) {
console.error('ERROR: Push APN config could not find key');
}
} else {
if (!options.apn.token.key || !options.apn.token.key.length) {
console.error('ERROR: Push APN config could not find "token.key"');
}
if (!options.apn.token.keyId || !options.apn.token.keyId.length) {
console.error('ERROR: Push APN config could not find "token.keyId"');
}
if (!options.apn.token.teamId || !options.apn.token.teamId.length) {
console.error('ERROR: Push APN config could not find "token.teamId"');
}
}
**/

// Check key data
if (!options.apn.keyData || !options.apn.keyData.length) {
console.error('ERROR: Push server could not find keyData');
if (!options.apn.pfx) {
console.error('ERROR: This fork of Push APN needs a pfx (single p12) file');
}

// Rig apn connection
var apn = Npm.require('apn');
var apnConnection = new apn.Connection( options.apn );
var apnConnection = new apn.Provider( options.apn );

// Listen to transmission errors - should handle the same way as feedback.
apnConnection.on('transmissionError', Meteor.bindEnvironment(function (errCode, notification, recipient) {
Expand Down Expand Up @@ -179,12 +190,8 @@ Push.Configure = function(options) {
notification = _.extend({}, notification, notification.apn);
}

// console.log('sendAPN', notification.from, userToken, notification.title, notification.text,
// notification.badge, notification.priority);
var priority = (notification.priority || notification.priority === 0)? notification.priority : 10;

var myDevice = new apn.Device(userToken);

var note = new apn.Notification();

note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
Expand All @@ -194,16 +201,13 @@ Push.Configure = function(options) {
if (typeof notification.sound !== 'undefined') {
note.sound = notification.sound;
}
//console.log(notification.contentAvailable);
//console.log("lala2");
//console.log(notification);
// xxx: topic is required on notifications
note.topic = notification.topic || notification.from || 'topic';
if (typeof notification.contentAvailable !== 'undefined') {
//console.log("lala");
note.setContentAvailable(notification.contentAvailable);
//console.log(note);
}

// adds category support for iOS8 custom actions as described here:
// adds category support for iOS8 custom actions as described here:
// https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/
// RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW36
if (typeof notification.category !== 'undefined') {
Expand All @@ -230,46 +234,24 @@ Push.Configure = function(options) {

// console.log('I:Send message to: ' + userToken + ' count=' + count);

apnConnection.pushNotification(note, myDevice);

};


var initFeedback = function () {
var apn = Npm.require('apn');
// console.log('Init feedback');
var feedbackOptions = {
'batchFeedback': true,

// Time in SECONDS
'interval': 5,
production: !options.apn.development,
cert: options.certData,
key: options.keyData,
passphrase: options.passphrase
};

var feedback = new apn.Feedback(feedbackOptions);
feedback.on('feedback', function (devices) {
devices.forEach(function (item) {
// Do something with item.device and item.time;
// console.log('A:PUSH FEEDBACK ' + item.device + ' - ' + item.time);
// The app is most likely removed from the device, we should
// remove the token
_removeToken({
apn: item.device
});
});
apnConnection.send(note, userToken).then( (response) => {
response.sent.forEach( (token) => {
notificationSent(user, token);
});
response.failed.forEach( (failure) => {
if (failure.error) {
// A transport-level error occurred (e.g. network problem)
notificationError(user, failure.device, failure.error);
} else {
// `failure.status` is the HTTP status code
// `failure.response` is the JSON payload
notificationFailed(user, failure.device, failure.status, failure.response);
}
});
});

feedback.start();
};

// Init feedback from apn server
// This will help keep the appCollection up-to-date, it will help update
// and remove token from appCollection.
initFeedback();

} // EO ios notification

if (options.gcm && options.gcm.apiKey) {
Expand Down
Loading

0 comments on commit 44d70b1

Please sign in to comment.