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 = () => {
console.log("Chat WS closed, reconnecting...");
setTimeout(initChatWs, 3000);
console.log("Chat WS closed, refreshing page for resilience...");
// 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.joinedChannelId = state.selectedVoiceChannelId;
localStorage.setItem("active_voice_channel", state.selectedVoiceChannelId);
// Start mic setup in parallel so channel join is not blocked by device init.
createLocalVoiceStream()
@ -1318,6 +1320,7 @@ async function joinVoice() {
}
async function leaveVoice() {
localStorage.removeItem("active_voice_channel");
if (state.voice.ws) state.voice.ws.close();
}
@ -1900,6 +1903,18 @@ async function init() {
initChatWs();
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();
} catch (err) {
console.error("init failed", err);