index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 app = express.createServer();
  7. var staticDir = express.static;
  8. io = io.listen(app);
  9. var opts = {
  10. port : 1947,
  11. baseDir : __dirname + '/../../'
  12. };
  13. io.sockets.on('connection', function(socket) {
  14. socket.on('slidechanged', function(slideData) {
  15. socket.broadcast.emit('slidedata', slideData);
  16. });
  17. });
  18. app.configure(function() {
  19. [ 'css', 'assets', 'js', 'lib' ].forEach(function(dir) {
  20. app.use('/' + dir, staticDir(opts.baseDir + dir));
  21. });
  22. });
  23. app.get("/", function(req, res) {
  24. fs.createReadStream(opts.baseDir + '/index.html').pipe(res);
  25. });
  26. app.get("/notes/:socketId", function(req, res) {
  27. fs.readFile(opts.baseDir + 'lib/slidenotes/notes.html', function(err, data) {
  28. res.send(Mustache.to_html(data.toString(), {
  29. socketId : req.params.socketId
  30. }));
  31. });
  32. // fs.createReadStream(opts.baseDir + 'slidenotes/notes.html').pipe(res);
  33. });
  34. // Actually listen
  35. app.listen(opts.port || null);
  36. console.log("Open the slides at http://localhost" + (opts.port ? (':' + opts.port) : '') + " and look for a link to the speaker notes in the console");
  37. console.log("Advance through your slides and your notes will advance automatically");