From c536ecbc1ce01b69f7692bd97c77d2b84c311ca4 Mon Sep 17 00:00:00 2001 From: Yann Flory Date: Tue, 8 Mar 2016 15:13:57 +0100 Subject: [PATCH] Temp commit --- WebRTCSrv.js | 4 --- www/common/netflux.js | 2 ++ www/common/realtime-input.js | 53 +++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/WebRTCSrv.js b/WebRTCSrv.js index 06dfd61f4..e3e0a3c42 100644 --- a/WebRTCSrv.js +++ b/WebRTCSrv.js @@ -5,10 +5,6 @@ const UNSUPPORTED_DATA = 1007 const POLICY_VIOLATION = 1008 const CLOSE_UNSUPPORTED = 1003 -// let server = new WebSocketServer({port: PORT}, () => { - // console.log('Server runs on: ws://localhost:' + PORT) -// }) - var run = module.exports.run = function(storage, server) { server.on('connection', (socket) => { socket.on('message', (data) => { diff --git a/www/common/netflux.js b/www/common/netflux.js index 5252a4767..d63470bba 100644 --- a/www/common/netflux.js +++ b/www/common/netflux.js @@ -500,6 +500,7 @@ return /******/ (function(modules) { // webpackBootstrap }, { key: 'broadcast', value: function broadcast(webChannel, data) { + console.log(data); var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; @@ -508,6 +509,7 @@ return /******/ (function(modules) { // webpackBootstrap for (var _iterator = webChannel.channels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var c = _step.value; + console.log(c); c.send(data); } } catch (err) { diff --git a/www/common/realtime-input.js b/www/common/realtime-input.js index 17eb724f5..ebddde624 100644 --- a/www/common/realtime-input.js +++ b/www/common/realtime-input.js @@ -127,27 +127,46 @@ define([ // Add the Facade's peer messages handler Netflux._onPeerMessage = onPeerMessage; + function getParameterByName(name, url) { + if (!url) url = window.location.href; + name = name.replace(/[\[\]]/g, "\\$&"); + var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), + results = regex.exec(url); + if (!results) return null; + if (!results[2]) return ''; + return decodeURIComponent(results[2].replace(/\+/g, " ")); + } + + if(getParameterByName("server")) { + console.log('SERVER'); + console.log(channel); var webchannel = Netflux.create(); webchannel.openForJoining(options).then(function(data) { - console.log('keys'); - console.log(channel); - console.log(data); - webchannel.onmessage = onMessage; // On receiving message - webchannel.onJoining = onJoining; // On user joining the session - webchannel.onLeaving = onLeaving; // On user leaving the session // console.log('resolved'); - onOpen(); + onOpen(webchannel); }, function(err) { console.log('rejected'); console.error(err); }); - - var onOpen = function() { + } + else { + console.log('CLIENT'); + console.log(channel); // Connect to the WebSocket server Netflux.join(channel, options).then(function(wc) { + onOpen(wc); + }, function(error) { + warn(error); + }); + } + + var onOpen = function(wc) { + + console.log('joined the channel'); + console.log(wc.myID); wc.onmessage = onMessage; // On receiving message wc.onJoining = onJoining; // On user joining the session @@ -166,12 +185,16 @@ define([ // On sending message realtime.onMessage(function(message) { + // TODO: put in ChaindpadAdapter // Do not send authentication messages since it is handled by Netflux var parsed = parseMessage(message); if (parsed.content[0] !== 0) { + console.log('ENVOI '+message); message = Crypto.encrypt(message, cryptKey); wc.send(message); + onMessage('', message); } + // END-TODO }); // Get the channel history @@ -188,9 +211,7 @@ define([ bump = realtime.bumpSharejs; realtime.start(); - }, function(error) { - warn(error); - }); + } var createRealtime = function() { @@ -208,12 +229,18 @@ define([ })); var onMessage = function(peer, msg) { + + // TODO : put in ChainpadAdapter // remove the password var passLen = msg.substring(0,msg.indexOf(':')); var message = msg.substring(passLen.length+1 + Number(passLen)); + message = Crypto.decrypt(message, cryptKey); - + console.log('RECOIS '+message); + + // END-TODO ChainpadAdapter + verbose(message); allMessages.push(message); if (!initializing) {