mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 01:46:14 -04:00
Handle client reconnect properly
This commit is contained in:
parent
4265f4175e
commit
bf05e9ae89
3 changed files with 131 additions and 6 deletions
|
@ -60,6 +60,8 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
var debugMessages = [];
|
||||
var msgQueue = [];
|
||||
|
||||
var socketIOError = false;
|
||||
|
||||
tellAceAboutHistoricalAuthors(serverVars.historicalAuthorData);
|
||||
tellAceActiveAuthorInfo(initialUserInfo);
|
||||
|
||||
|
@ -181,7 +183,8 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
}
|
||||
|
||||
var sentMessage = false;
|
||||
if (getSocket().realConnected) {
|
||||
if (getSocket().realConnected && !socketIOError)
|
||||
{
|
||||
var userChangesData = editor.prepareUserChangeset();
|
||||
if (userChangesData.changeset)
|
||||
{
|
||||
|
@ -198,9 +201,10 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
callbacks.onInternalAction("commitPerformed");
|
||||
}
|
||||
}
|
||||
else {
|
||||
// run again in a few seconds, to check if there was a reconnection attempt
|
||||
setTimeout(wrapRecordingErrors("setTimeout(handleUserChanges)", handleUserChanges), 1000);
|
||||
else
|
||||
{
|
||||
// run again in a few seconds, to detect a reconnect
|
||||
setTimeout(wrapRecordingErrors("setTimeout(handleUserChanges)", handleUserChanges), 3000);
|
||||
}
|
||||
|
||||
if (sentMessage)
|
||||
|
@ -336,6 +340,44 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
});
|
||||
handleUserChanges();
|
||||
}
|
||||
else if (msg.type == 'CLIENT_RECONNECT')
|
||||
{
|
||||
if (msg.noChanges)
|
||||
{
|
||||
socketIOError = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var currRev = msg.currRev;
|
||||
var newRev = msg.newRev;
|
||||
var changeset = msg.changeset;
|
||||
var author = (msg.author || '');
|
||||
var apool = msg.apool;
|
||||
|
||||
|
||||
if (rev + 1 == currRev)
|
||||
{
|
||||
if (author == pad.getUserId())
|
||||
{
|
||||
editor.applyPreparedChangesetToBase();
|
||||
setStateIdle();
|
||||
}
|
||||
else
|
||||
{
|
||||
editor.applyChangesToBase(changeset, author, apool);
|
||||
}
|
||||
|
||||
}
|
||||
if (rev + 1 < currRev)
|
||||
{
|
||||
editor.applyChangesToBase(changeset, author, apool);
|
||||
}
|
||||
if (currRev == newRev)
|
||||
{
|
||||
socketIOError = false;
|
||||
rev = newRev;
|
||||
}
|
||||
}
|
||||
else if (msg.type == "NO_COMMIT_PENDING")
|
||||
{
|
||||
if (state == "COMMITTING")
|
||||
|
@ -597,6 +639,10 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
schedulePerhapsCallIdleFuncs();
|
||||
}
|
||||
|
||||
function setSocketIOError(value)
|
||||
{
|
||||
socketIOError = value;
|
||||
}
|
||||
function callWhenNotCommitting(func)
|
||||
{
|
||||
idleFuncs.push(func);
|
||||
|
@ -663,7 +709,8 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
|||
callWhenNotCommitting: callWhenNotCommitting,
|
||||
addHistoricalAuthors: tellAceAboutHistoricalAuthors,
|
||||
setChannelState: setChannelState,
|
||||
setStateIdle: setStateIdle
|
||||
setStateIdle: setStateIdle,
|
||||
setSocketIOError: setSocketIOError
|
||||
};
|
||||
|
||||
$(document).ready(setUpSocket);
|
||||
|
|
|
@ -209,11 +209,12 @@ function handshake()
|
|||
socket.on('reconnect', function () {
|
||||
socket.realConnected = true;
|
||||
pad.collabClient.setChannelState("CONNECTED");
|
||||
pad.sendClientReady(true);
|
||||
pad.sendClientReady(receivedClientVars);
|
||||
});
|
||||
|
||||
socket.on('reconnecting', function() {
|
||||
socket.realConnected = false;
|
||||
pad.collabClient.setStateIdle();
|
||||
pad.collabClient.setChannelState("RECONNECTING");
|
||||
});
|
||||
|
||||
|
@ -224,6 +225,7 @@ function handshake()
|
|||
socket.on('error', function(error) {
|
||||
socket.realConnected = false;
|
||||
pad.collabClient.setStateIdle();
|
||||
pad.collabClient.setSocketIOError(true);
|
||||
});
|
||||
|
||||
var initalized = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue