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/index.js | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 presentation/plugin/multiplex/index.js (limited to 'presentation/plugin/multiplex/index.js') 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('