github.com/mweagle/Sparta@v1.15.0/docs_source/static/presentations/reveal.js-3.9.2/plugin/notes-server/index.js (about)

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