From 77e7fb5724c6e07136a2967290e5b0e194990a69 Mon Sep 17 00:00:00 2001 From: Yann Flory Date: Mon, 14 Mar 2016 14:49:19 +0100 Subject: [PATCH] Fix an issue with the WebRTC service where it was impossible to join a channel once someone had left this channel --- ChainPadSrv.js | 2 -- WebRTCSrv.js | 2 ++ www/common/netflux.js | 32 +++++++++++++++++++++----------- www/common/realtime-input.js | 1 - 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ChainPadSrv.js b/ChainPadSrv.js index c73fe9e3e..4ed6ff840 100644 --- a/ChainPadSrv.js +++ b/ChainPadSrv.js @@ -49,7 +49,6 @@ var popPassword = function (msg) { }; var sendMsg = function (msg, socket) { - console.log('>> '+msg); socket.send(msg); }; @@ -109,7 +108,6 @@ var dropClient = function (ctx, userpass) { }; var handleMessage = function (ctx, socket, msg) { - console.log('<< '+msg); var parsed = parseMessage(msg); var userPass = parsed.user + ':' + parsed.pass; msg = popPassword(msg); diff --git a/WebRTCSrv.js b/WebRTCSrv.js index ffcde5c53..8b818f3fe 100644 --- a/WebRTCSrv.js +++ b/WebRTCSrv.js @@ -9,6 +9,7 @@ var run = module.exports.run = function(server) { socket.on('message', (data) => { try { let msg = JSON.parse(data) + console.log(msg); if (msg.hasOwnProperty('key')) { for (let master of server.clients) { if (master.key === msg.key) { @@ -32,6 +33,7 @@ var run = module.exports.run = function(server) { socket.master = master master.joiningClients.push(socket) let id = master.joiningClients.length - 1 + console.log(id); master.send(JSON.stringify({id, data: msg.data})) return } diff --git a/www/common/netflux.js b/www/common/netflux.js index 971dc0a9b..ef4b196b5 100644 --- a/www/common/netflux.js +++ b/www/common/netflux.js @@ -406,7 +406,7 @@ return /******/ (function(modules) { // webpackBootstrap value: function get(code) { var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; - var service = void 0; + var service = undefined; switch (code) { case cs.WEBRTC_SERVICE: service = new _WebRTCService2.default(options); @@ -490,6 +490,9 @@ return /******/ (function(modules) { // webpackBootstrap if (webChannel.channels.size === 0) { webChannel.channels.add(channel); + channel.onclose = function () { + webChannel.channels.delete(channel); + }; resolve(channel.peerID); } else { (function () { @@ -515,11 +518,17 @@ return /******/ (function(modules) { // webpackBootstrap key: 'addFinish', value: function addFinish(webChannel, id) { if (id != webChannel.myID) { - webChannel.channels.add(webChannel.aboutToJoin.get(id)); - //webChannel.aboutToJoin.delete(id) - if (Reflect.has(webChannel, 'successfullyConnected')) { - webChannel.successfullyConnected.delete(id); - } + (function () { + var channel = webChannel.aboutToJoin.get(id); + webChannel.channels.add(webChannel.aboutToJoin.get(id)); + channel.onclose = function () { + webChannel.channels.delete(channel); + }; + //webChannel.aboutToJoin.delete(id) + if (Reflect.has(webChannel, 'successfullyConnected')) { + webChannel.successfullyConnected.delete(id); + } + })(); } else { webChannel.onopen(); } @@ -846,7 +855,7 @@ return /******/ (function(modules) { // webpackBootstrap var settings = Object.assign({}, this.settings, options); return new Promise(function (resolve, reject) { - var connection = void 0; + var connection = undefined; var socket = new window.WebSocket(settings.signaling); socket.onopen = function () { connection = new _this2.RTCPeerConnection(settings.webRTCOptions); @@ -966,8 +975,8 @@ return /******/ (function(modules) { // webpackBootstrap }, function () {}); })(); } else if (msg.sdp.type === 'answer') { - var _sd = Object.assign(new this.RTCSessionDescription(), msg.sdp); - webChannel.connections.get(msg.senderPeerID).setRemoteDescription(_sd, function () {}, function () {}); + var sd = Object.assign(new this.RTCSessionDescription(), msg.sdp); + webChannel.connections.get(msg.senderPeerID).setRemoteDescription(sd, function () {}, function () {}); } } else if (Reflect.has(msg, 'candidate')) { webChannel.connections.get(msg.senderPeerID).addIceCandidate(new this.RTCIceCandidate(msg.candidate)); @@ -1080,7 +1089,7 @@ return /******/ (function(modules) { // webpackBootstrap var settings = Object.assign({}, this.settings, options); return new Promise(function (resolve, reject) { - var connection = void 0; + var connection = undefined; var socket = new window.WebSocket(settings.signaling); socket.seq = 1; socket.facade = options.facade || null; @@ -1169,6 +1178,7 @@ return /******/ (function(modules) { // webpackBootstrap case cs.JOIN_FINISH: webChannel.topologyService.addFinish(webChannel, msg.id); if (msg.id != webChannel.myID) { + console.log('different id'); webChannel.onJoining(msg.id); } break; @@ -1321,7 +1331,7 @@ return /******/ (function(modules) { // webpackBootstrap }, { key: 'message', value: function message(code, data) { - var type = void 0; + var type = undefined; switch (code) { case cs.USER_DATA: type = 'MSG'; diff --git a/www/common/realtime-input.js b/www/common/realtime-input.js index fcc8e8612..5ced253a4 100644 --- a/www/common/realtime-input.js +++ b/www/common/realtime-input.js @@ -363,7 +363,6 @@ define([ else { warn(error); } }); }; - joinChannel(); var checkConnection = function(wc) {