fixed delayed WS bug

This commit is contained in:
MathMan05 2024-07-30 21:04:23 -05:00
parent ebea3af112
commit fb4721196b
2 changed files with 36 additions and 19 deletions

View file

@ -167,15 +167,23 @@ class Localuser{
w.write(arr.buffer);
arr=new Uint8Array();
//console.log(data,test);
const read=(await r.read());
const data=new TextDecoder().decode(read.value);
build+=data;
console.log("temp");
try{
temp=JSON.parse(build);
build="";
}catch{
return;
while(true){
const read=(await r.read());
const data=new TextDecoder().decode(read.value);
if(data===""){
break;
}
build+=data;
console.log("temp");
try{
temp=JSON.parse(build);
build="";
if(temp.op===0&&temp.t==="READY"){
returny();
}
this.handleEvent(temp);
}catch{
}
}
}else{
temp=JSON.parse(event.data);
@ -184,6 +192,7 @@ class Localuser{
returny();
}
this.handleEvent(temp);
});
this.ws.addEventListener("close", event => {