app.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var static = require('node-static'),
  2. http = require('http'),
  3. util = require('util'),
  4. url = require('url'),
  5. fs = require('fs');
  6. var fileServer = new static.Server('./public');
  7. var server = http.createServer(function (req, res) {
  8. var pathname = url.parse(req.url).pathname;
  9. //console.log('pathname: '+pathname);
  10. req.addListener('end', function () {
  11. fileServer.serve(req, res);
  12. }).resume();
  13. }).listen(process.env.PORT || 8888, function() {
  14. console.log('Listening at: http://localhost:' + (process.env.PORT || 8888));
  15. });
  16. var io = require('socket.io').listen(server, { log: false });
  17. io.sockets.on('connection', function(socket){
  18. socket.on('message', function(message){
  19. socket.broadcast.emit('message', message);
  20. });
  21. socket.on('key down', function(data){
  22. socket.broadcast.emit('key down', data);
  23. });
  24. socket.on('key up', function(data){
  25. socket.broadcast.emit('key up', data);
  26. });
  27. socket.on('flowtime minimap complete', function(data){
  28. socket.broadcast.emit('flowtime minimap complete', data);
  29. });
  30. socket.on('navigate', function(data){
  31. socket.broadcast.emit('navigate', data);
  32. });
  33. socket.on('disconnect', function(){
  34. console.log("Connection " + socket.id + " terminated.");
  35. });
  36. });