refresh browser on connection loss

This commit is contained in:
pavel 2026-02-26 23:43:43 +01:00
commit 8847f3fcf6

View file

@ -698,8 +698,9 @@ function initChatWs() {
}; };
ws.onclose = () => { ws.onclose = () => {
console.log("Chat WS closed, reconnecting..."); console.log("Chat WS closed, refreshing page for resilience...");
setTimeout(initChatWs, 3000); // Automatically refresh on connection loss instead of just background reconnecting
location.reload();
}; };
} }
@ -1187,6 +1188,7 @@ async function joinVoice() {
state.voice.ws = ws; state.voice.ws = ws;
state.voice.joinedChannelId = state.selectedVoiceChannelId; state.voice.joinedChannelId = state.selectedVoiceChannelId;
localStorage.setItem("active_voice_channel", state.selectedVoiceChannelId);
// Start mic setup in parallel so channel join is not blocked by device init. // Start mic setup in parallel so channel join is not blocked by device init.
createLocalVoiceStream() createLocalVoiceStream()
@ -1318,6 +1320,7 @@ async function joinVoice() {
} }
async function leaveVoice() { async function leaveVoice() {
localStorage.removeItem("active_voice_channel");
if (state.voice.ws) state.voice.ws.close(); if (state.voice.ws) state.voice.ws.close();
} }
@ -1900,6 +1903,18 @@ async function init() {
initChatWs(); initChatWs();
startVoicePresencePolling(); startVoicePresencePolling();
// Auto-reconnect to voice if previously joined
const savedVoiceChannel = localStorage.getItem("active_voice_channel");
if (savedVoiceChannel) {
console.log("Auto-reconnecting to voice channel:", savedVoiceChannel);
state.selectedVoiceChannelId = savedVoiceChannel;
// Wait for components to be ready
setTimeout(() => {
joinVoice().catch(err => console.error("Auto-reconnect failed", err));
}, 800);
}
lucide.createIcons(); lucide.createIcons();
} catch (err) { } catch (err) {
console.error("init failed", err); console.error("init failed", err);