From 3a188625e089444abe27ca867ceee218fffe00eb Mon Sep 17 00:00:00 2001 From: Yann Flory Date: Mon, 14 Mar 2016 15:20:00 +0100 Subject: [PATCH] Improve the detection of a disconnected peer to update the user list with the WebRTC service --- WebRTCSrv.js | 2 -- www/common/netflux.js | 20 ++++++++------------ www/common/realtime-input.js | 4 ---- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/WebRTCSrv.js b/WebRTCSrv.js index 8b818f3fe..ffcde5c53 100644 --- a/WebRTCSrv.js +++ b/WebRTCSrv.js @@ -9,7 +9,6 @@ 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) { @@ -33,7 +32,6 @@ 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 ef4b196b5..9633ebfba 100644 --- a/www/common/netflux.js +++ b/www/common/netflux.js @@ -222,9 +222,7 @@ return /******/ (function(modules) { // webpackBootstrap _createClass(WebChannel, [{ key: 'leave', - value: function leave() { - this.topologyService.leave(this); - } + value: function leave() {} }, { key: 'send', value: function send(data) { @@ -491,6 +489,7 @@ return /******/ (function(modules) { // webpackBootstrap if (webChannel.channels.size === 0) { webChannel.channels.add(channel); channel.onclose = function () { + webChannel.onLeaving(channel.peerID); webChannel.channels.delete(channel); }; resolve(channel.peerID); @@ -522,6 +521,7 @@ return /******/ (function(modules) { // webpackBootstrap var channel = webChannel.aboutToJoin.get(id); webChannel.channels.add(webChannel.aboutToJoin.get(id)); channel.onclose = function () { + webChannel.onLeaving(channel.peerID); webChannel.channels.delete(channel); }; //webChannel.aboutToJoin.delete(id) @@ -602,8 +602,7 @@ return /******/ (function(modules) { // webpackBootstrap }, { key: 'leave', value: function leave(webChannel) { - var protocol = _ServiceProvider2.default.get(cs.EXCHANGEPROTOCOL_SERVICE); - this.broadcast(webChannel, protocol.message(cs.LEAVING, { id: webChannel.myID })); + this.broadcast(webChannel); } }, { key: '_generateID', @@ -946,6 +945,10 @@ return /******/ (function(modules) { // webpackBootstrap e.channel.webChannel = webChannel; e.channel.onmessage = _this3.protocol.onmessage; webChannel.channels.add(e.channel); + e.channel.onclose = function () { + webChannel.onLeaving(e.channel.peerID); + webChannel.channels.delete(e.channel); + }; }; }; connection.onicecandidate = function (e) { @@ -1158,9 +1161,6 @@ return /******/ (function(modules) { // webpackBootstrap case cs.GET_HISTORY: webChannel.onPeerMessage(msg.id, msg.code); break; - case cs.LEAVING: - webChannel.onLeaving(msg.id); - break; case cs.SERVICE_DATA: var service = _ServiceProvider2.default.get(msg.service); service.onmessage(channel, msg.data); @@ -1178,7 +1178,6 @@ 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; @@ -1196,9 +1195,6 @@ return /******/ (function(modules) { // webpackBootstrap case cs.GET_HISTORY: msg.id = data.id; break; - case cs.LEAVING: - msg.id = data.id; - break; case cs.SERVICE_DATA: msg.service = data.service; msg.data = Object.assign({}, data.data); diff --git a/www/common/realtime-input.js b/www/common/realtime-input.js index 5ced253a4..21ab83361 100644 --- a/www/common/realtime-input.js +++ b/www/common/realtime-input.js @@ -281,10 +281,6 @@ define([ onPeerMessage(peerId, type, wc); }; - window.onunload = function() { - wc.leave(); - }; - // Open a Chainpad session realtime = createRealtime();