mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -04:00
fix: add binarytype support to websocket
This commit is contained in:
parent
a105aa97ce
commit
15c75b4c36
1 changed files with 18 additions and 2 deletions
|
@ -65,9 +65,25 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
barews.addEventListener("close", (ev) => {
|
||||
fakeEventSend(new CloseEvent("close", ev));
|
||||
});
|
||||
barews.addEventListener("message", (ev) => {
|
||||
barews.addEventListener("message", async (ev) => {
|
||||
let payload = ev.data;
|
||||
if (typeof payload === "string") {
|
||||
// DO NOTHING
|
||||
} else if ("byteLength" in payload) {
|
||||
if (state.binaryType === "blob") {
|
||||
payload = new Blob([payload]);
|
||||
} else {
|
||||
Object.setPrototypeOf(payload, ArrayBuffer.prototype);
|
||||
}
|
||||
} else if ("arrayBuffer" in payload) {
|
||||
if (state.binaryType === "arraybuffer") {
|
||||
payload = await payload.arrayBuffer();
|
||||
Object.setPrototypeOf(payload, ArrayBuffer.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
const fakeev = new MessageEvent("message", {
|
||||
data: ev.data,
|
||||
data: payload,
|
||||
origin: ev.origin,
|
||||
lastEventId: ev.lastEventId,
|
||||
source: ev.source,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue