mirror of
https://gitlab.silvrtree.co.uk/martind2000/SODashServer.git
synced 2025-02-11 10:19:15 +00:00
Apple Push notifications.
This commit is contained in:
parent
ec6cecd270
commit
16dfd3ef2a
23
app.js
23
app.js
@ -22,6 +22,8 @@ var WebSocketServer = require('websocket').server;
|
||||
var EventEmitter = require('events');
|
||||
var busEmitter = new EventEmitter();
|
||||
|
||||
var apn = require('apn');
|
||||
|
||||
var calendar = require('./lib/office/officeController.js');
|
||||
var cal = new calendar.officeController(busEmitter);
|
||||
|
||||
@ -31,6 +33,7 @@ var projector_v1 = require('./routes/projector_v1');
|
||||
var isProduction = false;
|
||||
|
||||
var iosTokens = [];
|
||||
var apnTimer = 0;
|
||||
|
||||
|
||||
mqttConnect.setEmitter(busEmitter);
|
||||
@ -44,6 +47,9 @@ if (process.env.NODE_ENV === 'production') {
|
||||
|
||||
logger.debug('isProduction:', isProduction);
|
||||
|
||||
var options = { };
|
||||
|
||||
var apnConnection = new apn.Connection(options);
|
||||
|
||||
var app = express();
|
||||
|
||||
@ -227,6 +233,23 @@ app.post('/api/v1/register/ios', function(req, res) {
|
||||
if (iosTokens.indexOf(registrationId) === -1) {
|
||||
iosTokens.push(registrationId);
|
||||
logger.info('IOS Device registered.');
|
||||
|
||||
apnTimer = setInterval(function() {
|
||||
|
||||
var myDevice = new apn.Device(registrationId[0]);
|
||||
|
||||
var note = new apn.Notification();
|
||||
|
||||
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
|
||||
note.badge = 3;
|
||||
note.sound = "ping.aiff";
|
||||
note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
|
||||
note.payload = {'messageFrom': 'Caroline'};
|
||||
|
||||
apnConnection.pushNotification(note, myDevice);
|
||||
|
||||
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"after": "^0.8.1",
|
||||
"apn": "^1.7.5",
|
||||
"basic-authentication": "^1.6.2",
|
||||
"chai": "^3.5.0",
|
||||
"cheerio": "^0.20.0",
|
||||
|
Loading…
Reference in New Issue
Block a user