2011-11-06 12:21:27 -08:00
|
|
|
fs = require 'fs'
|
|
|
|
io = require('socket.io').listen 8888
|
|
|
|
redis = require 'redis'
|
2012-03-28 19:13:30 -07:00
|
|
|
|
2012-04-10 09:54:43 -07:00
|
|
|
REDIS_SERVER = if process.env.NODE_ENV == 'development' then 'localhost' else 'db01'
|
2012-03-28 19:13:30 -07:00
|
|
|
client = redis.createClient 6379, REDIS_SERVER
|
2011-11-06 12:21:27 -08:00
|
|
|
|
2012-04-10 09:54:43 -07:00
|
|
|
io.configure 'production', ->
|
|
|
|
io.set 'log level', 1
|
2012-05-03 13:43:18 -07:00
|
|
|
io.enable 'browser client minification'
|
|
|
|
io.enable 'browser client etag'
|
|
|
|
io.enable 'browser client gzip'
|
|
|
|
|
2012-04-10 09:54:43 -07:00
|
|
|
|
|
|
|
io.configure 'development', ->
|
|
|
|
io.set 'log level', 2
|
|
|
|
|
2011-11-06 12:21:27 -08:00
|
|
|
io.sockets.on 'connection', (socket) ->
|
2012-04-03 22:01:12 -07:00
|
|
|
socket.on 'subscribe:feeds', (@feeds, @username) ->
|
|
|
|
console.log " ---> [#{@username}] Subscribing to #{feeds.length} feeds " +
|
|
|
|
" (#{io.sockets.clients().length} users on)"
|
|
|
|
|
2012-03-28 16:13:17 -07:00
|
|
|
socket.subscribe?.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 @feeds
|
2011-11-06 12:21:27 -08:00
|
|
|
|
2012-04-10 10:09:46 -07:00
|
|
|
socket.subscribe.on 'message', (channel, message) =>
|
2012-04-03 22:01:12 -07:00
|
|
|
console.log " ---> [#{@username}] Update on #{channel}: #{message}"
|
2011-11-06 12:21:27 -08:00
|
|
|
socket.emit 'feed:update', channel
|
|
|
|
|
|
|
|
socket.on 'disconnect', () ->
|
|
|
|
socket.subscribe?.end()
|
2012-04-03 22:01:12 -07:00
|
|
|
console.log " ---> [#{@username}] Disconnect, there are now" +
|
|
|
|
" #{io.sockets.clients().length-1} users."
|
2011-11-06 12:21:27 -08:00
|
|
|
|