summaryrefslogtreecommitdiff
path: root/examples/lib/okpush/apn.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-10-05 17:49:19 -0400
committerJules Laplace <jules@okfoc.us>2016-10-05 17:49:19 -0400
commitae843591da0fea1a57684f26737be0b484718809 (patch)
tree547be3ae5d69c3568626a2f9ce9f35e034c82ed6 /examples/lib/okpush/apn.js
parent95df0e83fdb7f564d64b6c916e674e0db46c116d (diff)
okpush template stuff
Diffstat (limited to 'examples/lib/okpush/apn.js')
-rw-r--r--examples/lib/okpush/apn.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/examples/lib/okpush/apn.js b/examples/lib/okpush/apn.js
index 11b8711..050a466 100644
--- a/examples/lib/okpush/apn.js
+++ b/examples/lib/okpush/apn.js
@@ -1,13 +1,14 @@
-var config = require('./Config');
-var apn = require('apn');
+var config = require('./Config')
+var apn = require('apn')
var db = require('./db')
+var apnConnection, apnFeedback
function init (config) {
- var apnConnection = new apn.Connection(config.apn.connection)
+ apnConnection = new apn.Connection(config.apn.connection)
apnConnection.on('transmissionError', onTransmissionError)
- var apnFeedback = new apn.Feedback(config.apn.feedback)
+ apnFeedback = new apn.Feedback(config.apn.feedback)
apnFeedback.on('feedback', onFeedback)
return apnConnection
@@ -20,7 +21,7 @@ function onTransmissionError (errorCode, notification, recipient) {
var token = recipient.token.toString('hex').toUpperCase()
console.log('Invalid token: removing device ' + token)
- pushAssociations.removeDevice(token)
+ db.remove(token)
}
}
@@ -28,17 +29,17 @@ function onFeedback (deviceInfos) {
console.log('Feedback service, number of devices to remove: ' + deviceInfos.length)
if (deviceInfos.length > 0) {
- pushAssociations.removeDevices(deviceInfos.map(function (deviceInfo) {
+ db.removeDevices(deviceInfos.map(function (deviceInfo) {
return deviceInfo.device.token.toString('hex')
})
}
}
-var push = function (tokens, payload) {
- apnSender().pushNotification(payload, tokens)
+function push (tokens, payload) {
+ apnConnection.pushNotification(payload, tokens)
}
-var buildPayload = function (options) {
+function buildPayload (options) {
var notif = new apn.Notification()
notif.expiry = options.expiry || 0