add better clarification on websocket payload conversion

This commit is contained in:
Percs 2024-10-21 13:44:45 -05:00
parent 2760770b3d
commit baa9884d5d

View file

@ -70,12 +70,14 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
if (typeof payload === "string") { if (typeof payload === "string") {
// DO NOTHING // DO NOTHING
} else if ("byteLength" in payload) { } else if ("byteLength" in payload) {
// arraybuffer, convert to blob if needed or set the proper prototype
if (state.binaryType === "blob") { if (state.binaryType === "blob") {
payload = new Blob([payload]); payload = new Blob([payload]);
} else { } else {
Object.setPrototypeOf(payload, ArrayBuffer.prototype); Object.setPrototypeOf(payload, ArrayBuffer.prototype);
} }
} else if ("arrayBuffer" in payload) { } else if ("arrayBuffer" in payload) {
// blob, convert to arraybuffer if neccesary.
if (state.binaryType === "arraybuffer") { if (state.binaryType === "arraybuffer") {
payload = await payload.arrayBuffer(); payload = await payload.arrayBuffer();
Object.setPrototypeOf(payload, ArrayBuffer.prototype); Object.setPrototypeOf(payload, ArrayBuffer.prototype);