ws.onmessage = (event) => { let data = event.data; if (typeof data === "string") { console.log("Received string data:", data); } elseif (data instanceofArrayBuffer) { console.log("Received ArrayBuffer data:", data); // If you need to convert the ArrayBuffer to a byte array, you can do this: const byteArray = newUint8Array(data); console.log("Byte array:", byteArray); } elseif (data instanceofBlob) { console.log("Received Blob data:", data); // If you need to convert the Blob to an ArrayBuffer or byte array, you can use FileReader const reader = newFileReader(); reader.onload = () => { const arrayBuffer = reader.resultasArrayBuffer; console.log("ArrayBuffer:", arrayBuffer); const byteArray = newUint8Array(arrayBuffer); console.log("Byte array:", byteArray); let jsonString = newTextDecoder().decode(byteArray); console.log("jsonSt =", jsonString); let data1 = JSON.parse(jsonString); console.log("data1 =", data1); }; reader.readAsArrayBuffer(data); } else { console.log("Received unknown data type:", data); } };