From c8d5d2048cacd44b202bf81520eeab5e0453d923 Mon Sep 17 00:00:00 2001 From: Bruno Charest Date: Fri, 19 Jun 2026 23:27:59 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=C3=A9liminer=20doublon=20fonction=20sen?= =?UTF-8?q?d()=20et=20ws.onmessage=20dans=20le=20JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- bot_direct.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bot_direct.py b/bot_direct.py index 892eb02..1e5eca1 100644 --- a/bot_direct.py +++ b/bot_direct.py @@ -91,11 +91,14 @@ ws.onopen=()=>{recon=0;reconDelay=2000;s.textContent='🟢 Connecté — JARVIS ws.onclose=()=>{b.disabled=true;if(reconws.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} -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()