type alias BinaryType
Specifies the type of binary data being received over a WebSocket connection.
"blob": Binary data is returned asBlobobjects"arraybuffer": Binary data is returned asArrayBufferobjects
Examples #
#
// Setting up WebSocket for binary data as ArrayBuffer
const ws = new WebSocket("ws://localhost:8080");
ws.binaryType = "arraybuffer";
ws.onmessage = (event) => {
if (event.data instanceof ArrayBuffer) {
// Process binary data
const view = new Uint8Array(event.data);
console.log(`Received binary data of ${view.length} bytes`);
} else {
// Process text data
console.log(`Received text: ${event.data}`);
}
};
// Sending binary data
const binaryData = new Uint8Array([1, 2, 3, 4]);
ws.send(binaryData.buffer);
Definition #
"arraybuffer" | "blob"