NewsBlur/node/unread_counts.js

71 lines
2.4 KiB
JavaScript
Raw Normal View History

2012-10-23 14:07:28 -07:00
// Generated by CoffeeScript 1.4.0
(function() {
var REDIS_SERVER, SECURE, ca, certificate, client, fs, io, privateKey, redis;
fs = require('fs');
redis = require('redis');
2013-03-14 19:32:05 -07:00
REDIS_SERVER = process.env.NODE_ENV === 'development' ? 'localhost' : 'db10';
SECURE = !!process.env.NODE_SSL;
client = redis.createClient(6379, REDIS_SERVER);
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);
}
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');
});
io.configure('development', function() {
return io.set('log level', 2);
});
io.sockets.on('connection', function(socket) {
socket.on('subscribe:feeds', function(feeds, username) {
var _ref,
_this = this;
this.feeds = feeds;
this.username = username;
console.log((" ---> [" + this.username + "] Subscribing to " + feeds.length + " feeds ") + (" (" + (io.sockets.clients().length) + " users on)"));
if ((_ref = socket.subscribe) != null) {
_ref.end();
}
socket.subscribe = redis.createClient(6379, REDIS_SERVER);
socket.subscribe.subscribe(this.feeds);
socket.subscribe.subscribe(this.username);
return socket.subscribe.on('message', function(channel, message) {
console.log(" ---> [" + _this.username + "] Update on " + channel + ": " + message);
if (channel === _this.username) {
return socket.emit('user:update', channel, message);
} else {
return socket.emit('feed:update', channel, message);
}
});
});
return socket.on('disconnect', function() {
var _ref, _ref1;
if ((_ref = socket.subscribe) != null) {
_ref.end();
}
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)")));
});
});
}).call(this);