blob: b95f07188c81e5e8f2a324998140ecbe8ecfea45 [file] [log] [blame]
JJ Allaireefa6ad42016-01-30 13:12:05 -05001var http = require('http');
2var express = require('express');
3var fs = require('fs');
4var io = require('socket.io');
JJ Allaireefa6ad42016-01-30 13:12:05 -05005var Mustache = require('mustache');
6
7var app = express();
8var staticDir = express.static;
9var server = http.createServer(app);
10
11io = io(server);
12
13var opts = {
14 port : 1947,
15 baseDir : __dirname + '/../../'
16};
17
18io.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 ) {
Bruce's Thinkpad8b73dcf2016-07-14 00:12:43 +080025 delete data.state.overview;
JJ Allaireefa6ad42016-01-30 13:12:05 -050026 socket.broadcast.emit( 'statechanged', data );
27 });
28
29 socket.on( 'statechanged-speaker', function( data ) {
Bruce's Thinkpad8b73dcf2016-07-14 00:12:43 +080030 delete data.state.overview;
JJ Allaireefa6ad42016-01-30 13:12:05 -050031 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
40app.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
47app.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
58server.listen( opts.port || null );
59
60var brown = '\033[33m',
61 green = '\033[32m',
62 reset = '\033[0m';
63
64var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : '' );
65
66console.log( brown + 'reveal.js - Speaker Notes' + reset );
67console.log( '1. Open the slides at ' + green + slidesLocation + reset );
Bruce's Thinkpad8b73dcf2016-07-14 00:12:43 +080068console.log( '2. Click on the link in your JS console to go to the notes page' );
JJ Allaireefa6ad42016-01-30 13:12:05 -050069console.log( '3. Advance through your slides and your notes will advance automatically' );