Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Fix tabs in server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
thepatrick committed May 15, 2013
1 parent 709733b commit 4fd4bfb
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,52 @@
var nodeStatic = require('./node-static'),
util = require('util'),
http = require('http'),
io = require('./socket.io'),
file, server, socket, touches = {}, channelListeners = {};
io = require('./socket.io'),
file, server, socket, touches = {}, channelListeners = {};

fileServer = new(nodeStatic.Server)('./public');
server = http.createServer(function (request, response) {
request.addListener('end', function () {
fileServer.serve(request, response);
});
request.addListener('end', function () {
fileServer.serve(request, response);
});
});

server.listen(process.env.PORT || 8080);
socket = io.listen(server);
socket.on('connection', function(client){
var myChosenChannel = null;
util.log("Connected! :)");
client.send({ e: 'welcome' });
var myChosenChannel = null;
util.log("Connected! :)");
client.send({ e: 'welcome' });
client.on('message', function(m){
if(m.e == "canvas") {
myChosenChannel = m.c;
if(touches[myChosenChannel]) {
touches[myChosenChannel].forEach(function(t){
client.send(t);
});
} else {
touches[myChosenChannel] = [];
}
if(!channelListeners[myChosenChannel]) {
channelListeners[myChosenChannel] = [];
}
channelListeners[myChosenChannel].push(client);
return;
}
channelListeners[myChosenChannel].forEach(function(c){
if(c != client) {
c.send(m);
}
});
if(m.e == "clear") {
util.log("Clearing all touches on channel " + myChosenChannel);
touches[myChosenChannel] = [];
} else {
util.log("Touch " + m.e + ' on channel ' + myChosenChannel);
touches[myChosenChannel].push(m);
}
})
if(m.e == "canvas") {
myChosenChannel = m.c;
if(touches[myChosenChannel]) {
touches[myChosenChannel].forEach(function(t){
client.send(t);
});
} else {
touches[myChosenChannel] = [];
}
if(!channelListeners[myChosenChannel]) {
channelListeners[myChosenChannel] = [];
}
channelListeners[myChosenChannel].push(client);
return;
}
channelListeners[myChosenChannel].forEach(function(c){
if(c != client) {
c.send(m);
}
});
if(m.e == "clear") {
util.log("Clearing all touches on channel " + myChosenChannel);
touches[myChosenChannel] = [];
} else {
util.log("Touch " + m.e + ' on channel ' + myChosenChannel);
touches[myChosenChannel].push(m);
}
});
client.on('disconnect', function(){
util.log("Disconnect :(")
})
util.log("Disconnect :(")
});
});

0 comments on commit 4fd4bfb

Please sign in to comment.