Skip to content

Instantly share code, notes, and snippets.

@Blankwonder
Created December 9, 2013 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blankwonder/7869121 to your computer and use it in GitHub Desktop.
Save Blankwonder/7869121 to your computer and use it in GitHub Desktop.
var redis = require('redis');
redis.debug_mode = true;
var db = redis.createClient(process.env.NODE_ENV === 'development' ? '6379' : '6392');
var apns = require('apn');
var util = require('util');
var errorCallback = function(errcode, err) {
console.log(errcode, err);
};
var iosOption = {
cert: __dirname + '/keys/ios_cert.pem',
key: __dirname + '/keys/ios_key.pem',
errorCallback: errorCallback
};
var iosSandboxOption = {
cert: __dirname + '/keys/ios_sandbox_cert.pem',
key: __dirname + '/keys/ios_sandbox_key.pem',
gateway: 'gateway.sandbox.push.apple.com',
errorCallback: errorCallback
};
var apnConnections = {
ios: new apns.Connection(iosOption),
iosSandbox: new apns.Connection(iosSandboxOption)
};
doloop = function() {
db.brpop('queue:push.IOS_SANDBOX', 'queue:push.IOS', 0, function(err, info) {
if (!err) {
var connection;
var key = info[0];
if (key === 'queue:push.IOS_SANDBOX') {
connection = apnConnections.iosSandbox;
} else if (key === 'queue:push.IOS') {
connection = apnConnections.ios;
}
info = JSON.parse(info[1]);
if (connection) {
var note = new apns.Notification();
note.payload = info.payload;
note.device = new apns.Device(info.token);
connection.sendNotification(note);
}
}
doloop();
});
};
db.select(1, doloop);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment