diff options
Diffstat (limited to 'public/plugin/multiplex')
-rw-r--r-- | public/plugin/multiplex/client.js | 13 | ||||
-rw-r--r-- | public/plugin/multiplex/index.js | 56 | ||||
-rw-r--r-- | public/plugin/multiplex/master.js | 51 |
3 files changed, 120 insertions, 0 deletions
diff --git a/public/plugin/multiplex/client.js b/public/plugin/multiplex/client.js new file mode 100644 index 00000000..e6179f6d --- /dev/null +++ b/public/plugin/multiplex/client.js @@ -0,0 +1,13 @@ +(function() { + var multiplex = Reveal.getConfig().multiplex; + var socketId = multiplex.id; + var socket = io.connect(multiplex.url); + + socket.on(multiplex.id, function(data) { + // ignore data from sockets that aren't ours + if (data.socketId !== socketId) { return; } + if( window.location.host === 'localhost:1947' ) return; + + Reveal.slide(data.indexh, data.indexv, data.indexf, 'remote'); + }); +}()); diff --git a/public/plugin/multiplex/index.js b/public/plugin/multiplex/index.js new file mode 100644 index 00000000..6f5d8b11 --- /dev/null +++ b/public/plugin/multiplex/index.js @@ -0,0 +1,56 @@ +var express = require('express'); +var fs = require('fs'); +var io = require('socket.io'); +var crypto = require('crypto'); + +var app = express.createServer(); +var staticDir = express.static; + +io = io.listen(app); + +var opts = { + port: 1948, + baseDir : __dirname + '/../../' +}; + +io.sockets.on('connection', function(socket) { + socket.on('slidechanged', function(slideData) { + if (typeof slideData.secret == 'undefined' || slideData.secret == null || slideData.secret === '') return; + if (createHash(slideData.secret) === slideData.socketId) { + slideData.secret = null; + socket.broadcast.emit(slideData.socketId, slideData); + }; + }); +}); + +app.configure(function() { + [ 'css', 'js', '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("/token", function(req,res) { + var ts = new Date().getTime(); + var rand = Math.floor(Math.random()*9999999); + var secret = ts.toString() + rand.toString(); + res.send({secret: secret, socketId: createHash(secret)}); +}); + +var createHash = function(secret) { + var cipher = crypto.createCipher('blowfish', secret); + return(cipher.final('hex')); +}; + +// Actually listen +app.listen(opts.port || null); + +var brown = '\033[33m', + green = '\033[32m', + reset = '\033[0m'; + +console.log( brown + "reveal.js:" + reset + " Multiplex running on port " + green + opts.port + reset );
\ No newline at end of file diff --git a/public/plugin/multiplex/master.js b/public/plugin/multiplex/master.js new file mode 100644 index 00000000..b6a7eb7d --- /dev/null +++ b/public/plugin/multiplex/master.js @@ -0,0 +1,51 @@ +(function() { + // Don't emit events from inside of notes windows + if ( window.location.search.match( /receiver/gi ) ) { return; } + + var multiplex = Reveal.getConfig().multiplex; + + var socket = io.connect(multiplex.url); + + var notify = function( slideElement, indexh, indexv, origin ) { + if( typeof origin === 'undefined' && origin !== 'remote' ) { + var nextindexh; + var nextindexv; + + var fragmentindex = Reveal.getIndices().f; + if (typeof fragmentindex == 'undefined') { + fragmentindex = 0; + } + + if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') { + nextindexh = indexh; + nextindexv = indexv + 1; + } else { + nextindexh = indexh + 1; + nextindexv = 0; + } + + var slideData = { + indexh : indexh, + indexv : indexv, + indexf : fragmentindex, + nextindexh : nextindexh, + nextindexv : nextindexv, + secret: multiplex.secret, + socketId : multiplex.id + }; + + socket.emit('slidechanged', slideData); + } + } + + Reveal.addEventListener( 'slidechanged', function( event ) { + notify( event.currentSlide, event.indexh, event.indexv, event.origin ); + } ); + + var fragmentNotify = function( event ) { + notify( Reveal.getCurrentSlide(), Reveal.getIndices().h, Reveal.getIndices().v, event.origin ); + }; + + Reveal.addEventListener( 'fragmentshown', fragmentNotify ); + Reveal.addEventListener( 'fragmenthidden', fragmentNotify ); +}());
\ No newline at end of file |