support all request body types

This commit is contained in:
ading2210 2024-03-10 03:53:59 -04:00
parent 997b2afca4
commit e2b50db5fa
6 changed files with 56 additions and 60 deletions

View file

@ -73,7 +73,6 @@ class FakeWebSocket extends EventTarget {
}
send(data) {
let is_text = typeof data === "string";
if (this.status === this.CONNECTING) {
throw new DOMException("websocket not ready yet");
}
@ -81,15 +80,18 @@ class FakeWebSocket extends EventTarget {
return;
}
(async () => {
if (is_text) {
this.socket.send(data);
}
else {
let data_array = await data_to_array(data);
this.send(data_array);
}
})();
if (data instanceof Blob) {
(async () => {
let array_buffer = await data.arrayBuffer();
this.socket.send(new Uint8Array(array_buffer));
})();
}
else if (typeof data === "string") {
this.socket.send(data);
}
else {
this.socket.send(data_to_array(data));
}
}
close() {