From 0740711fdeadb4765a2e1f495ed85b4846ef926f Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 23 Jun 2019 12:42:22 +0200 Subject: Began presentation --- presentation/plugin/multiplex/client.js | 15 +++++++ presentation/plugin/multiplex/index.js | 64 ++++++++++++++++++++++++++++++ presentation/plugin/multiplex/master.js | 36 +++++++++++++++++ presentation/plugin/multiplex/package.json | 19 +++++++++ 4 files changed, 134 insertions(+) create mode 100644 presentation/plugin/multiplex/client.js create mode 100644 presentation/plugin/multiplex/index.js create mode 100644 presentation/plugin/multiplex/master.js create mode 100644 presentation/plugin/multiplex/package.json (limited to 'presentation/plugin/multiplex') diff --git a/presentation/plugin/multiplex/client.js b/presentation/plugin/multiplex/client.js new file mode 100644 index 0000000..f2af3cc --- /dev/null +++ b/presentation/plugin/multiplex/client.js @@ -0,0 +1,15 @@ +(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.setState(data.state); + }); +}()); diff --git a/presentation/plugin/multiplex/index.js b/presentation/plugin/multiplex/index.js new file mode 100644 index 0000000..b4f3c7f --- /dev/null +++ b/presentation/plugin/multiplex/index.js @@ -0,0 +1,64 @@ +var http = require('http'); +var express = require('express'); +var fs = require('fs'); +var io = require('socket.io'); +var crypto = require('crypto'); + +var app = express(); +var staticDir = express.static; +var server = http.createServer(app); + +io = io(server); + +var opts = { + port: process.env.PORT || 1948, + baseDir: __dirname + '/../../' +}; + +io.on('connection', function (socket) { + socket.on('multiplex-statechanged', function (data) { + if (typeof data.secret == 'undefined' || data.secret == null || data.secret === '') return; + if (createHash(data.secret) === data.socketId) { + data.secret = null; + socket.broadcast.emit(data.socketId, data); + } + }); +}); + +['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'}); + + var stream = fs.createReadStream(opts.baseDir + '/index.html'); + stream.on('error', function (error) { + res.write('