我无法让 firefox 读取一个 blob,或者更确切地说理解一个包含 ArrayBuffer 的变量。
我正在用 typescript 试验 WebRTC。
// Create a data Channel for communication
this.gameChannel = this.RtcConnection.createDataChannel('g', gameDataChannelOptions);
// Start listener
this.gameChannel.onmessage = function (event: any) {
console.log(event);
}
上面的代码在 chrome 中有效,但在 firefox 中无效,或者更确切地说,firefox 无法读取结果数据(或者很可能是我做错了什么)。
下面是 chrome 和 FF 的控制台,注意在 chrome 中我看到了预期的数据,而在 FF 中我只得到了预期长度的 blob,但我似乎无法访问它。
如何在两种浏览器中获得相同的结果?
最佳答案
设置 this.gameChannel.binaryType = "arraybuffer"
使其工作。
Firefox 是正确的,因为 "blob"
是默认的二进制类型。飞行员错误。
Chrome does not yet implement “blob”
,这可能就是它默认为数组缓冲区的原因。如果我在 Chrome 中设置 "blob"
我会得到:
Failed to set the 'binaryType' property on 'RTCDataChannel':
Blob support not implemented yet
不幸的是,正如您的问题所示,这会导致网络兼容性问题。
关于javascript - Firefox 不理解变量包含 ArrayBuffer 而 Chrome 理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53327281/