Skip to content

Commit

Permalink
multiplex boosting
Browse files Browse the repository at this point in the history
  • Loading branch information
dajmcdon committed Nov 2, 2023
1 parent f218128 commit c5e56b1
Show file tree
Hide file tree
Showing 6 changed files with 1,163 additions and 3 deletions.
4 changes: 2 additions & 2 deletions _freeze/schedule/slides/20-boosting/execute-results/html.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions _freeze/site_libs/revealjs/plugin/multiplex/multiplex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(function() {

// emulate async script load
window.addEventListener( 'load', function() {
var multiplex = Reveal.getConfig().multiplex;
var socketId = multiplex.id;
var socket = io.connect(multiplex.url);

function post( evt ) {
var messageData = {
state: Reveal.getState(),
secret: multiplex.secret,
socketId: multiplex.id,
content: (evt || {}).content
};
socket.emit( 'multiplex-statechanged', messageData );
};

// master
if (multiplex.secret !== null) {

// Don't emit events from inside of notes windows
if ( window.location.search.match( /receiver/gi ) ) { return; }

// post once the page is loaded, so the client follows also on "open URL".
post();

// 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 );
document.addEventListener( 'send', post ); // broadcast custom events sent by other plugins

// client
} else {
socket.on(multiplex.id, function(message) {
// ignore data from sockets that aren't ours
if (message.socketId !== socketId) { return; }
if( window.location.host === 'localhost:1947' ) return;

if ( message.state ) {
Reveal.setState(message.state);
}
if ( message.content ) {
// forward custom events to other plugins
var event = new CustomEvent('received');
event.content = message.content;
document.dispatchEvent( event );
}
});
}
});
}());
8 changes: 8 additions & 0 deletions _freeze/site_libs/revealjs/plugin/multiplex/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: multiplex
script: [socket.io.js, multiplex.js]
register: false
config:
multiplex:
secret: null
id: null
url: "https://reveal-multiplex.glitch.me/"
9 changes: 9 additions & 0 deletions _freeze/site_libs/revealjs/plugin/multiplex/socket.io.js

Large diffs are not rendered by default.

Loading

0 comments on commit c5e56b1

Please sign in to comment.