Temp commit

pull/1/head
Yann Flory 9 years ago
parent 870b2dbb7e
commit c536ecbc1c

@ -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) => {

@ -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) {

@ -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() {
@ -209,10 +230,16 @@ 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);

Loading…
Cancel
Save