From 034918f685f9e4bf1933999082f47a75119b7c28 Mon Sep 17 00:00:00 2001 From: Lian Hsueh Date: Mon, 30 Jul 2012 15:09:18 +0800 Subject: [PATCH] push to remote --- config.js | 14 -------- controller/index.js | 40 ---------------------- controller/publish.js | 48 --------------------------- controller/subscribe.js | 13 -------- makefile | 6 ++++ server.js | 23 ------------- setup.js | 26 --------------- socket/index.js | 73 ----------------------------------------- src/socket/index.coffee | 3 +- tools/middleware.js | 8 ----- tools/ping.js | 6 ---- view/index.jade | 28 ---------------- view/index2.jade | 30 ----------------- view/index3.jade | 29 ---------------- view/online.jade | 38 --------------------- 15 files changed, 8 insertions(+), 377 deletions(-) delete mode 100644 config.js delete mode 100644 controller/index.js delete mode 100644 controller/publish.js delete mode 100644 controller/subscribe.js delete mode 100644 server.js delete mode 100644 setup.js delete mode 100644 socket/index.js delete mode 100644 tools/middleware.js delete mode 100644 tools/ping.js delete mode 100644 view/index.jade delete mode 100644 view/index2.jade delete mode 100644 view/index3.jade delete mode 100644 view/online.jade diff --git a/config.js b/config.js deleted file mode 100644 index 2aaf899..0000000 --- a/config.js +++ /dev/null @@ -1,14 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - - exports.VSERSION = '1.2'; - - exports.TOKEN = 'aS5odW5hbnR2LmNvbQ=='; - - exports.domain = 'http://pusher.hunantv.com'; - - exports.port = 80; - - exports.numCPUs = require('os').cpus().length; - -}).call(this); diff --git a/controller/index.js b/controller/index.js deleted file mode 100644 index 8d5327a..0000000 --- a/controller/index.js +++ /dev/null @@ -1,40 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var configs; - - configs = require('../config'); - - module.exports = function(app, io) { - app.get('/', function(req, res) { - return res.render('online', { - layout: false, - pusher: configs.domain - }); - }); - app.get('/1', function(req, res) { - return res.render('index', { - layout: false, - pusher: configs.domain, - id: 1 - }); - }); - app.get('/2', function(req, res) { - return res.render('index', { - layout: false, - pusher: configs.domain, - id: 2 - }); - }); - app.get('/3', function(req, res) { - return res.render('index', { - layout: false, - pusher: configs.domain, - id: 3 - }); - }); - return ['publish', 'subscribe'].map(function(controllerName) { - return require('./' + controllerName)(app, io); - }); - }; - -}).call(this); diff --git a/controller/publish.js b/controller/publish.js deleted file mode 100644 index 9582ea2..0000000 --- a/controller/publish.js +++ /dev/null @@ -1,48 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var justMsg, publish; - - justMsg = function(req, res) { - return res.send('Honey Pusher publish API'); - }; - - publish = function(req, res, io) { - /* - Subscribe: - project: 'project name. eg: ihunantv' - channel: 'channel name. eg: a movie id' - body: 'message body' - - Message: - project: 'project name. eg: ihunantv' - from: 'msg send from who' - to: 'msg send to who' - body: 'message body' - */ - - var data, room; - data = req.body; - if (data.project) { - /* - Get room name - */ - - if (data.type === 'subscribe') { - room = "" + data.project + ":channel:" + data.channel; - } else { - room = data.to ? "" + data.project + ":" + data.to : data.project; - } - console.log(room); - io.sockets["in"](room).emit(data.type, data); - } - return res.send(req.body); - }; - - module.exports = function(app, io) { - app.get('/pub', justMsg); - return app.post('/pub', function(req, res) { - return publish(req, res, io); - }); - }; - -}).call(this); diff --git a/controller/subscribe.js b/controller/subscribe.js deleted file mode 100644 index 87db083..0000000 --- a/controller/subscribe.js +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var subscribe; - - subscribe = function(req, res) { - return res.send('subscribe'); - }; - - module.exports = function(app) { - return app.get('/sub', subscribe); - }; - -}).call(this); diff --git a/makefile b/makefile index c1a88af..12c0449 100644 --- a/makefile +++ b/makefile @@ -9,11 +9,17 @@ package: @echo copy package.json @cp package.json build + + push113: package + @echo make config file + @mv build/config.113.js build/config.js @echo git push origin master @cd build ; git add ./ ; git commit -a -m 'new changes' ; git push origin master push61: package + @echo make config file + @mv build/config.61.js build/config.js @echo git push 61 master @cd build ; git add ./ ; git commit -a -m 'new changes' ; git push 61 master diff --git a/server.js b/server.js deleted file mode 100644 index b92f788..0000000 --- a/server.js +++ /dev/null @@ -1,23 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - "use strict"; - - var app, configs, express, io; - - express = require('express'); - - configs = require('./config'); - - app = express.createServer(); - - app.listen(configs.port); - - io = require('socket.io').listen(app); - - require('./socket')(io); - - require('./setup')(app, express, io); - - require('./controller')(app, io); - -}).call(this); diff --git a/setup.js b/setup.js deleted file mode 100644 index dcd5b59..0000000 --- a/setup.js +++ /dev/null @@ -1,26 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - var middleware; - - middleware = require('./tools/middleware'); - - module.exports = function(app, express, io) { - app.use(express.bodyParser()); - app.use(express.cookieParser()); - app.use(express.session({ - secret: "honey pusher" - })); - app.enable('view cache'); - app.use(express["static"](__dirname + '/static')); - app.set('views', __dirname + '/view'); - app.set('view engine', 'jade'); - app.set('view options', { - cookiesign: false - }); - app.use(middleware.viewOption); - return io.set('authorization', function(data, accept) { - return accept(null, true); - }); - }; - -}).call(this); diff --git a/socket/index.js b/socket/index.js deleted file mode 100644 index 6261999..0000000 --- a/socket/index.js +++ /dev/null @@ -1,73 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - "use strict"; - - var S, onlines, pushOnlines, _; - - _ = require('underscore')._; - - S = require('string'); - - onlines = { - users: {}, - sessions: {} - }; - - pushOnlines = function(_s) { - return _s.broadcast.emit('onlines', _.keys(onlines.users)); - }; - - module.exports = function(io) { - io.set('log level', 1); - return io.sockets.on('connection', function(socket) { - var ip, sessions, users; - users = onlines.users; - sessions = onlines.sessions; - console.log(socket.handshake.address); - ip = socket.handshake.address.address; - pushOnlines(socket); - socket.on('client-session', function(data) { - var channel, key, user, _i, _len, _ref, _results; - //key = "" + data.project + ":" + data.key + ":" + ip; - key = "" + data.project + ":" + data.key; - sessions[socket.id] = key; - user = users[key]; - if (user) { - user.push(socket.id); - user = _.uniq(user); - } else { - users[key] = [socket.id]; - socket.broadcast.emit('add_user', key); - pushOnlines(socket); - } - socket.join(key); - socket.join(data.project); - if (data.channels) { - _ref = data.channels.split(','); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - channel = _ref[_i]; - channel = S(channel).trim().s; - _results.push(socket.join("" + data.project + ":channel:" + channel)); - } - return _results; - } - }); - return socket.on('disconnect', function(_user) { - var key, user; - key = sessions[socket.id]; - user = users[key]; - delete sessions[socket.id]; - if (user) { - user = _.without(user, socket.id); - } - if (!user || !user.length) { - delete users[key]; - socket.broadcast.emit('remove_user', key); - return pushOnlines(socket); - } - }); - }); - }; - -}).call(this); diff --git a/src/socket/index.coffee b/src/socket/index.coffee index 939edf8..11e23e4 100644 --- a/src/socket/index.coffee +++ b/src/socket/index.coffee @@ -21,7 +21,8 @@ module.exports = (io)-> pushOnlines socket socket.on 'client-session', (data)-> - key = "#{ data.project }:#{ data.key }:#{ ip }" + #key = "#{ data.project }:#{ data.key }:#{ ip }" + key = "#{ data.project }:#{ data.key }" sessions[socket.id] = key user = users[key] diff --git a/tools/middleware.js b/tools/middleware.js deleted file mode 100644 index 1abe7fe..0000000 --- a/tools/middleware.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - - exports.viewOption = function(req, res, next) { - return next(); - }; - -}).call(this); diff --git a/tools/ping.js b/tools/ping.js deleted file mode 100644 index 273865e..0000000 --- a/tools/ping.js +++ /dev/null @@ -1,6 +0,0 @@ -// Generated by CoffeeScript 1.3.3 -(function() { - - - -}).call(this); diff --git a/view/index.jade b/view/index.jade deleted file mode 100644 index 3e414b3..0000000 --- a/view/index.jade +++ /dev/null @@ -1,28 +0,0 @@ -!!!5 -html - head - title Honey Pusher - //script(src="http://honey.hunantv.com/i/config.js") - script(src="http://honey.hunantv.com/i/js/honey.source.js") - body - h1 Honey Pusher Demo (UID: #{ id }) - script - online = 0; - honey.go('lib_jquery, lib_socket, mod_pusher', function() { - honey.pusher({ - socket: '#{ pusher }', - data: {project: 'ihunantv', key: '#{ id }', channels: 'server, movie, music'} - }, function(socket) { - - socket.on('subscribe', function(msg) { - //$('

').html(msg.channel +'send a msg:'+ msg.msg); - $('

').html(msg.channel +'send a msg:'+ msg.msg).appendTo('body'); - //console.log(msg); - }); - - socket.on('msg', function(msg) { - $('

').html(msg.channel +'send a msg:'+ msg.msg); - }); - - }); - }); diff --git a/view/index2.jade b/view/index2.jade deleted file mode 100644 index 77e7b34..0000000 --- a/view/index2.jade +++ /dev/null @@ -1,30 +0,0 @@ -!!!5 -html - head - title Honey Pusher - script(src="http://honey.hunantv.com/src/config.js") - script(src="http://honey.hunantv.com/src/honey.source.js") - body - h1 Honey Pusher 2 - script - online = 0; - honey.go('lib_jquery, lib_socket, mod_pusher', function() { - - honey.pusher({ - socket: '#{ pusher }', - data: {project: 'ihunantv', key: '2', channels: 'server, tv'} - }, function(socket) { - - socket.on('subscribe', function(msg) { - //console.log(msg); - $('

').html(msg.channel +'send a msg:'+ msg.msg).appendTo('body'); - }); - - socket.on('msg', function(msg) { - $('

').html(msg.channel +'send a msg:'+ msg.msg); - //console.log(msg); - }); - - }); - - }); diff --git a/view/index3.jade b/view/index3.jade deleted file mode 100644 index b98bce5..0000000 --- a/view/index3.jade +++ /dev/null @@ -1,29 +0,0 @@ -!!!5 -html - head - title Honey Pusher - script(src="http://honey.hunantv.com/src/config.js") - script(src="http://honey.hunantv.com/src/honey.source.js") - body - h1 Honey Pusher 3 - script - online = 0; - honey.go('lib_jquery, lib_socket, mod_pusher', function() { - - honey.pusher({ - socket: '#{ pusher }', - data: {project: 'ihunantv', key: '3', channels: 'server, tv, movie'} - }, function(socket) { - - socket.on('subscribe', function(msg) { - //$('

').html(msg.channel +'send a msg:'+ msg.msg); - $('

').html(msg.channel +'send a msg:'+ msg.msg).appendTo('body'); - }); - - socket.on('msg', function(msg) { - console.log(msg); - }); - - }); - - }); diff --git a/view/online.jade b/view/online.jade deleted file mode 100644 index e72938b..0000000 --- a/view/online.jade +++ /dev/null @@ -1,38 +0,0 @@ -!!!5 -html - head - title Honey Pusher - //script(src="http://honey.hunantv.com/i/config.js") - script(src="http://honey.hunantv.com/i/js/honey.source.js") - style - #users { - font-size: 18px; - font-weight: 800; - color: blue; - } - body - h1 Honey Pusher Onlines - h3 Online users - #users - h3 logs - #logs - script - online = 0; - honey.go('lib_jquery, lib_socket', function() { - var socket = io.connect('http://honey.hunantv.com:8888'); - socket.on('onlines', function(_users) { - $('#users').html(_users.join(',')); - }); - socket.on('add_user', function(_user) { - $('

').html(_user +' is online.').appendTo('#logs'); - }); - socket.on('remove_user', function(_user) { - $('

').html(_user +' is offline.') - .css('color', 'red').appendTo('#logs'); - }); - socket.on('connect', function() { - $('

').html(socket.socket.sessionid +' is online.[self]').appendTo('body'); - //console.log(socket.socket.sessionid); - }); - - });