index.js 1.7 KB

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