index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var http = require('http');
  2. var express = require('express');
  3. var fs = require('fs');
  4. var io = require('socket.io');
  5. var _ = require('underscore');
  6. var Mustache = require('mustache');
  7. var app = express();
  8. var staticDir = express.static;
  9. var server = http.createServer(app);
  10. io = io(server);
  11. var opts = {
  12. port : 1947,
  13. baseDir : __dirname + '/../../'
  14. };
  15. io.on( 'connection', function( socket ) {
  16. socket.on( 'new-subscriber', function( data ) {
  17. socket.broadcast.emit( 'new-subscriber', data );
  18. });
  19. socket.on( 'statechanged', function( data ) {
  20. socket.broadcast.emit( 'statechanged', data );
  21. });
  22. socket.on( 'statechanged-speaker', function( data ) {
  23. socket.broadcast.emit( 'statechanged-speaker', data );
  24. });
  25. });
  26. [ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
  27. app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
  28. });
  29. app.get('/', function( req, res ) {
  30. res.writeHead( 200, { 'Content-Type': 'text/html' } );
  31. fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res );
  32. });
  33. app.get( '/notes/:socketId', function( req, res ) {
  34. fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) {
  35. res.send( Mustache.to_html( data.toString(), {
  36. socketId : req.params.socketId
  37. }));
  38. });
  39. });
  40. // Actually listen
  41. server.listen( opts.port || null );
  42. var brown = '\033[33m',
  43. green = '\033[32m',
  44. reset = '\033[0m';
  45. var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : '' );
  46. console.log( brown + 'reveal.js - Speaker Notes' + reset );
  47. console.log( '1. Open the slides at ' + green + slidesLocation + reset );
  48. console.log( '2. Click on the link your JS console to go to the notes page' );
  49. console.log( '3. Advance through your slides and your notes will advance automatically' );