-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·80 lines (62 loc) · 2.28 KB
/
Copy pathindex.js
File metadata and controls
executable file
·80 lines (62 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let http = require('http');
let express = require('express');
let fs = require('fs');
let mustache = require('mustache');
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const argv = yargs(hideBin(process.argv)).argv
const main = () => {
let app = express();
let server = http.createServer(app);
let io = require('socket.io')(server);
let opts = {
hostname: argv.hostname,
port: argv.port || 1947,
revealDir: argv.revealDir || process.cwd(),
presentationDir: argv.presentationDir || '.',
presentationIndex: argv.presentationIndex || '/index.html',
pluginDir: __dirname
};
io.on( 'connection', socket => {
socket.on( 'new-subscriber', data => {
socket.broadcast.emit( 'new-subscriber', data );
});
socket.on( 'statechanged', data => {
delete data.state.overview;
socket.broadcast.emit( 'statechanged', data );
});
socket.on( 'statechanged-speaker', data => {
delete data.state.overview;
socket.broadcast.emit( 'statechanged-speaker', data );
});
});
app.use( express.static( opts.revealDir ) );
app.use( express.static( opts.presentationDir ) );
app.get('/', ( req, res ) => {
res.writeHead( 200, { 'Content-Type': 'text/html' } );
fs.createReadStream( opts.presentationDir + opts.presentationIndex ).pipe( res );
});
app.get( '/notes/:socketId', ( req, res ) => {
fs.readFile( opts.pluginDir + '/index.html', ( err, data ) => {
res.send( mustache.render( data.toString(), {
socketId : req.params.socketId
}));
});
});
// Actually listen
if(opts.hostname) {
server.listen( opts.port || null, opts.hostname);
} else {
server.listen( opts.port || null);
}
let brown = '\033[33m',
green = '\033[32m',
reset = '\033[0m';
let slidesLocation = 'http://' + (opts.hostname ? opts.hostname : 'localhost') + ( opts.port ? ( ':' + opts.port ) : '' );
console.log( brown + 'reveal.js - Speaker Notes' + reset );
console.log( '1. Open the slides at ' + green + slidesLocation + reset );
console.log( `Or alternatively with QR code: ${green + slidesLocation}?qr=true${reset}`);
console.log( '2. Click on the link in your JS console to go to the notes page' );
console.log( '3. Advance through your slides and your notes will advance automatically' );
}
module.exports = main;