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