I have trouble making firefox read a blob, or rather understand a variable contains an ArrayBuffer.
I am experimenting with WebRTC in typescript.
// Create a data Channel for communication
this.gameChannel = this.RtcConnection.createDataChannel('g', gameDataChannelOptions);
// Start listener
this.gameChannel.onmessage = function (event: any) {
console.log(event);
}
The above code is working in chrome, but not in firefox, or rather firefox cannot read the resulting data (or most likely I'm doing something wrong).
Below is the console in chrome and FF, notice that in chrome I am seeing the expected data, while in FF I just get a blob of the expected length, but I cant seem to access it.
How do I get the same result in both browsers?
1. A Buffer is just a view for looking into an ArrayBuffer . A Buffer , in fact, is a FastBuffer , which extends (inherits from) Uint8Array , which is an octet-unit view (“partial accessor”) of the actual memory, an ArrayBuffer .
The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. It is an array of bytes, often referred to in other languages as a "byte array".
Set this.gameChannel.binaryType = "arraybuffer"
to make it work.
Firefox is correct, because "blob"
is the default binary type. Pilot error.
Chrome does not yet implement "blob"
, which is probably why it defaults to array buffer. If I set "blob"
in Chrome I get:
Failed to set the 'binaryType' property on 'RTCDataChannel':
Blob support not implemented yet
Unfortunately, this is causing web compatibility issues, as your question demonstrates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With