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 POLICY_VIOLATION = 1008
const CLOSE_UNSUPPORTED = 1003 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) { var run = module.exports.run = function(storage, server) {
server.on('connection', (socket) => { server.on('connection', (socket) => {
socket.on('message', (data) => { socket.on('message', (data) => {

@ -500,6 +500,7 @@ return /******/ (function(modules) { // webpackBootstrap
}, { }, {
key: 'broadcast', key: 'broadcast',
value: function broadcast(webChannel, data) { value: function broadcast(webChannel, data) {
console.log(data);
var _iteratorNormalCompletion = true; var _iteratorNormalCompletion = true;
var _didIteratorError = false; var _didIteratorError = false;
var _iteratorError = undefined; 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) { for (var _iterator = webChannel.channels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var c = _step.value; var c = _step.value;
console.log(c);
c.send(data); c.send(data);
} }
} catch (err) { } catch (err) {

@ -127,27 +127,46 @@ define([
// Add the Facade's peer messages handler // Add the Facade's peer messages handler
Netflux._onPeerMessage = onPeerMessage; 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(); var webchannel = Netflux.create();
webchannel.openForJoining(options).then(function(data) { 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'); // console.log('resolved');
onOpen(); onOpen(webchannel);
}, function(err) { }, function(err) {
console.log('rejected'); console.log('rejected');
console.error(err); console.error(err);
}); });
}
var onOpen = function() { else {
console.log('CLIENT');
console.log(channel);
// Connect to the WebSocket server // Connect to the WebSocket server
Netflux.join(channel, options).then(function(wc) { 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.onmessage = onMessage; // On receiving message
wc.onJoining = onJoining; // On user joining the session wc.onJoining = onJoining; // On user joining the session
@ -166,12 +185,16 @@ define([
// On sending message // On sending message
realtime.onMessage(function(message) { realtime.onMessage(function(message) {
// TODO: put in ChaindpadAdapter
// Do not send authentication messages since it is handled by Netflux // Do not send authentication messages since it is handled by Netflux
var parsed = parseMessage(message); var parsed = parseMessage(message);
if (parsed.content[0] !== 0) { if (parsed.content[0] !== 0) {
console.log('ENVOI '+message);
message = Crypto.encrypt(message, cryptKey); message = Crypto.encrypt(message, cryptKey);
wc.send(message); wc.send(message);
onMessage('', message);
} }
// END-TODO
}); });
// Get the channel history // Get the channel history
@ -188,9 +211,7 @@ define([
bump = realtime.bumpSharejs; bump = realtime.bumpSharejs;
realtime.start(); realtime.start();
}, function(error) {
warn(error);
});
} }
var createRealtime = function() { var createRealtime = function() {
@ -208,12 +229,18 @@ define([
})); }));
var onMessage = function(peer, msg) { var onMessage = function(peer, msg) {
// TODO : put in ChainpadAdapter
// remove the password // remove the password
var passLen = msg.substring(0,msg.indexOf(':')); var passLen = msg.substring(0,msg.indexOf(':'));
var message = msg.substring(passLen.length+1 + Number(passLen)); var message = msg.substring(passLen.length+1 + Number(passLen));
message = Crypto.decrypt(message, cryptKey); message = Crypto.decrypt(message, cryptKey);
console.log('RECOIS '+message);
// END-TODO ChainpadAdapter
verbose(message); verbose(message);
allMessages.push(message); allMessages.push(message);
if (!initializing) { if (!initializing) {

Loading…
Cancel
Save