pad: Check for null collabClient in socket.io event handlers

pull/4425/head
Richard Hansen 2020-10-19 14:19:07 -04:00 committed by John McLear
parent b1acf6143a
commit 5b887396c3
1 changed files with 21 additions and 7 deletions

View File

@ -189,23 +189,37 @@ function handshake()
});
socket.on('reconnect', function () {
pad.collabClient.setChannelState("CONNECTED");
// pad.collabClient might be null if the hanshake failed (or it never got that far).
if (pad.collabClient != null) {
pad.collabClient.setChannelState('CONNECTED');
}
sendClientReady(receivedClientVars);
});
socket.on('reconnecting', function() {
pad.collabClient.setStateIdle();
pad.collabClient.setIsPendingRevision(true);
pad.collabClient.setChannelState("RECONNECTING");
// pad.collabClient might be null if the hanshake failed (or it never got that far).
if (pad.collabClient != null) {
pad.collabClient.setStateIdle();
pad.collabClient.setIsPendingRevision(true);
pad.collabClient.setChannelState('RECONNECTING');
}
});
socket.on('reconnect_failed', function(error) {
pad.collabClient.setChannelState("DISCONNECTED", "reconnect_timeout");
// pad.collabClient might be null if the hanshake failed (or it never got that far).
if (pad.collabClient != null) {
pad.collabClient.setChannelState('DISCONNECTED', 'reconnect_timeout');
} else {
throw new Error('Reconnect timed out');
}
});
socket.on('error', function(error) {
pad.collabClient.setStateIdle();
pad.collabClient.setIsPendingRevision(true);
// pad.collabClient might be null if the error occurred before the hanshake completed.
if (pad.collabClient != null) {
pad.collabClient.setStateIdle();
pad.collabClient.setIsPendingRevision(true);
}
});
var initalized = false;