Firefox not understanding that a variable contains

2020-02-14 05:38发布

问题:

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:

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.