var http=require("http"),express=require("express"),fs=require("fs"),io=require("socket.io"),crypto=require("crypto"),app=express(),staticDir=express.static,server=http.createServer(app);io=io(server);var opts={port:process.env.PORT||1948,baseDir:__dirname+"/../../"};io.on("connection",function(r){r.on("multiplex-statechanged",function(e){typeof e.secret=="undefined"||e.secret==null||e.secret===""||createHash(e.secret)===e.socketId&&(e.secret=null,r.broadcast.emit(e.socketId,e))})}),["css","js","plugin","lib"].forEach(function(r){app.use("/"+r,staticDir(opts.baseDir+r))}),app.get("/",function(r,e){e.writeHead(200,{"Content-Type":"text/html"});var t=fs.createReadStream(opts.baseDir+"/index.html");t.on("error",function(n){e.write('<style>body{font-family: sans-serif;}</style><h2>reveal.js multiplex server.</h2><a href="/token">Generate token</a>'),e.end()}),t.on("readable",function(){t.pipe(e)})}),app.get("/token",function(r,e){var t=new Date().getTime(),n=Math.floor(Math.random()*9999999),o=t.toString()+n.toString();e.send({secret:o,socketId:createHash(o)})});var createHash=function(r){var e=crypto.createCipher("blowfish",r);return e.final("hex")};server.listen(opts.port||null);var brown="\x1B[33m",green="\x1B[32m",reset="\x1B[0m";console.log(brown+"reveal.js:"+reset+" Multiplex running on port "+green+opts.port+reset);
