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

This commit is contained in:
Richard Hansen 2020-10-19 14:19:07 -04:00 committed by John McLear
parent b1acf6143a
commit 5b887396c3

View file

@ -189,23 +189,37 @@ function handshake()
}); });
socket.on('reconnect', function () { 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); sendClientReady(receivedClientVars);
}); });
socket.on('reconnecting', function() { socket.on('reconnecting', function() {
pad.collabClient.setStateIdle(); // pad.collabClient might be null if the hanshake failed (or it never got that far).
pad.collabClient.setIsPendingRevision(true); if (pad.collabClient != null) {
pad.collabClient.setChannelState("RECONNECTING"); pad.collabClient.setStateIdle();
pad.collabClient.setIsPendingRevision(true);
pad.collabClient.setChannelState('RECONNECTING');
}
}); });
socket.on('reconnect_failed', function(error) { 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) { socket.on('error', function(error) {
pad.collabClient.setStateIdle(); // pad.collabClient might be null if the error occurred before the hanshake completed.
pad.collabClient.setIsPendingRevision(true); if (pad.collabClient != null) {
pad.collabClient.setStateIdle();
pad.collabClient.setIsPendingRevision(true);
}
}); });
var initalized = false; var initalized = false;