Skip to content

Commit

Permalink
v0.0.1 - Working fine.
Browse files Browse the repository at this point in the history
  • Loading branch information
daraosn committed Jan 25, 2012
0 parents commit a4eeb19
Show file tree
Hide file tree
Showing 452 changed files with 47,201 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>pusher</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.aptana.ide.core.unifiedBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.aptana.projects.webnature</nature>
</natures>
</projectDescription>
120 changes: 120 additions & 0 deletions app.js
@@ -0,0 +1,120 @@
global.dump = function(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];

if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Stings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}

global.debug=function(params,alive) {
console.log(params);
if(!alive) process.exit(0);
}

/**
* Module dependencies.
*/

var express = require('express')
, routes = require('./routes')

var app = module.exports = express.createServer();
var io = require('socket.io').listen(app);

configure();

var channels=[];

// Sockets
global.password = "bGINGS/(ADNfg78GASIMDbkASbj";
var mySocket=io.of('/puller').on('connection', function(socket) {
//console.log('*** CLIENT CONNECTED ***')
//socket.emit('log','welcome')
var currentChannel;
socket.on('subscribe', function(channel) {
if(channel) {
if(currentChannel) {
socket.leave(currentChannel);
//socket.emit('log','left channel: '+currentChannel);
}
socket.join(channel);
currentChannel=channel;
socket.emit('subscribed', channel);
//socket.emit('log','joined channel: '+channel)
}
});
socket.on('run', function(password, channel, command) {
socketRun(password, channel, command)
});
});

function socketRun(password, channel, command) {
if(password==global.password) {
//socket.emit('log','authorized')
if(channel) {
mySocket.to(channel).emit('run', command);
//socket.emit('log','broadcasted to channel ('+channel+'): '+command);
} else {
mySocket.emit('run', command);
//socket.emit('log','broadcasted to all: '+command);
}
return true;
} else {
//socket.emit('log','not authorized')
return false;
}
}

app.post('/puller/run', function(req, res) {
var password=req.body.password;
var channel=req.body.channel;
var command=req.body.command;
var result=socketRun(password, channel, command);
res.send(JSON.stringify({'success':result, 'channel': channel, 'command': command}));
});


function configure() {
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
// Disable /public/monitor.html on production
app.get('/example.html', function(req, res) {
res.redirect('/');
});
app.use(express.errorHandler());
});
}


app.listen(8080);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
1 change: 1 addition & 0 deletions node_modules/.bin/express

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jade

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/express/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a4eeb19

Please sign in to comment.