diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2014-05-04 10:10:21 +0200 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2014-05-04 10:10:21 +0200 |
commit | 3eb7038a153b12245cffbc840a727a764d82b333 (patch) | |
tree | 9e514ea03995fd2a988f1996f37692dbcf6448f2 | |
parent | 5e85f02eb1596d0c5a71aa35430c0914e0b6d35a (diff) | |
download | perl-software-in-gnu-guix-3eb7038a153b12245cffbc840a727a764d82b333.tar perl-software-in-gnu-guix-3eb7038a153b12245cffbc840a727a764d82b333.tar.gz |
sync server-side speaker notes after notes window opens
-rw-r--r-- | plugin/notes-server/client.js | 7 | ||||
-rw-r--r-- | plugin/notes-server/index.js | 8 | ||||
-rw-r--r-- | plugin/notes-server/notes.html | 16 |
3 files changed, 26 insertions, 5 deletions
diff --git a/plugin/notes-server/client.js b/plugin/notes-server/client.js index f7ecfa2..628586f 100644 --- a/plugin/notes-server/client.js +++ b/plugin/notes-server/client.js @@ -36,10 +36,15 @@ messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string'; } - socket.emit( 'state', messageData ); + socket.emit( 'statechanged', messageData ); } + // When a new notes window connects, post our current state + socket.on( 'connect', function( data ) { + post(); + } ); + // Monitor events that trigger a change in state Reveal.addEventListener( 'slidechanged', post ); Reveal.addEventListener( 'fragmentshown', post ); diff --git a/plugin/notes-server/index.js b/plugin/notes-server/index.js index b6779d3..df917f1 100644 --- a/plugin/notes-server/index.js +++ b/plugin/notes-server/index.js @@ -16,8 +16,12 @@ var opts = { io.sockets.on( 'connection', function( socket ) { - socket.on( 'state', function( state ) { - socket.broadcast.emit( 'state', state ); + socket.on( 'connect', function( data ) { + socket.broadcast.emit( 'connect', data ); + }); + + socket.on( 'statechanged', function( data ) { + socket.broadcast.emit( 'statechanged', data ); }); }); diff --git a/plugin/notes-server/notes.html b/plugin/notes-server/notes.html index 4ff48f1..72d0317 100644 --- a/plugin/notes-server/notes.html +++ b/plugin/notes-server/notes.html @@ -187,7 +187,7 @@ var socket = io.connect( window.location.origin ), socketId = '{{socketId}}'; - socket.on( 'state', function( data ) { + socket.on( 'statechanged', function( data ) { // ignore data from sockets that aren't ours if( data.socketId !== socketId ) { return; } @@ -206,6 +206,18 @@ } ); + window.addEventListener( 'message', function( event ) { + + var data = JSON.parse( event.data ); + + if( data && data.namespace === 'reveal' ) { + if( /ready/.test( data.eventName ) ) { + socket.emit( 'connect', { socketId: socketId } ); + } + } + + } ); + /** * Called when the main window sends an updated state. */ @@ -266,7 +278,7 @@ ].join( '&' ); var hash = '#/' + data.state.indexh + '/' + data.state.indexv; - var currentURL = '/?' + params + hash; + var currentURL = '/?' + params + '&postMessageEvents=true' + hash; var upcomingURL = '/?' + params + '&controls=false' + hash; currentSlide = document.createElement( 'iframe' ); |