quic and dirty fix
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user