index.js 1.5 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 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( 'state', function( state ) {
  15. socket.broadcast.emit( 'state', state );
  16. });
  17. });
  18. app.configure( function() {
  19. [ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
  20. app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
  21. });
  22. });
  23. app.get('/', function( req, res ) {
  24. res.writeHead( 200, { 'Content-Type': 'text/html' } );
  25. fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res );
  26. });
  27. app.get( '/notes/:socketId', function( req, res ) {
  28. fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) {
  29. res.send( Mustache.to_html( data.toString(), {
  30. socketId : req.params.socketId
  31. }));
  32. });
  33. });
  34. // Actually listen
  35. app.listen( opts.port || null );
  36. var brown = '\033[33m',
  37. green = '\033[32m',
  38. reset = '\033[0m';
  39. var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : '' );
  40. console.log( brown + 'reveal.js - Speaker Notes' + reset );
  41. console.log( '1. Open the slides at ' + green + slidesLocation + reset );
  42. console.log( '2. Click on the link your JS console to go to the notes page' );
  43. console.log( '3. Advance through your slides and your notes will advance automatically' );