v51: onclose даёт 500ms фору onmessage — close frame обгонял text frame

This commit is contained in:
“Naeel”
2026-05-22 17:20:25 +04:00
parent 8fc986fe7f
commit 0504c6009c
+8 -2
View File
@@ -53,7 +53,7 @@ let mediaRecorder, audioChunks = [], userAudioBlob = null, ttsText = '';
let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null; let isRecording = false, isAnalyzing = false, micAnalyser = null, micAnimId = null;
let recordStartTime = 0, recordDuration = 0; let recordStartTime = 0, recordDuration = 0;
// ---------- Версия ---------- // ---------- Версия ----------
const VERSION = 'v50'; const VERSION = 'v51';
document.getElementById('ver').textContent = VERSION; document.getElementById('ver').textContent = VERSION;
// ---------- Перевод на русский (Groq) ---------- // ---------- Перевод на русский (Groq) ----------
@@ -660,7 +660,13 @@ async function transcribe(blob) {
}; };
ws.onerror = () => { console.log('[WS] error'); clearTimeout(timeout); done({ text: '', error: 'network' }); }; ws.onerror = () => { console.log('[WS] error'); clearTimeout(timeout); done({ text: '', error: 'network' }); };
ws.onclose = (e) => { console.log('[WS] close code=' + e.code); clearTimeout(timeout); done({ text: '', error: 'network' }); }; ws.onclose = (e) => {
console.log('[WS] close code=' + e.code);
// close может прийти раньше onmessage — даём фору 500ms
setTimeout(() => {
if (!settled) { clearTimeout(timeout); done({ text: '', error: 'network' }); }
}, 500);
};
}); });
} }