Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

javascript - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...