mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-11 13:47:05 +02:00
Fix race-condition where the websocket-connection is not recheked on page-reload
This commit is contained in:
@@ -69,20 +69,46 @@ function initStatusIndicator() {
|
|||||||
updateStatusIndicator('connecting', 'Connecting...');
|
updateStatusIndicator('connecting', 'Connecting...');
|
||||||
|
|
||||||
// Register callback with WebSocket manager when available
|
// Register callback with WebSocket manager when available
|
||||||
if (typeof wsManager !== 'undefined' && wsManager) {
|
function registerStatusCallback() {
|
||||||
wsManager.onStatusChange(function(state, text) {
|
if (typeof wsManager !== 'undefined' && wsManager) {
|
||||||
updateStatusIndicator(state, text);
|
// Register callback for future status changes
|
||||||
});
|
wsManager.onStatusChange(function(state, text) {
|
||||||
} else {
|
updateStatusIndicator(state, text);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Immediately update status based on current connection state
|
||||||
|
// This handles the case where connection was established before callback registration
|
||||||
|
var currentState = wsManager.getConnectionState();
|
||||||
|
var currentText = 'Connecting...';
|
||||||
|
|
||||||
|
if (currentState === 'connected' && wsManager.isConnected) {
|
||||||
|
currentText = 'Connected';
|
||||||
|
} else if (currentState === 'connecting') {
|
||||||
|
currentText = 'Connecting...';
|
||||||
|
} else if (currentState === 'disconnected') {
|
||||||
|
currentText = 'Disconnected';
|
||||||
|
} else if (currentState === 'disconnecting') {
|
||||||
|
currentText = 'Disconnecting...';
|
||||||
|
}
|
||||||
|
|
||||||
|
updateStatusIndicator(currentState, currentText);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!registerStatusCallback()) {
|
||||||
// Wait for WebSocket manager to be available
|
// Wait for WebSocket manager to be available
|
||||||
var checkInterval = setInterval(function() {
|
var checkInterval = setInterval(function() {
|
||||||
if (typeof wsManager !== 'undefined' && wsManager) {
|
if (registerStatusCallback()) {
|
||||||
wsManager.onStatusChange(function(state, text) {
|
|
||||||
updateStatusIndicator(state, text);
|
|
||||||
});
|
|
||||||
clearInterval(checkInterval);
|
clearInterval(checkInterval);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
// Stop checking after 5 seconds to avoid infinite loop
|
||||||
|
setTimeout(function() {
|
||||||
|
clearInterval(checkInterval);
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user