index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var express = require('express');
  2. var fs = require('fs');
  3. var io = require('socket.io');
  4. var _ = require('underscore');
  5. var Mustache = require('mustache');
  6. var crypto = require('crypto');
  7. var app = express.createServer();
  8. var staticDir = express.static;
  9. io = io.listen(app);
  10. var opts = {
  11. port : 1948,
  12. baseDir : __dirname + '/../../'
  13. };
  14. io.sockets.on('connection', function(socket) {
  15. socket.on('slidechanged', function(slideData) {
  16. console.log(slideData);
  17. if (createHash(slideData.secret) === slideData.socketId) {
  18. slideData.secret = null;
  19. socket.broadcast.emit(slideData.socketId, slideData);
  20. };
  21. });
  22. });
  23. app.configure(function() {
  24. [ 'css', 'js', 'plugin', 'lib' ].forEach(function(dir) {
  25. app.use('/' + dir, staticDir(opts.baseDir + dir));
  26. });
  27. });
  28. app.get("/", function(req, res) {
  29. fs.createReadStream(opts.baseDir + '/index.html').pipe(res);
  30. });
  31. app.get("/token", function(req,res) {
  32. var ts = new Date().getTime();
  33. var rand = Math.floor(Math.random()*9999999);
  34. var secret = ts.toString() + rand.toString();
  35. res.send({secret: secret, socketId: createHash(secret)});
  36. });
  37. var createHash = function(secret) {
  38. var cipher = crypto.createCipher('blowfish', secret);
  39. return(cipher.final('hex'));
  40. };
  41. // Actually listen
  42. app.listen(opts.port || null);
  43. var brown = '\033[33m',
  44. green = '\033[32m',
  45. reset = '\033[0m';
  46. var slidesLocation = "http://localhost" + ( opts.port ? ( ':' + opts.port ) : '' );
  47. console.log( brown + "reveal.js - Speaker Notes" + reset );
  48. console.log( "1. Open the slides at " + green + slidesLocation + reset );
  49. console.log( "2. Click on the link your JS console to go to the notes page" );
  50. console.log( "3. Advance through your slides and your notes will advance automatically" );