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

Order not preserved while sending data #746

Closed
aniket-banyal opened this issue Oct 9, 2020 · 10 comments · Fixed by #1038
Closed

Order not preserved while sending data #746

aniket-banyal opened this issue Oct 9, 2020 · 10 comments · Fixed by #1038

Comments

@aniket-banyal
Copy link

This is a part of my code that I am using to transfer files.

 const CHUNK_SIZE = 16 * 1024
 file = e.target.files[0]
 let i
 let idx = 0
 for (i = 0; i < file.size; i += CHUNK_SIZE) {
     connection.send({ chunk: file.slice(i, i + CHUNK_SIZE), idx })
     idx++
 }

When this data is received on the other user's end then I print the idx received and all of them are in the right order except the last two.
Example -
0
1
2
.
.
.
207
209
208

This is happening for all the files but most of the files are opening without any problem while some of them are not.

I tried setting the ordered attribute to true but it still remained false -

 connection = peer.connect(userId)
 connection.dataChannel.ordered = true
@Swanand01
Copy link

The same has been happening with me. The second to last chunk is always received before the last one.

@cohenstyle
Copy link

Yeah. It's not setting the DC to ordered unfortunately. Having the same issue.

@jonasgloning

This comment was marked as outdated.

github-actions bot pushed a commit that referenced this issue Feb 25, 2023
## [1.4.8-rc.1](v1.4.7...v1.4.8-rc.1) (2023-02-25)

### Bug Fixes

* `close` event was not triggered reliably ([#860](#860)) ([ec1d5ae](ec1d5ae)), closes [#636](#636)
* **datachannel:** sending order is now preserved correctly ([18d491a](18d491a)), closes [#746](#746)
* **deps:** update dependency @swc/helpers to ^0.4.0 ([a7de8b7](a7de8b7))
* **deps:** update dependency eventemitter3 to v5 ([caf01c6](caf01c6))
* **deps:** update dependency webrtc-adapter to v8 ([431f00b](431f00b))
* **npm audit:** Updates all dependencies that cause npm audit to issue a warning ([6ef5707](6ef5707))
@github-actions
Copy link

🎉 This issue has been resolved in version 1.4.8-rc.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jonasgloning
Copy link
Member

I published a new beta release that should respect the ordering (except for File/Blobs)
Please test it!

You can get it on npm via

npm i peerjs@rc

@cohenstyle
Copy link

Thanks a lot!
I was using it with files though so I don't have a setup that can test it.

@jonasgloning
Copy link
Member

Please don’t feel obligated to try, but maybe you could call file.arrayBuffer() before passing it to PeerJS.
Then there’s no async operation left in the send operation, and the order can be guaranteed.

const file : File = ....
const ab : ArrayBuffer = await file.arrayBuffer();
dataConnection.send(ab)

We could also make send itself async, but awaiting this could be confusing as a return would only mean "in buffer", not "on the wire".

@brianismeta
Copy link

brianismeta commented Mar 7, 2023

I was having an ordering issue but I thought it had to do with UDP... there are many data packets being transferred between two peers, and sometimes it gets out of order very quickly, or it gets out of order after a few hundred packets. I forced communication through TURN and used TCP channel, and the issue was resolved, as far as I could tell. I am assuming it was still a UDP issue but after reading this issue - is it possible it could have been this issue -- or does this issue only occur at the very "end" of the data channel communications (??) (Also my presumption is that UDP packets can get dropped anywhere along the way, whereas TCP will ensure it gets to the other side)

@jonasgloning
Copy link
Member

Hi @brianismeta, WebRTC’s data channels use SCTP, not UDP or TCP.
If you want to keep the order of messages, you’ll have to set {reliable: true} in the Peer.connect call. This setting will become the default soon. (Do you mean this with TCP channel?)
Forcing the traffic over TURN has no influence on the order.

If your issue gets resolved when using a "TCP channel", you are probably not affected by this issue. If not, please give the beta version a try.

jonasgloning added a commit that referenced this issue Jun 22, 2023
This upgrades `binarypack` to version 2.

`pack` now returns `ArrayBuffer`s which can be sent over all data
channel types without asynchronous conversion.
This implementation is also much faster than version 1.

Closes #746
github-actions bot pushed a commit that referenced this issue Aug 14, 2023
# [1.5.0-rc.1](v1.4.8-rc.1...v1.5.0-rc.1) (2023-08-14)

### Bug Fixes

* **datachannel:** sending order is now preserved correctly ([#1038](#1038)) ([0fb6179](0fb6179)), closes [#746](#746)
* **deps:** update dependency peerjs-js-binarypack to v1.0.2 ([7452e75](7452e75))
* **deps:** update dependency webrtc-adapter to v8.2.2 ([62402fc](62402fc))
* **deps:** update dependency webrtc-adapter to v8.2.3 ([963455e](963455e))
* **MediaConnection:** `close` event is fired on remote Peer ([0836356](0836356)), closes [#636](#636) [#1089](#1089) [#1032](#1032) [#832](#832) [#780](#780) [#653](#653)

### Features

* **DataConnection:** handle close messages and flush option ([6ca38d3](6ca38d3)), closes [#982](#982)
* **MediaChannel:** Add experimental `willCloseOnRemote` event to MediaConnection. ([ed84829](ed84829))
* MsgPack/Cbor serialization ([fcffbf2](fcffbf2))
@github-actions
Copy link

🎉 This issue has been resolved in version 1.5.0-rc.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue Sep 3, 2023
# [1.5.0](v1.4.7...v1.5.0) (2023-09-03)

### Bug Fixes

* **datachannel:** sending order is now preserved correctly ([#1038](#1038)) ([0fb6179](0fb6179)), closes [#746](#746)
* **deps:** update dependency @swc/helpers to ^0.4.0 ([a7de8b7](a7de8b7))
* **deps:** update dependency cbor-x to v1.5.4 ([c1f04ec](c1f04ec))
* **deps:** update dependency eventemitter3 to v5 ([caf01c6](caf01c6))
* **deps:** update dependency peerjs-js-binarypack to v1.0.2 ([7452e75](7452e75))
* **deps:** update dependency webrtc-adapter to v8 ([431f00b](431f00b))
* **deps:** update dependency webrtc-adapter to v8.2.2 ([62402fc](62402fc))
* **deps:** update dependency webrtc-adapter to v8.2.3 ([963455e](963455e))
* **MediaConnection:** `close` event is fired on remote Peer ([0836356](0836356)), closes [#636](#636) [#1089](#1089) [#1032](#1032) [#832](#832) [#780](#780) [#653](#653)
* **npm audit:** Updates all dependencies that cause npm audit to issue a warning ([6ef5707](6ef5707))

### Features

* `.type` property on `Error`s emitted from connections ([#1126](#1126)) ([debe7a6](debe7a6))
* `PeerError` from connections ([ad3a0cb](ad3a0cb))
* **DataConnection:** handle close messages and flush option ([6ca38d3](6ca38d3)), closes [#982](#982)
* **MediaChannel:** Add experimental `willCloseOnRemote` event to MediaConnection. ([ed84829](ed84829))
* MsgPack/Cbor serialization ([fcffbf2](fcffbf2))
* MsgPack/Cbor serialization ([#1120](#1120)) ([4367256](4367256)), closes [#611](#611)
github-actions bot pushed a commit that referenced this issue Dec 3, 2023
## [1.5.2-rc.1](v1.5.1...v1.5.2-rc.1) (2023-12-03)

### Bug Fixes

* `close` event was not triggered reliably ([#860](#860)) ([ec1d5ae](ec1d5ae)), closes [#636](#636)
* **datachannel:** sending order is now preserved correctly ([18d491a](18d491a)), closes [#746](#746)
* support Blobs nested in objects ([7956dd6](7956dd6)), closes [#1163](#1163)
@peers peers deleted a comment from github-actions bot Dec 3, 2023
github-actions bot pushed a commit that referenced this issue Apr 27, 2024
## [1.5.3-rc.1](v1.5.2...v1.5.3-rc.1) (2024-04-27)

### Bug Fixes

* `close` event was not triggered reliably ([#860](#860)) ([ec1d5ae](ec1d5ae)), closes [#636](#636)
* **datachannel:** sending order is now preserved correctly ([18d491a](18d491a)), closes [#746](#746)
* navigator is not defined ([305a180](305a180))
* navigator is not defined. ([6f85dd3](6f85dd3))
* remove need for `unsafe-eval` ([f1857fe](f1857fe))
@peers peers deleted a comment from github-actions bot Apr 27, 2024
@peers peers locked as resolved and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants