Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Can't send files #1137

Closed
worldzb opened this issue Sep 20, 2023 · 8 comments · Fixed by #1142
Closed

[bug] Can't send files #1137

worldzb opened this issue Sep 20, 2023 · 8 comments · Fixed by #1142

Comments

@worldzb
Copy link

worldzb commented Sep 20, 2023

Error

binarypack.ts:336 Uncaught Error: Type "function Blob() { [native code] }" not yet supported
    at $0cfd7828ad59115f$export$b9ec4b114aa40074.pack (binarypack.ts:336:12)
    at $0cfd7828ad59115f$export$b9ec4b114aa40074.pack_object (binarypack.ts:466:10)
    at $0cfd7828ad59115f$export$b9ec4b114aa40074.pack (binarypack.ts:334:11)
    at $0cfd7828ad59115f$export$2a703dbb0cb35339 (binarypack.ts:31:9)
    at $9fcfddb3ae148f88$export$f0a5a64d5bb37108._send (BinaryPack.ts:82:16)
    at $9fcfddb3ae148f88$export$f0a5a64d5bb37108.send (DataConnection.ts:138:15)
    at sendFile (useP2P.ts:123:10)
    at handleOnChange (SendFile.tsx:20:5)
    at HTMLUnknownElement.callCallback2 (react-dom.development.js:4164:14)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:16)

environment

"peerjs": "^1.5.0",

When I use 1.5.0, there will be error that Blob does not support。But when I use 1.4.7, there is no problem
I guess, the reason should be on Peerjs-JS-BinaryPack.At 2.0.0, I rewritten the problem with TS

@jonasgloning
Copy link
Member

jonasgloning commented Sep 20, 2023

It seems like your environment does not support Blob natively. Can you tell me more about it? How do you provoke this error? Is is emitted in a browser, or during a build step?

You could try to overwrite window.Blob with a polyfill like https://www.npmjs.com/package/blob-polyfill

@worldzb
Copy link
Author

worldzb commented Sep 21, 2023

I am using the latest version of Chrome,
Version 116.0.5845.140 (Official Build) (arm64)
so there should be no issue with blob support. I compared the source code of 1.0.1 and 2.0.0, and found the cause of the error.

v1.0.1 /lib/binarypack.js
image

v2.0.0 /lib/binarypack.ts
image

Based on the comparison of the source code, I suspect that in v2.0.0, there was a missing check for Blob and file types.

@jonasgloning
Copy link
Member

Ah, thank you!

Previously, Binarypack was designed to produce Blobs, which allowed packing another Blob to be a synchronous operation. However, we now emit ArrayBuffers. Converting from Blob to ArrayBuffer is an async only operation.

To avoid making all of Binarypacks interface async, Blobs should to be a special case within send(). This was proabaly lost somewhere in a feature branch. I’ll rectify this later this evening, or tomorrow at the lastest.

jonasgloning added a commit that referenced this issue Sep 23, 2023
As this is an `async` operation, we need to `await conn.send(..)` to
keep the order of transmitted files.

Closes #1137
@jonasgloning jonasgloning linked a pull request Sep 23, 2023 that will close this issue
github-actions bot pushed a commit that referenced this issue Sep 23, 2023
## [1.5.1](v1.5.0...v1.5.1) (2023-09-23)

### Bug Fixes

* convert `Blob`s to `ArrayBuffer`s during `.send()` ([95bb0f7](95bb0f7)), closes [#1137](#1137)
* convert `Blob`s to `ArrayBuffer`s during `.send()` ([#1142](#1142)) ([094f849](094f849))
@github-actions
Copy link

🎉 This issue has been resolved in version 1.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Lianting-Wang
Copy link

Lianting-Wang commented Nov 12, 2023

I find it strange that I am still experiencing the same problem when using 1.5.1.

<script src="https://unpkg.com/peerjs@1.5.1/dist/peerjs.min.js"></script>
Uncaught (in promise) Error: Type "function Blob() { [native code] }" not yet supported
    at a.pack (binarypack.ts:336:16)
    at a.pack_object (binarypack.ts:466:10)
    at a.pack (binarypack.ts:334:11)
    at o (binarypack.ts:31:9)
    at eQ._send (BinaryPack.ts:87:16)
    at eQ.send (DataConnection.ts:138:15)
    at sendFile (script.js:114:8)

(Incidentally my code works fine with version 1.3.1)

@jonasgloning
Copy link
Member

Could you give me bit of code to reproduce your error, @Lianting-Wang?
What do you try to send?

@ga676005
Copy link

ga676005 commented Nov 20, 2023

This is the sample code from P2P File Transfer example which works in 1.4.7.

function sendFile() {
  const file = fileInput.files[0]
  const blob = new Blob([file], { type: file.type })

  peerConnection.send({
    dataType: 'FILE',
    file: blob,
    fileName: file.name,
    fileType: file.type,
  })
}

In 1.5.1, we can send file directly, but if we send like above we would get Uncaught Error: Type "function Blob() { [native code] }" not yet supported. Does sending blob no longer being supported?

function sendFile() {
  const file = fileInput.files[0]
  peerConnection.send(file)
}

@jonasgloning
Copy link
Member

Thank you, @ga676005. Your code helped me to reproduce this. Now tracking this in #1163.

@peers peers locked and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants