Skip to content
Browse files

Move APNs feedback handling into APNs plugin

  • Loading branch information...
1 parent 6150d46 commit 7ceb220702d1a84dfe235ee2be0329783f1e6f19 @rs rs committed
Showing with 22 additions and 20 deletions.
  1. +11 −1 lib/pushservices/apns.coffee
  2. +1 −1 lib/pushservices/c2dm.coffee
  3. +1 −1 lib/pushservices/mpns.coffee
  4. +9 −17 pushd.coffee
View
12 lib/pushservices/apns.coffee
@@ -6,11 +6,21 @@ class PushServiceAPNS
if PushServiceAPNS::tokenFormat.test(token)
return token.toLowerCase()
- constructor: (conf, @logger) ->
+ constructor: (conf, @logger, tokenResolver) ->
conf.errorCallback = (errCode, note) =>
@logger?.error("APNS Error #{errCode} for subscriber #{note?.device?.subscriberId}")
@driver = new apns.Connection(conf)
+ # Handle Apple Feedbacks
+ conf.feedback = (time, apnsSubscriber) ->
+ tokenResolver 'apns', apnsSubscriber.hexToken(), (subscriber) =>
+ subscriber?.get (info) ->
+ if info.updated < time
+ @logger.warn("APNS Automatic unregistration for subscriber #{subscriber.id}")
+ subscriber.delete()
+ @feedback = new apns.Feedback(conf)
+
+
push: (subscriber, subOptions, payload) ->
subscriber.get (info) =>
note = new apns.Notification()
View
2 lib/pushservices/c2dm.coffee
@@ -7,7 +7,7 @@ class PushServiceC2DM
if PushServiceC2DM::tokenFormat.test(token)
return token
- constructor: (conf, @logger) ->
+ constructor: (conf, @logger, tokenResolver) ->
conf.concurrency ?= 10
conf.keepAlive = true
@driver = new c2dm.C2DM(conf)
View
2 lib/pushservices/mpns.coffee
@@ -6,7 +6,7 @@ class PushServiceMPNS
if PushServiceMPNS::tokenFormat.test(token)
return token
- constructor: (@conf, @logger) ->
+ constructor: (@conf, @logger, tokenResolver) ->
push: (subscriber, subOptions, payload) ->
# TO BE IMPLEMENTED
View
26 pushd.coffee
@@ -10,9 +10,17 @@ Event = require('./lib/event').Event
PushServices = require('./lib/pushservices').PushServices
logger = console
+createSubscriber = (fields, cb) ->
+ throw new Error("Invalid value for `proto'") unless service = pushservices.getService(fields.proto)
+ throw new Error("Invalid value for `token'") unless fields.token = service.validateToken(fields.token)
+ Subscriber::create(redis, fields, cb)
+
+tokenResolver = (proto, token, cb) ->
+ Subscriber::getInstanceFromToken redis, proto, token, cb
+
pushservices = new PushServices()
for name, conf of settings when conf.enabled
- pushservices.addService(name, new conf.class(conf, logger))
+ pushservices.addService(name, new conf.class(conf, logger, tokenResolver))
app = express.createServer()
@@ -38,11 +46,6 @@ app.param 'event_id', (req, res, next, id) ->
catch error
res.json error: error.message, 400
-createSubscriber = (fields, cb) ->
- throw new Error("Invalid value for `proto'") unless service = pushservices.getService(fields.proto)
- throw new Error("Invalid value for `token'") unless fields.token = service.validateToken(fields.token)
- Subscriber::create(redis, fields, cb)
-
authorize = (realm) ->
if allow_from = settings.server?.acl?[realm]
networks = []
@@ -94,14 +97,3 @@ udpApi.on 'message', (msg, rinfo) ->
logger.log("UDP/#{method} #{req.pathname} #{status}") if settings.server?.access_log
udpApi.bind settings?.server?.udp_port ? 80
-
-# Handle Apple Feedbacks
-apns = require 'apn'
-options = settings.apns
-options.feedback = (time, apnsSubscriber) ->
- Subscriber::getInstanceFromToken redis, 'apns', apnsSubscriber.hexToken(), (subscriber) ->
- subscriber?.get (info) ->
- if info.updated < time
- logger.warn("APNS Automatic unregistration for subscriber #{subscriber.id}")
- subscriber.delete()
-feedback = new apns.Feedback(options)

0 comments on commit 7ceb220

Please sign in to comment.
Something went wrong with that request. Please try again.