quic and dirty fix

This commit is contained in:
2025-05-05 11:26:59 +02:00
parent bfa0ba8edf
commit 9315abc488
4 changed files with 55 additions and 23 deletions

View File

@@ -99,6 +99,8 @@ class MainScreen implements PresentationScreen {
}
public async end(): Promise<void> {
this.dom_root.style.opacity = "0";
await sleep(500);
}
private async show_question(text: string): Promise<void> {
@@ -231,6 +233,7 @@ class IdleScreen implements PresentationScreen {
}
public async start(): Promise<void> {
await sleep(10);
this.dom_title.style.transform = "translateY(0)";
this.dom_title.style.opacity = "1";
await sleep(250);

View File

@@ -92,7 +92,8 @@ export class PythagorasClient {
private async recv_inner_bytes(): Promise<Uint8Array> {
const received = await this.recv_inner();
if (received.bytes !== undefined) { return await received.bytes(); }
return utf8_encode(await received.text());
const text = await received.text();
return utf8_encode(text);
}
/**
@@ -115,16 +116,12 @@ export class PythagorasClient {
public async recv(): Promise<PythagorasIncomingMessage> {
while (true) {
const advertised_length = uint_bytes_to_num(await this.recv_length(4));
try {
const payload = utf8_decode(await this.recv_length(advertised_length));
const parsed = JSON.parse(payload);
console.log(parsed);
return parsed;
} catch {
this.buf = new Uint8Array(0);
await this.reconnect();
}
const payload = await this.recv_inner();
const text = payload.bytes === undefined ?
(await payload.text()).slice(4) : (utf8_decode((await payload.bytes()).slice(4)));
console.log("payload:", text);
const parsed = JSON.parse(text);
return parsed;
}
}
}

View File

@@ -9,7 +9,15 @@ export function uint_bytes_to_num(value: Uint8Array): number {
export function utf8_encode(value: string): Uint8Array {
const encoder = new TextEncoder();
return encoder.encode(value);
let res: Uint8Array = new Uint8Array(0);
for (const ch of value) {
const cur = encoder.encode(ch)[0];
const prev = res;
res = new Uint8Array(prev.length + 1);
res.set(prev, 0);
res.set([cur], prev.length);
}
return res;
}
export function utf8_decode(value: Uint8Array): string {