mirror of
https://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
synced 2025-02-14 20:49:16 +00:00
Apple Push notifications. Trying something else
This commit is contained in:
parent
2a3ed8acb2
commit
b66a9f3650
42
app.js
42
app.js
@ -35,15 +35,37 @@ var isProduction = false;
|
|||||||
var iosTokens = [];
|
var iosTokens = [];
|
||||||
var apnTimer = 0;
|
var apnTimer = 0;
|
||||||
|
|
||||||
var apns = require("apns"), options, connection, notification;
|
var apn = require('apn');
|
||||||
|
|
||||||
|
var apnService = new apn.connection({ production: false });
|
||||||
|
|
||||||
|
apnService.on('connected', function() {
|
||||||
|
logger.debug('APN Connected');
|
||||||
|
});
|
||||||
|
|
||||||
|
apnService.on('transmitted', function(notification, device) {
|
||||||
|
logger.debug('APN Notification transmitted to:' + device.token.toString('hex'));
|
||||||
|
});
|
||||||
|
|
||||||
|
apnService.on('transmissionError', function(errCode, notification, device) {
|
||||||
|
logger.error('APNNotification caused error: ' + errCode + ' for device ', device, notification);
|
||||||
|
if (errCode === 8) {
|
||||||
|
logger.error('A error code of 8 indicates that the device token is invalid. This could be for a number of reasons - are you using the correct environment? i.e. Production vs. Sandbox');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
apnService.on('timeout', function() {
|
||||||
|
logger.debug('Connection Timeout');
|
||||||
|
});
|
||||||
|
|
||||||
|
apnService.on('disconnected', function() {
|
||||||
|
logger.debug('Disconnected from APNS');
|
||||||
|
});
|
||||||
|
|
||||||
|
apnService.on('socketError', logger.error);
|
||||||
|
|
||||||
|
|
||||||
options = {
|
|
||||||
keyFile : "conf/key.pem",
|
|
||||||
certFile : "conf/cert.pem",
|
|
||||||
debug : true
|
|
||||||
};
|
|
||||||
|
|
||||||
connection = new apns.Connection(options);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -255,13 +277,7 @@ app.post('/api/v1/register/ios', function(req, res) {
|
|||||||
|
|
||||||
apnConnection.pushNotification(note, myDevice);*/
|
apnConnection.pushNotification(note, myDevice);*/
|
||||||
|
|
||||||
logger.warn('Sending Apple Notifications');
|
|
||||||
|
|
||||||
notification = new apns.Notification();
|
|
||||||
notification.device = new apns.Device(iosTokens[0]);
|
|
||||||
notification.alert = "Hello World !";
|
|
||||||
|
|
||||||
connection.sendNotification(notification);
|
|
||||||
|
|
||||||
|
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
10
package.json
10
package.json
@ -17,10 +17,10 @@
|
|||||||
"method-override": "*",
|
"method-override": "*",
|
||||||
"minibus": "^3.1.0",
|
"minibus": "^3.1.0",
|
||||||
"morgan": "*",
|
"morgan": "*",
|
||||||
"mqtt": "^1.7.0",
|
"mqtt": "^1.10.0",
|
||||||
"mqtt_over_websockets": "0.0.1",
|
"mqtt_over_websockets": "0.0.1",
|
||||||
"node-localstorage": "^1.1.2",
|
"node-localstorage": "^1.1.2",
|
||||||
"request": "*",
|
"request": "^2.72.0",
|
||||||
"websocket": "^1.0.22"
|
"websocket": "^1.0.22"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -37,7 +37,7 @@
|
|||||||
"gulp-autoprefixer": "^3.1.0",
|
"gulp-autoprefixer": "^3.1.0",
|
||||||
"gulp-cache": "^0.4.2",
|
"gulp-cache": "^0.4.2",
|
||||||
"gulp-concat": "^2.6.0",
|
"gulp-concat": "^2.6.0",
|
||||||
"gulp-cssnano": "^2.1.1",
|
"gulp-cssnano": "^2.1.2",
|
||||||
"gulp-debug": "^2.1.2",
|
"gulp-debug": "^2.1.2",
|
||||||
"gulp-google-webfonts": "0.0.12",
|
"gulp-google-webfonts": "0.0.12",
|
||||||
"gulp-html-replace": "^1.5.5",
|
"gulp-html-replace": "^1.5.5",
|
||||||
@ -49,14 +49,14 @@
|
|||||||
"gulp-notify": "^2.2.0",
|
"gulp-notify": "^2.2.0",
|
||||||
"gulp-rename": "^1.2.2",
|
"gulp-rename": "^1.2.2",
|
||||||
"gulp-uglify": "^1.5.3",
|
"gulp-uglify": "^1.5.3",
|
||||||
"jshint": "^2.9.1",
|
"jshint": "^2.9.2",
|
||||||
"jsonfile": "^2.3.0",
|
"jsonfile": "^2.3.0",
|
||||||
"log4js": "^0.6.35",
|
"log4js": "^0.6.35",
|
||||||
"mocha": "^2.4.5",
|
"mocha": "^2.4.5",
|
||||||
"mqtt-ws": "^0.2.0",
|
"mqtt-ws": "^0.2.0",
|
||||||
"node-cron": "^1.1.1",
|
"node-cron": "^1.1.1",
|
||||||
"require-dir": "^0.3.0",
|
"require-dir": "^0.3.0",
|
||||||
"should": "^8.2.2",
|
"should": "^8.3.1",
|
||||||
"string": "^3.3.1",
|
"string": "^3.3.1",
|
||||||
"sugar-date": "^1.5.1",
|
"sugar-date": "^1.5.1",
|
||||||
"superagent": "^1.7.2",
|
"superagent": "^1.7.2",
|
||||||
|
Loading…
Reference in New Issue
Block a user