Fix possible race condition in player auto-connect

This commit is contained in:
Christopher Cookman 2026-05-14 14:54:17 -06:00
parent 98e742c612
commit f6ef75549b

View file

@ -366,17 +366,23 @@
// ==================== Boot ==================== // ==================== Boot ====================
// Function used by connect button and auto-connect // Function used by connect button and auto-connect
let autoContinueTimer;
function connectBtnFunc() { function connectBtnFunc() {
unlockAudio(); if (autoContinueTimer) {
const url = document.getElementById('serverUrl').value.trim().replace(/\/$/, ''); clearInterval(autoContinueTimer);
if (!url) return; autoContinueTimer = null;
config.serverUrl = url; document.getElementById('connectBtn').textContent = _t('connect');
saveConfig(config); }
document.getElementById('connectBtn').disabled = true; unlockAudio();
document.getElementById('setupSpinner').style.display = 'block'; const url = document.getElementById('serverUrl').value.trim().replace(/\/$/, '');
document.getElementById('setupStatus').textContent = 'Connecting...'; if (!url) return;
connect(url); config.serverUrl = url;
}; saveConfig(config);
document.getElementById('connectBtn').disabled = true;
document.getElementById('setupSpinner').style.display = 'block';
document.getElementById('setupStatus').textContent = 'Connecting...';
connect(url);
};
// Auto-detect server URL from origin since player is served from the same server // Auto-detect server URL from origin since player is served from the same server
if (!config.serverUrl) { if (!config.serverUrl) {
@ -433,7 +439,7 @@
connectBtn.textContent = `${_t('connect')} (${countdown})`; connectBtn.textContent = `${_t('connect')} (${countdown})`;
const autoContinueTimer = setInterval(() => { autoContinueTimer = setInterval(() => {
countdown--; countdown--;
if (countdown > 0) { if (countdown > 0) {
connectBtn.textContent = `${_t('connect')} (${countdown})`; connectBtn.textContent = `${_t('connect')} (${countdown})`;