From c168ce2d1cba04653a72ca2c051b36e579d50f35 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 25 Aug 2016 17:56:17 +0200 Subject: [PATCH] Ability to reconnect after a connection failure --- www/common/toolbar.js | 5 +++-- www/pad/main.js | 12 ++++++++++++ www/text/main.js | 11 ++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/www/common/toolbar.js b/www/common/toolbar.js index d4552c6c6..956defc4d 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -224,10 +224,11 @@ define([ return { failed: function () { connected = false; - userListElement.textContent = ''; + userListElement.textContent = 'Disconnected'; lagElement.textContent = ''; }, - reconnecting: function () { + reconnecting: function (userId) { + myUserName = userId; connected = false; userListElement.textContent = Messages.reconnecting; lagElement.textContent = ''; diff --git a/www/pad/main.js b/www/pad/main.js index 366b25701..e1f981b71 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -603,6 +603,18 @@ define([ Cryptpad.alert(Messages.disconnectAlert); }; + var onConnectionChange = realtimeOptions.onConnectionChange = function (info) { + setEditable(info.state); + toolbar.failed(); + if (info.state) { + initializing = true; + toolbar.reconnecting(info.myId); + Cryptpad.findOKButton().click(); + } else { + Cryptpad.alert(Messages.disconnectAlert); + } + }; + var onLocal = realtimeOptions.onLocal = function () { if (initializing) { return; } diff --git a/www/text/main.js b/www/text/main.js index 18e8888b4..94890aeb9 100644 --- a/www/text/main.js +++ b/www/text/main.js @@ -74,10 +74,19 @@ define([ }; var onAbort = config.onAbort = function (info) { - $textarea.attr('disabled', true); + setEditable(false); window.alert("Server Connection Lost"); }; + var onConnectionChange = config.onConnectionChange = function (info) { + if (info.state) { + initializing = true; + } else { + setEditable(false); + window.alert("Server Connection Lost. Trying to reconnect..."); + } + }; + var rt = Realtime.start(config); ['cut', 'paste', 'change', 'keyup', 'keydown', 'select', 'textInput']