WebSocket auto-reconnect: yhteys palautuu 3s kuluttua katkoksesta
connectHub() luo uuden WebSocketin ja asettaa onopen/onclose/onmessage. onclose käynnistää 3s timerin joka kutsuu connectHub() uudelleen. Terminaaliin tulee '↻ Yhdistetään uudelleen...' -viesti. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1672,9 +1672,19 @@
|
||||
if (e.key === 'Enter') sendUserText();
|
||||
});
|
||||
|
||||
// Kytkemme sivuston UI-puolen (JS) omaan passiiviseen WebSocket-kuuntelijaan.
|
||||
const uiSocket = new WebSocket(`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`);
|
||||
// WebSocket-yhteys hubiin — automaattinen reconnect
|
||||
const wsUrl = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`;
|
||||
let uiSocket = null;
|
||||
let wsReconnectTimer = null;
|
||||
|
||||
function connectHub() {
|
||||
if (uiSocket && (uiSocket.readyState === 0 || uiSocket.readyState === 1)) return;
|
||||
uiSocket = new WebSocket(wsUrl);
|
||||
window._uiSocket = uiSocket;
|
||||
// Kytketään onmessage uudelleen (handler määritellään myöhemmin, asetetaan kun valmis)
|
||||
setTimeout(() => {
|
||||
if (window._wsMessageHandler) uiSocket.onmessage = window._wsMessageHandler;
|
||||
}, 0);
|
||||
uiSocket.onopen = async () => {
|
||||
// Päivitetään agents-näkymän hub-status
|
||||
const hubDot = document.getElementById('agent-hub-dot');
|
||||
@@ -1746,7 +1756,18 @@
|
||||
coderEl.textContent = 'Disconnected';
|
||||
coderEl.style.color = '#f85149';
|
||||
}
|
||||
// Automaattinen reconnect 3s kuluttua
|
||||
if (!wsReconnectTimer) {
|
||||
wsReconnectTimer = setTimeout(() => {
|
||||
wsReconnectTimer = null;
|
||||
termLog(' <span style="color:#d29922">↻ Yhdistetään uudelleen...</span>');
|
||||
connectHub();
|
||||
}, 3000);
|
||||
}
|
||||
};
|
||||
} // connectHub()
|
||||
connectHub();
|
||||
|
||||
// Terminaalin komentorivi
|
||||
const termInput = document.getElementById('term-input');
|
||||
const termPanel = document.getElementById('agent-terminal');
|
||||
@@ -2753,7 +2774,8 @@ Files: ${Object.keys(generatedFiles).join(', ')}`;
|
||||
// Klikkaa terminaalipaneelia → fokusoi input
|
||||
termPanel?.addEventListener('click', () => termInput?.focus());
|
||||
|
||||
uiSocket.onmessage = (event) => {
|
||||
// Tallennetaan message-handler funktioon jotta reconnect voi käyttää samaa
|
||||
const _wsHandler = (event) => {
|
||||
try {
|
||||
const raw = event.data;
|
||||
if (raw.includes('"single_tokenize"')) return;
|
||||
@@ -3115,6 +3137,8 @@ Files: ${Object.keys(generatedFiles).join(', ')}`;
|
||||
}
|
||||
} catch(e) {}
|
||||
};
|
||||
window._wsMessageHandler = _wsHandler;
|
||||
if (uiSocket) uiSocket.onmessage = _wsHandler;
|
||||
|
||||
btn.addEventListener('click', async () => {
|
||||
// Käytetään viewer-authissa jo tunnistettua WebGPU-tilaa
|
||||
|
||||
Reference in New Issue
Block a user