Skip to content

Commit 4c5b15d

Browse files
committed
update server side notes to match client side plugin
1 parent 54e2567 commit 4c5b15d

3 files changed

Lines changed: 392 additions & 160 deletions

File tree

plugin/notes-server/client.js

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,28 @@
11
(function() {
2+
23
// don't emit events from inside the previews themselves
34
if( window.location.search.match( /receiver/gi ) ) { return; }
45

5-
var socket = io.connect( window.location.origin );
6-
var socketId = Math.random().toString().slice( 2 );
6+
var socket = io.connect( window.location.origin ),
7+
socketId = Math.random().toString().slice( 2 );
78

89
console.log( 'View slide notes at ' + window.location.origin + '/notes/' + socketId );
910

1011
window.open( window.location.origin + '/notes/' + socketId, 'notes-' + socketId );
1112

12-
// Fires when a fragment is shown
13-
Reveal.addEventListener( 'fragmentshown', function( event ) {
14-
var fragmentData = {
15-
fragment : 'next',
16-
socketId : socketId
17-
};
18-
socket.emit('fragmentchanged', fragmentData);
19-
} );
13+
/**
14+
* Posts the current slide data to the notes window
15+
*/
16+
function post() {
2017

21-
// Fires when a fragment is hidden
22-
Reveal.addEventListener( 'fragmenthidden', function( event ) {
23-
var fragmentData = {
24-
fragment : 'previous',
25-
socketId : socketId
26-
};
27-
socket.emit( 'fragmentchanged', fragmentData );
28-
} );
29-
30-
// Fires when slide is changed
31-
Reveal.addEventListener( 'slidechanged', function( event ) {
32-
var nextindexh,
33-
nextindexv,
34-
slideElement = event.currentSlide,
18+
var slideElement = Reveal.getCurrentSlide(),
3519
notesElement = slideElement.querySelector( 'aside.notes' );
3620

37-
if( slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION' ) {
38-
nextindexh = event.indexh;
39-
nextindexv = event.indexv + 1;
40-
} else {
41-
nextindexh = event.indexh + 1;
42-
nextindexv = 0;
43-
}
44-
4521
var messageData = {
46-
notes : '',
47-
indexh : event.indexh,
48-
indexv : event.indexv,
49-
nextindexh : nextindexh,
50-
nextindexv : nextindexv,
51-
socketId : socketId,
52-
markdown : false
22+
notes: '',
23+
markdown: false,
24+
socketId: socketId,
25+
state: Reveal.getState()
5326
};
5427

5528
// Look for notes defined in a slide attribute
@@ -63,6 +36,20 @@
6336
messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string';
6437
}
6538

66-
socket.emit( 'slidechanged', messageData );
67-
} );
39+
socket.emit( 'state', messageData );
40+
41+
}
42+
43+
// Monitor events that trigger a change in state
44+
Reveal.addEventListener( 'slidechanged', post );
45+
Reveal.addEventListener( 'fragmentshown', post );
46+
Reveal.addEventListener( 'fragmenthidden', post );
47+
Reveal.addEventListener( 'overviewhidden', post );
48+
Reveal.addEventListener( 'overviewshown', post );
49+
Reveal.addEventListener( 'paused', post );
50+
Reveal.addEventListener( 'resumed', post );
51+
52+
// Post the initial state
53+
post();
54+
6855
}());

plugin/notes-server/index.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,49 @@ var opts = {
1414
baseDir : __dirname + '/../../'
1515
};
1616

17-
io.sockets.on('connection', function(socket) {
18-
socket.on('slidechanged', function(slideData) {
19-
socket.broadcast.emit('slidedata', slideData);
20-
});
21-
socket.on('fragmentchanged', function(fragmentData) {
22-
socket.broadcast.emit('fragmentdata', fragmentData);
17+
io.sockets.on( 'connection', function( socket ) {
18+
19+
socket.on( 'state', function( state ) {
20+
socket.broadcast.emit( 'state', state );
2321
});
22+
2423
});
2524

26-
app.configure(function() {
27-
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach(function(dir) {
28-
app.use('/' + dir, staticDir(opts.baseDir + dir));
25+
app.configure( function() {
26+
27+
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
28+
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
2929
});
30+
3031
});
3132

32-
app.get("/", function(req, res) {
33-
res.writeHead(200, {'Content-Type': 'text/html'});
34-
fs.createReadStream(opts.baseDir + '/index.html').pipe(res);
33+
app.get('/', function( req, res ) {
34+
35+
res.writeHead( 200, { 'Content-Type': 'text/html' } );
36+
fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res );
37+
3538
});
3639

37-
app.get("/notes/:socketId", function(req, res) {
40+
app.get( '/notes/:socketId', function( req, res ) {
3841

39-
fs.readFile(opts.baseDir + 'plugin/notes-server/notes.html', function(err, data) {
40-
res.send(Mustache.to_html(data.toString(), {
42+
fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) {
43+
res.send( Mustache.to_html( data.toString(), {
4144
socketId : req.params.socketId
4245
}));
4346
});
44-
// fs.createReadStream(opts.baseDir + 'notes-server/notes.html').pipe(res);
47+
4548
});
4649

4750
// Actually listen
48-
app.listen(opts.port || null);
51+
app.listen( opts.port || null );
4952

5053
var brown = '\033[33m',
5154
green = '\033[32m',
5255
reset = '\033[0m';
5356

54-
var slidesLocation = "http://localhost" + ( opts.port ? ( ':' + opts.port ) : '' );
57+
var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : '' );
5558

56-
console.log( brown + "reveal.js - Speaker Notes" + reset );
57-
console.log( "1. Open the slides at " + green + slidesLocation + reset );
58-
console.log( "2. Click on the link your JS console to go to the notes page" );
59-
console.log( "3. Advance through your slides and your notes will advance automatically" );
59+
console.log( brown + 'reveal.js - Speaker Notes' + reset );
60+
console.log( '1. Open the slides at ' + green + slidesLocation + reset );
61+
console.log( '2. Click on the link your JS console to go to the notes page' );
62+
console.log( '3. Advance through your slides and your notes will advance automatically' );

0 commit comments

Comments
 (0)