These are chat archives for argon/node-apn

16th
Sep 2015
Naveen Singh
@w0w
Sep 16 2015 08:31
@argon I was wondering how much performance difference will it make when i use
          var options = {
              cert:  apnsCert,
              certData: null,
              key:apnsKey,
              keyData: null,
              passphrase: 'asdfgh',
              ca: null,
              gateway: 'gateway.sandbox.push.apple.com',
              port: 2195,
              enhanced: true,
              errorCallback: function(err,notifcation){
                console.log(err);
                console.log(notifcation);
              },
              cacheLength: 100
          };
when i use cert and key options
instead of certData and keyData
Naveen Singh
@w0w
Sep 16 2015 08:38
does it perform fileread operation everytime a notification is sent
Andrew Naylor
@argon
Sep 16 2015 10:30
It will perform a file read operation each time a Connection object is created by you. Which should be once.
Naveen Singh
@w0w
Sep 16 2015 11:29
      else if (item.deviceType==='ios') {
        // Use apn to send notification
        Push.app.models.application.findById(item.appId, function(err, a){
          if(err) { return cb(err);}
          var apnsCert = path.join(__dirname + '/../../server/credentials/', 'apns_cert_dev.pem');
          var apnsKey = path.join(__dirname + '/../../server/credentials/', 'apns_key_dev.pem');
          var options = {
              cert:  apnsCert,
              certData: null,
              key:apnsKey,
              keyData: null,
              passphrase: 'asdfgh',
              ca: null,
              gateway: 'gateway.sandbox.push.apple.com',
              port: 2195,
              enhanced: true,
              errorCallback: function(err,notifcation){
                console.log(err);
                console.log(notifcation);
              },
              cacheLength: 100
          };
          var apnsConnection = new apns.Connection(options);
          var token = item.deviceToken;
          var myDevice = new apns.Device(token);
          var note = new apns.Notification();

          note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
          note.badge = 1;
          note.sound = "ping.aiff";
          note.alert = ""+ ctx.text;
          note.payload = ctx;
          note.device = myDevice;
          apnsConnection.sendNotification(note);
          cb();
        });
      }
Andrew Naylor
@argon
Sep 16 2015 12:43
You're creating a new connection every time you send a notification. You're going to see terrible performance as each connection can take up to a second to create.

From Apples Docs:

Keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack. You should leave a connection open unless you know it will be idle for an extended period of time—for example, if you only send notifications to your users once a day it is ok to use a new connection each day.

Naveen Singh
@w0w
Sep 16 2015 14:24
please if possible guide me how to create a connection just once
Andrew Naylor
@argon
Sep 16 2015 17:25
Don't create more than one apns.Connection object. Create it once elsewhere and reuse it whenever you need to send a push notification