diff --git a/app.js b/app.js index 6702da1..36c0366 100644 --- a/app.js +++ b/app.js @@ -36,6 +36,34 @@ var iosTokens = []; var apnTimer = 0; +var settings = { + gcm: { + id: null, // PUT YOUR GCM SERVER API KEY, + options: {}, + msgcnt: 1, + dataDefaults: { + delayWhileIdle: false, + timeToLive: 4 * 7 * 24 * 3600, // 4 weeks + retries: 4 + } + }, + apn: { + gateway: 'gateway.sandbox.push.apple.com', + badge: 1, + defaultData: { + expiry: 5, // 4 weeks + sound: 'ping.aiff' + } + }, + adm: { + client_id: null, // PUT YOUR ADM CLIENT ID, + client_secret: null, // PUT YOUR ADM CLIENT SECRET, + expiresAfter: 4 * 7 * 24 * 3600, // 4 weeks + } +}; +var push = new require('node-pushnotifications')(settings); + + mqttConnect.setEmitter(busEmitter); mqttConnect.doConnection(); @@ -236,17 +264,23 @@ app.post('/api/v1/register/ios', function(req, res) { apnTimer = setInterval(function() { - var myDevice = new apn.Device(registrationId[0]); + /* Var myDevice = new apn.Device(registrationId[0]); - var note = new apn.Notification(); + 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); + 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);*/ + + logger.warn('Sending Apple Notifications'); + data = {title: 'New push notification' , message: 'Powered by Martin', otherfields: 'optionally add more data'}; + push.sendPush(iosTokens, data, function(result) { + logger.debug(result); + }); }, 30000); diff --git a/package.json b/package.json index de25489..0e98138 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "mocha": "^2.4.5", "mqtt-ws": "^0.2.0", "node-cron": "^1.1.1", + "node-pushnotifications": "^0.1.4", "require-dir": "^0.3.0", "should": "^8.2.2", "string": "^3.3.1",