Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox not understanding that a variable contains an ArrayBuffer while Chrome does

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?

enter image description here

like image 704
JensB Avatar asked Nov 15 '18 20:11

JensB


People also ask

Is ArrayBuffer same as buffer?

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 .

What is 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".


1 Answers

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.

like image 196
jib Avatar answered Nov 14 '22 22:11

jib