From fb20c26c5f36be272060a45286188f4eafbd451e Mon Sep 17 00:00:00 2001 From: anugu-chegg Date: Sat, 3 Feb 2018 13:29:52 +0530 Subject: [PATCH] Don't send COMMIT-MESSAGE when socketio connection is not active --- src/static/js/collab_client.js | 34 ++++++++++++++++++++-------------- src/static/js/pad.js | 4 ++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index fd0d9d44..9fc03991 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -181,20 +181,26 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad) } var sentMessage = false; - var userChangesData = editor.prepareUserChangeset(); - if (userChangesData.changeset) - { - lastCommitTime = t; - state = "COMMITTING"; - stateMessage = { - type: "USER_CHANGES", - baseRev: rev, - changeset: userChangesData.changeset, - apool: userChangesData.apool - }; - sendMessage(stateMessage); - sentMessage = true; - callbacks.onInternalAction("commitPerformed"); + if (getSocket().realConnected) { + var userChangesData = editor.prepareUserChangeset(); + if (userChangesData.changeset) + { + lastCommitTime = t; + state = "COMMITTING"; + stateMessage = { + type: "USER_CHANGES", + baseRev: rev, + changeset: userChangesData.changeset, + apool: userChangesData.apool + }; + sendMessage(stateMessage); + sentMessage = true; + callbacks.onInternalAction("commitPerformed"); + } + } + else { + // run again in a few seconds, to check if there was a reconnection attempt + setTimeout(wrapRecordingErrors("setTimeout(handleUserChanges)", handleUserChanges), 1000); } if (sentMessage) diff --git a/src/static/js/pad.js b/src/static/js/pad.js index bab59f42..152a48d9 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -201,15 +201,19 @@ function handshake() }); socket.once('connect', function () { + // Setup our own connected flag since socketio one doesn't work accurately + socket.realConnected = true; sendClientReady(false); }); socket.on('reconnect', function () { + socket.realConnected = true; pad.collabClient.setChannelState("CONNECTED"); pad.sendClientReady(true); }); socket.on('reconnecting', function() { + socket.realConnected = false; pad.collabClient.setChannelState("RECONNECTING"); });