JJ Allaire | efa6ad4 | 2016-01-30 13:12:05 -0500 | [diff] [blame] | 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 | |
| 8 | var app = express(); |
| 9 | var staticDir = express.static; |
| 10 | var server = http.createServer(app); |
| 11 | |
| 12 | io = io(server); |
| 13 | |
| 14 | var opts = { |
| 15 | port : 1947, |
| 16 | baseDir : __dirname + '/../../' |
| 17 | }; |
| 18 | |
| 19 | io.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 | |
| 39 | app.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 | |
| 46 | app.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 |
| 57 | server.listen( opts.port || null ); |
| 58 | |
| 59 | var brown = '\033[33m', |
| 60 | green = '\033[32m', |
| 61 | reset = '\033[0m'; |
| 62 | |
| 63 | var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : '' ); |
| 64 | |
| 65 | console.log( brown + 'reveal.js - Speaker Notes' + reset ); |
| 66 | console.log( '1. Open the slides at ' + green + slidesLocation + reset ); |
| 67 | console.log( '2. Click on the link your JS console to go to the notes page' ); |
| 68 | console.log( '3. Advance through your slides and your notes will advance automatically' ); |