index.js 1.7 KB

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