forked from suncty/bity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapns.js
38 lines (32 loc) · 1.64 KB
/
apns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
eval(global.ty());
var apns = apn;
var apnsOption;
ty(function() {
apnsOptions = {
cert: config.apns.cert, /* Certificate file path */
certData: null, /* String or Buffer containing certificate data, if supplied uses this instead of cert file path */
key: config.apns.key, /* Key file path */
keyData: null, /* String or Buffer containing key data, as certData */
passphrase: config.apns.passphrase, /* A passphrase for the Key file */
ca: null, /* String or Buffer of CA data to use for the TLS connection */
gateway: config.apns.sandbox ? 'gateway.sandbox.push.apple.com' : 'gateway.push.apple.com',/* gateway address */
port: 2195, /* gateway port */
enhanced: true, /* enable enhanced format */
errorCallback: undefined, /* Callback when error occurs function(err,notification) */
cacheLength: 100 /* Number of notifications to cache for error purposes */
};
});
ty('device', function(token) {
return new apns.Device(token);
});
ty('notification', function(device, arg) {
var apnsConnection = new apns.Connection(apnsOptions);
var note = new apns.Notification();
note.expiry = Math.floor(Date.now() / 1000) + (arg.expiry ? arg.expiry : 3600);
note.badge = arg.badge ? arg.badge : 3;
note.sound = arg.sound ? (arg.sound + '.aiff') : 'ping.aiff';
note.alert = arg.alert;
note.payload = arg.payload;
note.device = device;
apnsConnection.sendNotification(note);
});