-
-
Notifications
You must be signed in to change notification settings - Fork 981
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
DataChannel multiplexing #334
Conversation
@nazar-pc As per our previous discussion about reducing bundle size, the DataChannel module can be changed to any lightweight module that has a similar constructor and exposes the 'open' event. Everything else it implements (streaming API or otherwise) will be inherited by the peer object. So a light version of the DataChannel will also make the Peer object light. |
On the surface looks good, API is simple to use, will look into details later. Are there upstream bug reports about Concerning size reduction, I think it would be a good idea to decouple basic functionality from |
I'm still working on reproducing the upstream bugs with onclose simply. The onopen problem is probably an implementation flaw on my side. Definitely still some work to be done here. I'll attempt to make a DataChannelLight implementation once these issues are worked out and we can explore further decoupling if that turns out to be difficult. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't run the code yet, will try to find time soon. Eager to implement signaling for re-negotiation on top of this using separate named data channel instead of forcing user to handle signal
event even when there is a working connection already.
PRs 1-5 in https://github.com/RationalCoding/simple-peer/pulls should hopefully solve points 1-3 and some of my review comments. There is also a test case for pre-negotiated default data channel. I think after merging those together it should work more reliable, though I have no access to Safari to check behavior there. We should probably mark Electron WebRTC support as deprecated now and note that it will not support multiple data channels, but should continue working otherwise until next major release. |
Moved `channelReady` back to `Peer` as it is only used there
Removed `self.peer.connected` usage and switched to `self._channel.readyState`
Fix tests for channel name reuse by waiting for data channel to be closed
Restored compatibility with older versions of simple-peer and alternative implementations
Support pre-negotiated default channel
Looks good to me now. How can I reproduce the first issue if it is still present? |
There are already tests in this PR for those issues that were disabled for Chrome and Safari. I've turned them back on, so just running the browser tests in Chrome should be enough to reproduce. Specifically: 'closing channels from creator side' and 'reusing channelNames of closed channels' |
So everything works fine in Chromium Nightly from about a week ago (a bit slow on some tests) and works perfectly smooth on latest Chromium Nightly. Shouldn't be a blocker if it is already fixed upstream. "reusing channelNames of closed channels" will stuck in Firefox Nightly and stable, but works perfectly in both once Dev Tools are open 😕. Not sure how to debug this behavior. Dev Tools typically slows down Firefox quite a bit so probably some kind of race too. Will try to play with various timeouts. |
…otherwise the other side might not yet get `close` event and data channel creation will be ignored
Fixed close behavior by listening for `close` event on correct side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now, awesome work!
So this has a few more unsolved browser-related issues. I've enforced unique channel names, which solved some issues, but there are more.
Going to need to reproduce with native WebRTC and open bugs. Synchronous creation works fine though. |
…relevant multiplex tests
I've added the All remaining issues are reported browser bugs. |
# Conflicts: # simplepeer.min.js
Hi everyone!! this is an awesome feature 👍 . Do you know when is going to be merged? |
Can't be merged until the browser bugs breaking some of the functionality are fixed. You're welcome to try it out if you don't mind a bit of instability. |
# Conflicts: # index.js # simplepeer.min.js
# Conflicts: # README.md # index.js # simplepeer.min.js
I've completed cross-browser testing for this. The only bug that's left is Firefox's inability to create new channels after any are destroyed. We could support only creating DataChannels for now (no calling |
I agree with @t-mullen here. This change moves simple-peer forward in supporting complex applications while maintaining the original public API. Would it be possible to add an |
I agree with @samuelmaddock @t-mullen @nazar-pc this is a much-needed feature and should be added with a harmony flag so others can test it, is it possible to do that now? Also @t-mullen, do these browser bugs persist in Node as well? If not, the more reason to land this now. |
Hello, I took a couple of hours this morning to read your code, fork the current master branch (which is now written in ES6) and compared them. Then I adapted a little bit of code, rewrote everything in ES6 and updated the documentation. It was not really easy comparing the files manually since they didn't share a common base / were written in different ES versions so I hope I didn't forget anything. I only did some basic testing like creating another data channel, checking its label and real channel name, sending / receiving data and destroying the data channel but so far it worked. If you want to have a look you can see the code here : https://github.com/Khivar/simple-peer/tree/multi-datachannels |
I'm getting an infinite loop when I call
|
Thanks for the feedback and sorry for the late reply. It should be fixed, I also updated the code to use the JavaScript Standard Style and synced with the upstream master branch. |
@t-mullen What are your thoughts on including this work behind an experimental flag until all browsers support it without major bugs? |
My concern is with interop between browsers. I'd want to run extensive testing again (you can see how many bugs came up the first time). I'd like to see interop unit tests similar to the ones in #575. I'll start work, seeing as this feature is almost 2 years overdue. I don't understand the idea of experimental flags in an open-source project. The version of simple-peer with these features is available in this PR or in @Khivar's fork - anyone is free to use them at their own risk and they aren't officially supported. |
Closed in favour of #694 |
Here's my implementation of DataChannel multiplexing. Opening channels and sending data works well, while preserving all of the old API.
It allows you to use the same
Peer
duplex stream as before by having the peers inherit theDataChannel
object. But it also allows you to do multiplexing easily like this:Open Problems:
onclose
behaviour in Chromium. Chrome intermittently doesn't fire the event when the datachannel creator closes it but instead gets stuck on "closing".InvalidStateError
when you attempt to do this.onopen
event, so any help here would be appreciated.Electron WebRTC has no support for multiple datachannels and needs to be fixed before this can be merged. Error when creating second DataChannel. mappum/electron-webrtc#127(electron-webrtc support has been dropped).Seeing as this is another significant change, I'd appreciate feedback on the code and API from the community.