From ad113ba69db6d700fdb86797e6caf616a9f8a546 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Wed, 22 Apr 2020 15:53:31 +0200 Subject: [PATCH] move notes-server plugin out of reveal.js core --- README.md | 72 ++-- plugin/notes-server/client.js | 65 ---- plugin/notes-server/index.js | 69 ---- plugin/notes-server/notes.html | 585 --------------------------------- 4 files changed, 27 insertions(+), 764 deletions(-) delete mode 100644 plugin/notes-server/client.js delete mode 100644 plugin/notes-server/index.js delete mode 100644 plugin/notes-server/notes.html diff --git a/README.md b/README.md index e2f6e8c0..2f55cd6d 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,9 @@ This project was started and is maintained by [@hakimel](https://github.com/haki - [Speaker Notes](#speaker-notes) - [Share and Print Speaker Notes](#share-and-print-speaker-notes) - [Server Side Speaker Notes](#server-side-speaker-notes) -- [Plugins](#plugins) - [Multiplexing](#multiplexing) - [MathJax](#mathjax) +- [Plugins](#plugins) - [License](#license) #### More reading @@ -1399,54 +1399,12 @@ The pacing timer can be enabled by configuring the `defaultTiming` parameter in ## Server Side Speaker Notes -In some cases it can be desirable to run notes on a separate device from the one you're presenting on. The Node.js-based notes plugin lets you do this using the same note definitions as its client side counterpart. Include the required scripts by adding the following dependencies: - -```javascript -Reveal.initialize({ - // ... - - dependencies: [ - { src: 'socket.io/socket.io.js', async: true }, - { src: 'plugin/notes-server/client.js', async: true } - ] -}); -``` - -Then: - -1. Install [Node.js](http://nodejs.org/) (9.0.0 or later) -2. Run `npm install` -3. Run `node plugin/notes-server` - - -## Plugins - -Plugins should register themselves with reveal.js by calling `Reveal.registerPlugin( MyPlugin )`. Registered plugins _must_ expose a unique `id` property and can optionally expose an `init` function that reveal.js will call to initialize them. - -When reveal.js is booted up via `initialize()`, it will go through all registered plugins and invoke their `init` methods. If the `init` method returns a Promise, reveal.js will wait for that promise to be fulfilled before finishing the startup sequence and firing the [ready](#ready-event) event. Here's an example of a plugin that does some asynchronous work before reveal.js can proceed: - -```javascript -let MyPlugin = { - id: 'myPlugin', - init: deck => new Promise( resolve => setTimeout( resolve, 3000 ) ) -}; -Reveal.initialize({ - dependencies: [ { plugin: MyPlugin } ] -}).then( () => { - console.log( 'Three seconds later...' ) -} ); -``` - -Note that reveal.js will *not* wait for init Promise fulfillment if the plugin is loaded as an [async dependency](#dependencies). If the plugin's init method does _not_ return a Promise, the plugin is considered ready right away and will not hold up the reveal.js startup sequence. - -### Retrieving Plugins - -If you want to check if a specific plugin is registered you can use the `Reveal.hasPlugin` method and pass in a plugin ID, for example: `Reveal.hasPlugin( 'myPlugin' )`. If you want to retrieve a plugin instance you can use `Reveal.getPlugin( 'myPlugin' )`. +In some cases it can be desirable to run notes on a separate device from the one you're presenting on. The Node.js-based notes plugin lets you do this using the same note definitions as its client side counterpart. See . ## Multiplexing -The multiplex plugin allows your audience to follow the slides of the presentation you are controlling on their own phone, tablet or laptop. As of 4.0.0 this plugin has moved to its own repo at ; +The multiplex plugin allows your audience to follow the slides of the presentation you are controlling on their own phone, tablet or laptop. As of 4.0.0 this plugin has moved to its own repo at . ## MathJax @@ -1483,6 +1441,30 @@ If you want to include math inside of a presentation written in Markdown you nee `$$ J(\theta_0,\theta_1) = \sum_{i=0} $$` ``` +## Plugins + +Plugins should register themselves with reveal.js by calling `Reveal.registerPlugin( MyPlugin )`. Registered plugins _must_ expose a unique `id` property and can optionally expose an `init` function that reveal.js will call to initialize them. + +When reveal.js is booted up via `initialize()`, it will go through all registered plugins and invoke their `init` methods. If the `init` method returns a Promise, reveal.js will wait for that promise to be fulfilled before finishing the startup sequence and firing the [ready](#ready-event) event. Here's an example of a plugin that does some asynchronous work before reveal.js can proceed: + +```javascript +let MyPlugin = { + id: 'myPlugin', + init: deck => new Promise( resolve => setTimeout( resolve, 3000 ) ) +}; +Reveal.initialize({ + dependencies: [ { plugin: MyPlugin } ] +}).then( () => { + console.log( 'Three seconds later...' ) +} ); +``` + +Note that reveal.js will *not* wait for init Promise fulfillment if the plugin is loaded as an [async dependency](#dependencies). If the plugin's init method does _not_ return a Promise, the plugin is considered ready right away and will not hold up the reveal.js startup sequence. + +### Retrieving Plugins + +If you want to check if a specific plugin is registered you can use the `Reveal.hasPlugin` method and pass in a plugin ID, for example: `Reveal.hasPlugin( 'myPlugin' )`. If you want to retrieve a plugin instance you can use `Reveal.getPlugin( 'myPlugin' )`. + ## License MIT licensed diff --git a/plugin/notes-server/client.js b/plugin/notes-server/client.js deleted file mode 100644 index d877949a..00000000 --- a/plugin/notes-server/client.js +++ /dev/null @@ -1,65 +0,0 @@ -(function() { - - // don't emit events from inside the previews themselves - if( window.location.search.match( /receiver/gi ) ) { return; } - - var socket = io.connect( window.location.origin ), - socketId = Math.random().toString().slice( 2 ); - - console.log( 'View slide notes at ' + window.location.origin + '/notes/' + socketId ); - - window.open( window.location.origin + '/notes/' + socketId, 'notes-' + socketId ); - - /** - * Posts the current slide data to the notes window - */ - function post() { - - var slideElement = Reveal.getCurrentSlide(), - notesElement = slideElement.querySelector( 'aside.notes' ); - - var messageData = { - notes: '', - markdown: false, - socketId: socketId, - state: Reveal.getState() - }; - - // Look for notes defined in a slide attribute - if( slideElement.hasAttribute( 'data-notes' ) ) { - messageData.notes = slideElement.getAttribute( 'data-notes' ); - } - - // Look for notes defined in an aside element - if( notesElement ) { - messageData.notes = notesElement.innerHTML; - messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string'; - } - - socket.emit( 'statechanged', messageData ); - - } - - // When a new notes window connects, post our current state - socket.on( 'new-subscriber', function( data ) { - 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.on( 'slidechanged', post ); - Reveal.on( 'fragmentshown', post ); - Reveal.on( 'fragmenthidden', post ); - Reveal.on( 'overviewhidden', post ); - Reveal.on( 'overviewshown', post ); - Reveal.on( 'paused', post ); - Reveal.on( 'resumed', post ); - - // Post the initial state - post(); - -}()); diff --git a/plugin/notes-server/index.js b/plugin/notes-server/index.js deleted file mode 100644 index b95f0718..00000000 --- a/plugin/notes-server/index.js +++ /dev/null @@ -1,69 +0,0 @@ -var http = require('http'); -var express = require('express'); -var fs = require('fs'); -var io = require('socket.io'); -var Mustache = require('mustache'); - -var app = express(); -var staticDir = express.static; -var server = http.createServer(app); - -io = io(server); - -var opts = { - port : 1947, - baseDir : __dirname + '/../../' -}; - -io.on( 'connection', function( socket ) { - - socket.on( 'new-subscriber', function( data ) { - socket.broadcast.emit( 'new-subscriber', data ); - }); - - socket.on( 'statechanged', function( data ) { - delete data.state.overview; - socket.broadcast.emit( 'statechanged', data ); - }); - - socket.on( 'statechanged-speaker', function( data ) { - delete data.state.overview; - socket.broadcast.emit( 'statechanged-speaker', data ); - }); - -}); - -[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) { - app.use( '/' + dir, staticDir( opts.baseDir + dir ) ); -}); - -app.get('/', function( req, res ) { - - res.writeHead( 200, { 'Content-Type': 'text/html' } ); - fs.createReadStream( opts.baseDir + '/index.html' ).pipe( res ); - -}); - -app.get( '/notes/:socketId', function( req, res ) { - - fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) { - res.send( Mustache.to_html( data.toString(), { - socketId : req.params.socketId - })); - }); - -}); - -// Actually listen -server.listen( opts.port || null ); - -var brown = '\033[33m', - green = '\033[32m', - reset = '\033[0m'; - -var slidesLocation = 'http://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( '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' ); diff --git a/plugin/notes-server/notes.html b/plugin/notes-server/notes.html deleted file mode 100644 index ab8c5b17..00000000 --- a/plugin/notes-server/notes.html +++ /dev/null @@ -1,585 +0,0 @@ - - - - - - reveal.js - Slide Notes - - - - - - -
-
Upcoming
-
-
-

Time Click to Reset

-
- 0:00 AM -
-
- 00:00:00 -
-
-
- - -
-
- - -
- - - - - - - -