Skip to content

Commit

Permalink
Merge pull request #5 from slidewiki/SWIK-2115-reveal-multiplex
Browse files Browse the repository at this point in the history
SWIK-2115 Reveal Multiplex
  • Loading branch information
rmeissn authored Jul 26, 2018
2 parents 414807e + 866263a commit 59d039a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Webserver](https://img.shields.io/badge/Socket%20Framework-Socket.io%202.0-blue.svg)](http://hapijs.com/)


Simple STUN Service for the WebRTC parts of slidewiki-platform.
Simple STUN service for the WebRTC parts of slidewiki-platform and also for the reveal multiplexing plugin.

### Install NodeJS ###
---
Expand Down
37 changes: 36 additions & 1 deletion application/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const Joi = require('joi'),
server = require('./server'),
os = require('os'),
twitter = require('twitter'),
_ = require('lodash');
_ = require('lodash'),
crypto = require('crypto'),
URL = require('url');

const twitterclient = new twitter(require('./config.json'));

Expand Down Expand Up @@ -43,6 +45,17 @@ module.exports = function(server) {
description: 'Get rooms for a specific deck with their opening time'
}
});

server.route({
method: 'GET',
path: '/token',
handler: getNewRevealMultiplexToken,
config: {
cors: {origin: ['http://localhost*', URL.parse(process.env.VIRTUAL_HOST).hostname]},
tags: ['api'],
description: 'Get a new token pair for the reveal multiplex plugin'
}
});
};

let rooms = {};//{deckid: [{roomName: string, openingTime: UTC, twitterStream: stream}, ...], ...}
Expand All @@ -60,6 +73,20 @@ function getRoomsForDeckWithTime(request, reply) {
reply(response.map((el) => {return {'roomName': el.roomName, 'openingTime': el.openingTime};}));
}

function getNewRevealMultiplexToken(request, reply) {
let ts = new Date().getTime();
let rand = Math.floor(Math.random()*9999999);
let secret = ts.toString() + rand.toString();
let socketID = createHash(secret);
console.log({secret: secret, socketId: socketID});
reply({secret: secret, socketId: socketID});
}

function createHash(secret) {
let cipher = crypto.createCipher('blowfish', secret);
return(cipher.final('hex'));
}

let io = require('socket.io')(server.listener);
io.on('connection', (socket) => {

Expand Down Expand Up @@ -158,4 +185,12 @@ io.on('connection', (socket) => {
}
});

socket.on('multiplex-statechanged', (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);
}
});

});

0 comments on commit 59d039a

Please sign in to comment.