ITADN

Cause for firefox not being supported: RTCDataChannel.binaryType deafults to "blob"

#24Closedminwidth0px 创建于 2024-08-08
M
minwidth0pxcommented
I looked into the issue of Firefox not working, and the issue appears to be that the default value for [RTCDataChannel.binaryType](https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/binaryType) on Firefox is `"blob"` and on Chrome and Webkit it's `"arraybuffer"`. Originally, the spec's default value was `"blob"`, but chrome never respected that, and the default value was actually changed to `"arraybuffer"` in January of this year (see https://github.com/w3c/webrtc-pc/issues/2170), but Firefox has not implemented that yet. Interestingly, chrome started supporting "blob" as of last week (see https://issues.webrtc.org/issues/41480941). What is more, setting `datachannel.binaryType = "arraybuffer"` in `WebRtcModule.connect` alone does not solve it. The `RTCDataChannel` when logged shows that it is of binaryType `"arraybuffer"`, but when printing the following in `NetSocket.connect` you can see that the messages being sent are still of type `"blob"`: ```js #onMessage(event) { console.log(event.data) if(event.data instanceof Blob) { console.log("Blob detected") event.data.arrayBuffer().then(buffer => { console.log("decoded text: ", new TextDecoder().decode(new Uint8Array(buffer))); }); } console.log(new TextDecoder().decode(new Uint8Array(event.data))); this.#readchannel.send(new Uint8Array(event.data)); } ``` Firefox: ``` Blob { size: 47, type: "" } Blob detected <empty string> decoded text: �������'{"headers":{},"method":"GET","url":"/"} ``` Chrome: ``` byteLength: 47detached: falsemaxByteLength: 47resizable: false[[Prototype]]: ArrayBuffer[[Int8Array]]: Int8Array(47)[[Uint8Array]]: Uint8Array(47)[[ArrayBufferByteLength]]: 47[[ArrayBufferData]]: 1509 '{"headers":{},"method":"GET","url":"/"} ``` I plan to investigate the root cause of this issue and maybe file a PR. For now, the following fixes the issue and allows Smoke to work on Firefox: ```js #onMessage(event) { if(event.data instanceof Blob) { event.data.arrayBuffer().then(buffer => { this.#readchannel.send(new Uint8Array(buffer)); }); }else{ this.#readchannel.send(new Uint8Array(event.data)); } } ``` Looks like https://bugzilla.mozilla.org/show_bug.cgi?id=1245138 might be related here: >If you want to receive data as an arraybuffer, you must set it to arraybuffer on the receiver side Although it is set on the receiver's side as well in this case...
关闭于 2024-08-09 7 条评论