From 953d98be96d65d1e7119ad3f25c5ead11ffdd745 Mon Sep 17 00:00:00 2001
From: yflory <yann.flory@xwiki.com>
Date: Wed, 6 Jun 2018 17:25:06 +0200
Subject: [PATCH] Fix reconnect

---
 www/common/cryptpad-common.js               | 6 ++++--
 www/common/outer/async-store.js             | 2 +-
 www/common/outer/worker-channel.js          | 2 +-
 www/common/sframe-chainpad-netflux-outer.js | 6 ++++--
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js
index 77707860c..e550671b0 100644
--- a/www/common/cryptpad-common.js
+++ b/www/common/cryptpad-common.js
@@ -556,8 +556,8 @@ define([
 
     // Pad RPC
     var pad = common.padRpc = {};
-    pad.joinPad = function (data, cb) {
-        postMessage("JOIN_PAD", data, cb);
+    pad.joinPad = function (data) {
+        postMessage("JOIN_PAD", data);
     };
     pad.sendPadMsg = function (data, cb) {
         postMessage("SEND_PAD_MSG", data, cb);
@@ -567,6 +567,7 @@ define([
     pad.onJoinEvent = Util.mkEvent();
     pad.onLeaveEvent = Util.mkEvent();
     pad.onDisconnectEvent = Util.mkEvent();
+    pad.onConnectEvent = Util.mkEvent();
     pad.onErrorEvent = Util.mkEvent();
 
     // Loading events
@@ -680,6 +681,7 @@ define([
         PAD_JOIN: common.padRpc.onJoinEvent.fire,
         PAD_LEAVE: common.padRpc.onLeaveEvent.fire,
         PAD_DISCONNECT: common.padRpc.onDisconnectEvent.fire,
+        PAD_CONNECT: common.padRpc.onConnectEvent.fire,
         PAD_ERROR: common.padRpc.onErrorEvent.fire,
         // Drive
         DRIVE_LOG: common.drive.onLog.fire,
diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js
index 664ad56af..eb8748c6f 100644
--- a/www/common/outer/async-store.js
+++ b/www/common/outer/async-store.js
@@ -966,7 +966,7 @@ define([
                 channel.queue.forEach(function (data) {
                     sendMessage(data.message);
                 });
-                cb({
+                postMessage("PAD_CONNECT", {
                     myID: wc.myID,
                     id: wc.id,
                     members: wc.members
diff --git a/www/common/outer/worker-channel.js b/www/common/outer/worker-channel.js
index c93fc6308..a2129bd69 100644
--- a/www/common/outer/worker-channel.js
+++ b/www/common/outer/worker-channel.js
@@ -24,7 +24,7 @@ define([
             var txid = mkTxid();
             var timeout = setTimeout(function () {
                 delete queries[txid];
-                console.log("Timeout making query " + q);
+                //console.log("Timeout making query " + q);
             }, 30000);
             queries[txid] = function (data, msg) {
                 clearTimeout(timeout);
diff --git a/www/common/sframe-chainpad-netflux-outer.js b/www/common/sframe-chainpad-netflux-outer.js
index 45c4bdabf..b08f1fe08 100644
--- a/www/common/sframe-chainpad-netflux-outer.js
+++ b/www/common/sframe-chainpad-netflux-outer.js
@@ -116,6 +116,10 @@ define([], function () {
             sframeChan.event('EV_RT_DISCONNECT');
         });
 
+        padRpc.onConnectEvent.reg(function (data) {
+            onOpen(data);
+        });
+
         padRpc.onErrorEvent.reg(function (err) {
             sframeChan.event('EV_RT_ERROR', err);
         });
@@ -128,8 +132,6 @@ define([], function () {
             owners: owners,
             password: password,
             expire: expire
-        }, function(data) {
-            onOpen(data);
         });
     };