2012-10-23 14:07:28 -07:00
|
|
|
// Generated by CoffeeScript 1.4.0
|
2011-11-06 12:21:27 -08:00
|
|
|
(function() {
|
2013-03-17 00:07:41 -07:00
|
|
|
var REDIS_SERVER, SECURE, ca, certificate, client, fs, io, privateKey, redis;
|
2011-11-06 12:21:27 -08:00
|
|
|
|
|
|
|
fs = require('fs');
|
|
|
|
|
|
|
|
redis = require('redis');
|
|
|
|
|
2013-03-14 19:32:05 -07:00
|
|
|
REDIS_SERVER = process.env.NODE_ENV === 'development' ? 'localhost' : 'db10';
|
2012-03-28 19:13:30 -07:00
|
|
|
|
2012-12-24 11:53:00 -08:00
|
|
|
SECURE = !!process.env.NODE_SSL;
|
|
|
|
|
2012-03-28 19:13:30 -07:00
|
|
|
client = redis.createClient(6379, REDIS_SERVER);
|
2011-11-06 12:21:27 -08:00
|
|
|
|
2012-12-24 11:53:00 -08:00
|
|
|
if (SECURE) {
|
|
|
|
privateKey = fs.readFileSync('./config/certificates/newsblur.com.key').toString();
|
|
|
|
certificate = fs.readFileSync('./config/certificates/newsblur.com.crt').toString();
|
|
|
|
ca = fs.readFileSync('./config/certificates/intermediate.crt').toString();
|
|
|
|
io = require('socket.io').listen(8889, {
|
|
|
|
key: privateKey,
|
|
|
|
cert: certificate,
|
|
|
|
ca: ca
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
io = require('socket.io').listen(8888);
|
|
|
|
}
|
|
|
|
|
2012-04-10 09:54:43 -07:00
|
|
|
io.configure('production', function() {
|
2012-05-03 13:43:18 -07:00
|
|
|
io.set('log level', 1);
|
|
|
|
io.enable('browser client minification');
|
|
|
|
io.enable('browser client etag');
|
|
|
|
return io.enable('browser client gzip');
|
2012-04-10 09:54:43 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
io.configure('development', function() {
|
|
|
|
return io.set('log level', 2);
|
|
|
|
});
|
|
|
|
|
2011-11-06 12:21:27 -08:00
|
|
|
io.sockets.on('connection', function(socket) {
|
2012-03-30 16:03:07 -07:00
|
|
|
socket.on('subscribe:feeds', function(feeds, username) {
|
2012-04-10 10:09:46 -07:00
|
|
|
var _ref,
|
|
|
|
_this = this;
|
2012-04-03 22:01:12 -07:00
|
|
|
this.feeds = feeds;
|
|
|
|
this.username = username;
|
|
|
|
console.log((" ---> [" + this.username + "] Subscribing to " + feeds.length + " feeds ") + (" (" + (io.sockets.clients().length) + " users on)"));
|
2012-10-22 16:25:36 -07:00
|
|
|
if ((_ref = socket.subscribe) != null) {
|
|
|
|
_ref.end();
|
|
|
|
}
|
2012-03-28 19:13:30 -07:00
|
|
|
socket.subscribe = redis.createClient(6379, REDIS_SERVER);
|
2012-04-03 22:01:12 -07:00
|
|
|
socket.subscribe.subscribe(this.feeds);
|
2012-10-22 16:25:36 -07:00
|
|
|
socket.subscribe.subscribe(this.username);
|
2011-11-06 12:21:27 -08:00
|
|
|
return socket.subscribe.on('message', function(channel, message) {
|
2012-04-10 10:09:46 -07:00
|
|
|
console.log(" ---> [" + _this.username + "] Update on " + channel + ": " + message);
|
2012-10-22 16:25:36 -07:00
|
|
|
if (channel === _this.username) {
|
|
|
|
return socket.emit('user:update', channel, message);
|
|
|
|
} else {
|
|
|
|
return socket.emit('feed:update', channel, message);
|
|
|
|
}
|
2011-11-06 12:21:27 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return socket.on('disconnect', function() {
|
2013-04-08 10:20:51 -07:00
|
|
|
var _ref, _ref1;
|
2012-10-22 16:25:36 -07:00
|
|
|
if ((_ref = socket.subscribe) != null) {
|
|
|
|
_ref.end();
|
|
|
|
}
|
2013-04-08 10:20:51 -07:00
|
|
|
return console.log((" ---> [" + this.username + "] Disconnect (" + ((_ref1 = this.feeds) != null ? _ref1.length : void 0) + " feeds), there are now") + (" " + (io.sockets.clients().length - 1) + " users. ") + (" " + (SECURE ? "(SSL)" : "(non-SSL)")));
|
2011-11-06 12:21:27 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|