index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var http = require('http');
  2. var express = require('express');
  3. var fs = require('fs');
  4. var io = require('socket.io');
  5. var Mustache = require('mustache');
  6. var app = express();
  7. var staticDir = express.static;
  8. var server = http.createServer(app);
  9. io = io(server);
  10. var opts = {
  11. port : 1947,
  12. baseDir : __dirname + '/../../'
  13. };
  14. io.on( 'connection', function( socket ) {
  15. socket.on( 'new-subscriber', function( data ) {
  16. socket.broadcast.emit( 'new-subscriber', data );
  17. });
  18. socket.on( 'statechanged', function( data ) {
  19. delete data.state.overview;
  20. socket.broadcast.emit( 'statechanged', data );
  21. });
  22. socket.on( 'statechanged-speaker', function( data ) {
  23. delete data.state.overview;
  24. socket.broadcast.emit( 'statechanged-speaker', data );
  25. });
  26. });
  27. [ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
  28. app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
  29. });
  30. app.get('/', function( req, res ) {
  31. res.writeHead( 200, { 'Content-Type': 'text/html' } );
  32. fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res );
  33. });
  34. app.get( '/notes/:socketId', function( req, res ) {
  35. fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) {
  36. res.send( Mustache.to_html( data.toString(), {
  37. socketId : req.params.socketId
  38. }));
  39. });
  40. });
  41. // Actually listen
  42. server.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 in your JS console to go to the notes page' );
  50. console.log( '3. Advance through your slides and your notes will advance automatically' );