From 4c5b15d0b92cae5828df5d39c5e5a51e68242752 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sun, 4 May 2014 09:32:00 +0200 Subject: update server side notes to match client side plugin --- plugin/notes-server/notes.html | 436 ++++++++++++++++++++++++++++++++--------- 1 file changed, 339 insertions(+), 97 deletions(-) (limited to 'plugin/notes-server/notes.html') diff --git a/plugin/notes-server/notes.html b/plugin/notes-server/notes.html index 25d1a62..4ff48f1 100644 --- a/plugin/notes-server/notes.html +++ b/plugin/notes-server/notes.html @@ -3,8 +3,6 @@ - - reveal.js - Slide Notes -
- -
+
+
UPCOMING:
+
+
+

Time Click to Reset

+
+ 0:00 AM +
+
+ 00:00:00 +
+
+
-
- - UPCOMING: +
-
-- cgit v1.2.3 From 3eb7038a153b12245cffbc840a727a764d82b333 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sun, 4 May 2014 10:10:21 +0200 Subject: sync server-side speaker notes after notes window opens --- plugin/notes-server/client.js | 7 ++++++- plugin/notes-server/index.js | 8 ++++++-- plugin/notes-server/notes.html | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) (limited to 'plugin/notes-server/notes.html') 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' ); -- cgit v1.2.3 From b16bc6fc2e948dedf597004fb99e69d4042daa47 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 29 Sep 2015 10:07:21 +0200 Subject: speaker notes work with socket.io 1.0 #1375 --- plugin/notes-server/client.js | 2 +- plugin/notes-server/index.js | 22 ++++++++++------------ plugin/notes-server/notes.html | 16 ++++++++++------ 3 files changed, 21 insertions(+), 19 deletions(-) (limited to 'plugin/notes-server/notes.html') diff --git a/plugin/notes-server/client.js b/plugin/notes-server/client.js index 628586f..719b495 100644 --- a/plugin/notes-server/client.js +++ b/plugin/notes-server/client.js @@ -41,7 +41,7 @@ } // When a new notes window connects, post our current state - socket.on( 'connect', function( data ) { + socket.on( 'new-subscriber', function( data ) { post(); } ); diff --git a/plugin/notes-server/index.js b/plugin/notes-server/index.js index df917f1..75838de 100644 --- a/plugin/notes-server/index.js +++ b/plugin/notes-server/index.js @@ -1,23 +1,25 @@ +var http = require('http'); var express = require('express'); var fs = require('fs'); var io = require('socket.io'); var _ = require('underscore'); var Mustache = require('mustache'); -var app = express.createServer(); +var app = express(); var staticDir = express.static; +var server = http.createServer(app); -io = io.listen(app); +io = io(server); var opts = { port : 1947, baseDir : __dirname + '/../../' }; -io.sockets.on( 'connection', function( socket ) { +io.on( 'connection', function( socket ) { - socket.on( 'connect', function( data ) { - socket.broadcast.emit( 'connect', data ); + socket.on( 'new-subscriber', function( data ) { + socket.broadcast.emit( 'new-subscriber', data ); }); socket.on( 'statechanged', function( data ) { @@ -26,12 +28,8 @@ io.sockets.on( 'connection', function( socket ) { }); -app.configure( function() { - - [ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) { - app.use( '/' + dir, staticDir( opts.baseDir + dir ) ); - }); - +[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) { + app.use( '/' + dir, staticDir( opts.baseDir + dir ) ); }); app.get('/', function( req, res ) { @@ -52,7 +50,7 @@ app.get( '/notes/:socketId', function( req, res ) { }); // Actually listen -app.listen( opts.port || null ); +server.listen( opts.port || null ); var brown = '\033[33m', green = '\033[32m', diff --git a/plugin/notes-server/notes.html b/plugin/notes-server/notes.html index 72d0317..d924ad9 100644 --- a/plugin/notes-server/notes.html +++ b/plugin/notes-server/notes.html @@ -195,7 +195,6 @@ if( connected === false ) { connected = true; - setupIframes( data ); setupKeyboard(); setupNotes(); setupTimer(); @@ -206,13 +205,19 @@ } ); + // Load our presentation iframes + setupIframes(); + + // Once the iframes have loaded, emit a signal saying there's + // a new subscriber which will trigger a 'statechanged' + // message to be sent back 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 } ); + socket.emit( 'new-subscriber', { socketId: socketId } ); } } @@ -267,7 +272,7 @@ /** * Creates the preview iframes. */ - function setupIframes( data ) { + function setupIframes() { var params = [ 'receiver', @@ -277,9 +282,8 @@ 'backgroundTransition=none' ].join( '&' ); - var hash = '#/' + data.state.indexh + '/' + data.state.indexv; - var currentURL = '/?' + params + '&postMessageEvents=true' + hash; - var upcomingURL = '/?' + params + '&controls=false' + hash; + var currentURL = '/?' + params + '&postMessageEvents=true'; + var upcomingURL = '/?' + params + '&controls=false'; currentSlide = document.createElement( 'iframe' ); currentSlide.setAttribute( 'width', 1280 ); -- cgit v1.2.3 From 215617740d15f46022dce479f3f412b4d62f44f8 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 9 Nov 2015 16:23:57 +0100 Subject: server notes sync slide changes both ways, fixes #1425 --- plugin/notes-server/client.js | 5 +++++ plugin/notes-server/index.js | 4 ++++ plugin/notes-server/notes.html | 7 +++++++ 3 files changed, 16 insertions(+) (limited to 'plugin/notes-server/notes.html') diff --git a/plugin/notes-server/client.js b/plugin/notes-server/client.js index 719b495..00b277b 100644 --- a/plugin/notes-server/client.js +++ b/plugin/notes-server/client.js @@ -45,6 +45,11 @@ post(); } ); + // When the state changes from inside of the speaker view + socket.on( 'statechanged-speaker', function( data ) { + Reveal.setState( data.state ); + } ); + // 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 75838de..683f064 100644 --- a/plugin/notes-server/index.js +++ b/plugin/notes-server/index.js @@ -26,6 +26,10 @@ io.on( 'connection', function( socket ) { socket.broadcast.emit( 'statechanged', data ); }); + socket.on( 'statechanged-speaker', function( data ) { + socket.broadcast.emit( 'statechanged-speaker', data ); + }); + }); [ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) { diff --git a/plugin/notes-server/notes.html b/plugin/notes-server/notes.html index d924ad9..ad8c719 100644 --- a/plugin/notes-server/notes.html +++ b/plugin/notes-server/notes.html @@ -221,6 +221,13 @@ } } + // Messages sent by reveal.js inside of the current slide preview + if( data && data.namespace === 'reveal' ) { + if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) { + socket.emit( 'statechanged-speaker', { state: data.state } ); + } + } + } ); /** -- cgit v1.2.3