collab_client: Fix connection timeout logic

rhansen-collab_client
Richard Hansen 2021-03-30 16:52:42 -04:00
parent 60dde4edf6
commit 54a746ce94
1 changed files with 7 additions and 4 deletions

View File

@ -43,7 +43,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
let stateMessage; let stateMessage;
let channelState = 'CONNECTING'; let channelState = 'CONNECTING';
let lastCommitTime = 0; let lastCommitTime = 0;
let initialStartConnectTime = 0; let startConnectTime = Date.now();
let commitDelay = 500; let commitDelay = 500;
const userId = initialUserInfo.userId; const userId = initialUserInfo.userId;
@ -81,7 +81,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
} }
const now = Date.now(); const now = Date.now();
if ((!getSocket()) || channelState === 'CONNECTING') { if ((!getSocket()) || channelState === 'CONNECTING') {
if (channelState === 'CONNECTING' && (now - initialStartConnectTime) > 20000) { if (channelState === 'CONNECTING' && now - startConnectTime > 20000) {
setChannelState('DISCONNECTED', 'initsocketfail'); setChannelState('DISCONNECTED', 'initsocketfail');
} else { } else {
// check again in a bit // check again in a bit
@ -151,8 +151,6 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
const setUpSocket = () => { const setUpSocket = () => {
setChannelState('CONNECTED'); setChannelState('CONNECTED');
doDeferredActions(); doDeferredActions();
initialStartConnectTime = Date.now();
}; };
const sendMessage = (msg) => { const sendMessage = (msg) => {
@ -360,6 +358,11 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
if (newChannelState === channelState) return; if (newChannelState === channelState) return;
channelState = newChannelState; channelState = newChannelState;
callbacks.onChannelStateChange(channelState, moreInfo); callbacks.onChannelStateChange(channelState, moreInfo);
switch (channelState) {
case 'CONNECTING':
startConnectTime = Date.now();
break;
}
}; };
const valuesArray = (obj) => { const valuesArray = (obj) => {