Here https://developer.mozilla.org/en/WebSockets/WebSockets_reference/MessageEvent it states attribute data is of type DOMString| Blob | ArrayBuffer. How do I tell it which type I want? Or how do I know which type I get?
The appropriate two types of frames that a server can send are text frames and binary frames (5.2). The ws.binaryType
allows you to define in which format you'd like to obtain the binary data.
binaryType
being set to either arraybuffer
or blob
To determine the type, you can use:
e.data instanceof ArrayBuffer
e.data instanceof Blob
typeof e.data === "string"
4. If type indicates that the data is Text, then initialize event's
data
attribute to data.If type indicates that the data is Binary, and
binaryType
is set to "blob
", then initialize event'sdata
attribute to a newBlob
object that represents data as its raw data.If type indicates that the data is Binary, and
binaryType
is set to "arraybuffer
", then initialize event'sdata
attribute to a new read-onlyArrayBuffer
object whose contents aredata
.