fix: éliminer doublon fonction send() et ws.onmessage dans le JS

- Le patch timeout avait créé un doublon: send() avec timeout puis send() sans timeout
- ws.onmessage défini deux fois (dans connect() et hors connect())
- Nettoyage: ws.onmessage uniquement dans connect(), send() unique avec timeout
- Correction du SyntaxError 'Unexpected end of input' causé par le JS corrompu
This commit is contained in:
2026-06-19 23:27:59 -04:00
parent 398ad2f295
commit c8d5d2048c
+7 -4
View File
@@ -91,11 +91,14 @@ ws.onopen=()=>{recon=0;reconDelay=2000;s.textContent='🟢 Connecté — JARVIS
ws.onclose=()=>{b.disabled=true;if(recon<reconMax){recon++;let d=Math.min(reconDelay*Math.pow(1.5,recon-1),30000); ws.onclose=()=>{b.disabled=true;if(recon<reconMax){recon++;let d=Math.min(reconDelay*Math.pow(1.5,recon-1),30000);
s.textContent='🟡 Reconnexion '+recon+'/'+reconMax+' dans '+Math.round(d/1000)+'s...';s.className='off';setTimeout(connect,d)} s.textContent='🟡 Reconnexion '+recon+'/'+reconMax+' dans '+Math.round(d/1000)+'s...';s.className='off';setTimeout(connect,d)}
else{s.textContent='🔴 Connexion perdue — recharge la page';s.className='off'}}; else{s.textContent='🔴 Connexion perdue — recharge la page';s.className='off'}};
ws.onerror=()=>ws.close();
ws.onmessage=e=>{try{let d=JSON.parse(e.data);if(ws._tid){clearTimeout(ws._tid);ws._tid=null}
if(d.type==='welcome')m(d.content,'sys');
else if(d.type==='response')m(d.content,'jarvis');
else if(d.type==='thinking')s.textContent='🤔 JARVIS réfléchit...';
else if(d.type==='error')m('❌ '+d.content,'sys')}catch(x){m(e.data,'jarvis')};
s.textContent='🟢 Connecté — JARVIS v3 prêt';b.disabled=false}}
function send(){let t=i.value.trim();if(!t||!ws||ws.readyState!==WebSocket.OPEN)return;m(t,'user');ws.send(JSON.stringify({text:t}));i.value='';b.disabled=true;s.textContent='🤔 JARVIS réfléchit...';let tid=setTimeout(()=>{if(b.disabled){b.disabled=false;s.textContent='⚠️ JARVIS prend du temps... tu peux réessayer'}},25000);ws._tid=tid} function send(){let t=i.value.trim();if(!t||!ws||ws.readyState!==WebSocket.OPEN)return;m(t,'user');ws.send(JSON.stringify({text:t}));i.value='';b.disabled=true;s.textContent='🤔 JARVIS réfléchit...';let tid=setTimeout(()=>{if(b.disabled){b.disabled=false;s.textContent='⚠️ JARVIS prend du temps... tu peux réessayer'}},25000);ws._tid=tid}
ws.onmessage=e=>{try{let d=JSON.parse(e.data);if(ws._tid){clearTimeout(ws._tid);ws._tid=null};if(d.type==='welcome')m(d.content,'sys');
else if(d.type==='response')m(d.content,'jarvis');else if(d.type==='thinking')s.textContent='🤔 JARVIS réfléchit...';
else if(d.type==='error')m('❌ '+d.content,'sys')}catch(x){m(e.data,'jarvis')};s.textContent='🟢 Connecté — JARVIS v3 prêt';b.disabled=false}
function send(){let t=i.value.trim();if(!t||!ws||ws.readyState!==WebSocket.OPEN)return;m(t,'user');ws.send(JSON.stringify({text:t}));i.value='';b.disabled=true;s.textContent='🤔 JARVIS réfléchit...'}
b.onclick=send;i.onkeydown=e=>{if(e.key==='Enter')send()};connect() b.onclick=send;i.onkeydown=e=>{if(e.key==='Enter')send()};connect()
</script> </script>
</body> </body>