Collaborative Editing using WebRTC ( Only 2 peers support )#1877
Collaborative Editing using WebRTC ( Only 2 peers support )#1877abhishekgahlot wants to merge 3 commits intoWordPress:masterfrom abhishekgahlot:master
Conversation
|
Nice! Let's tweak the boundaries of a locked block so they look and behave like other blocks. Like this: Let's make sure all floats and alignments work, with the tweaked markup. @youknowriad not urgent but if at some point you have time can you look at this PR? Thanks! |
blocks/editable/index.js
Outdated
There was a problem hiding this comment.
@youknowriad No it's being worked at, I added this because redux states had react elements which I was not able to serialize. This works fine and output string but we are working on this for proper structure.
editor/modes/visual-editor/block.js
Outdated
There was a problem hiding this comment.
Is it possible to avoid creating a new div here, and reuse the inner div?
editor/selectors.js
Outdated
There was a problem hiding this comment.
It's a bit weird to use global variables in a selector? What's the purpose of the window.grtcProps ? Can't we move this to the store maybe?
editor/state.js
Outdated
There was a problem hiding this comment.
Why do we need redux thunk? We're using an alternative in Gutenberg https://github.com/aduth/refx
There was a problem hiding this comment.
Also, where are we using thunks in this code?
|
This PR is not easy to review since I'm lacking a lot of information and knowledge using P2P collaboration. Some questions:
|
|
@youknowriad Thanks for the comments, I will check and fix them. Gutenberg RTC is not a generic library but wrapper written over simple-peer library. I didn't add that to Gutenberg because it does one thing which is maintain P2P data channel (encrypted) with the help of serverside key value store. |
|
@abhishekgahlot What about moving the library to a root folder in the gutenberg repository? we have several separate modules already, element, utils, components, date... |
|
@youknowriad Sure will do that too. Thanks for notifying. |
editor/state.js
Outdated
There was a problem hiding this comment.
This can be merged into a single applyMiddleware: applyMiddleware( refx( effects ), grtcMiddleware )
editor/state.js
Outdated
There was a problem hiding this comment.
Also, where are we using thunks in this code?
editor/selectors.js
Outdated
There was a problem hiding this comment.
Directly mutating the state, Fix this
There was a problem hiding this comment.
Note with #2172, these need to be updated to prefix the dependencies with @wordpress/. You will need to perform a rebase against the latest version of master and apply your changes:
git fetch origin
git rebase origin/master
|
@gziolo These are the few things that have been bottleneck till now.
|
editor/reducer.js
Outdated
There was a problem hiding this comment.
We should display global notice instead.
There was a problem hiding this comment.
Updated, but it still needs some work. Moved to todo list.
editor/modes/visual-editor/block.js
Outdated
There was a problem hiding this comment.
@gziolo @abhishekgahlot wonder if the changes to the visual-block component could be abstracted in a HoC withCollabEditing to try to clean this file cleaner.
There was a problem hiding this comment.
That would be nice, I will explore this idea. Moved to todo list :)
There was a problem hiding this comment.
This class should be more semantic: is-being-edited perhaps.
There was a problem hiding this comment.
These classes should be is-red etc
There was a problem hiding this comment.
Why do we need to support a null class?
editor/reducer.js
Outdated
editor/reducer.js
Outdated
There was a problem hiding this comment.
This doesn't seem a good place for this.
There was a problem hiding this comment.
Both constants were never used. I removed them.
editor/reducer.js
Outdated
There was a problem hiding this comment.
@jasmussen had a nicer idea for placing this in an ellipsis menu. (It's ok for an initial pass, though.)
There was a problem hiding this comment.
Maybe "enableCollaboration" or "toggleCollaborationMode"?
There was a problem hiding this comment.
I would like to unify language we use for this feature. If we would go for collaborative editing then I would go for toggleCollaborativeEditing.
grtc/DESIGN.md
Outdated
There was a problem hiding this comment.
Can we call this "architecture" to avoid clashes with design docs on searches, etc?
There was a problem hiding this comment.
Updated. Should we keep grtc in its own package?
There was a problem hiding this comment.
It's much smaller after encryption got removed. If we would keep it, where should we put it in the repository? Can it remain in the top level or rather should be moved to editor top level folder?
grtc/DESIGN.md
Outdated
There was a problem hiding this comment.
Also @gziolo maybe some of these notes can be added as comments in the code, which is always better.
There was a problem hiding this comment.
I updated the docs, they may require further iterations. Let's wait until we stabilize API.
lib/collaboration.php
Outdated
There was a problem hiding this comment.
These functions need the version since info.
lib/collaboration.php
Outdated
There was a problem hiding this comment.
Why are the extra sanity checks needed over the strict flag in base64_decode()?
grtc/crypto.js
Outdated
There was a problem hiding this comment.
Crypto packages tend to be extremely large for browser consumption. This one is approximately 266kb minified and gzipped. I'd sought similar in Automattic/wp-calypso#17356, though I'm unsure of a good alternative for RSA key generation as you need here. Do you know of other options we could evaluate? I think the size as-is is quite excessive.
There was a problem hiding this comment.
We can remove the support of encryption and trust the turn servers in the relay. It can be removed completely.
grtc/app.js
Outdated
There was a problem hiding this comment.
We shouldn't need 'use strict'; with Babel (it is added automatically)
There was a problem hiding this comment.
Would it be possible to split this file up, perhaps into one-file-per-class?
There was a problem hiding this comment.
use strict removed and classes moved to their own files.
grtc/app.js
Outdated
There was a problem hiding this comment.
jQuery is not defined as a dependency for this script (i.e. incidental that another plugin depends on jQuery, but cannot rely on this). In any case, we might want to consider if we can do without it (maybe fetch, which is already promise based?)
There was a problem hiding this comment.
My initial iteration uses window.fetch. We can update later id we decide on some different approach.
grtc/app.js
Outdated
There was a problem hiding this comment.
This and the following line could be made more readable by splitting into separate lines.
grtc/app.js
Outdated
There was a problem hiding this comment.
Arrow functions preserve this reference, you don't need to create a separate variable for tracking this.
There was a problem hiding this comment.
Yes, removed all self occurrences.
grtc/app.js
Outdated
There was a problem hiding this comment.
With arrow functions, I think this pattern of assigning a self variable should be largely avoidable and arguably discouraged.
|
@aduth @mtias I addressed almost all your comments. Those remaining are now on the todo list. I did quite a heavy refactoring, but there are a few things that can be further improved. In particular I would like to change the way we shaped Redux state. If I understood properly it can't properly handle more than 2 peers at the moment. Middleware is still a bit hard to read, so I plan to tackle this one, too. @abhishekgahlot what did you mean by "Optimization for XHR Polling". Can you elaborate on this one? |
|
@gziolo Right now the number of requests that goes to the server in order to check for new peers is done every 5 seconds this can become huge very soon. Maybe something can be done to optimize stop polling when both peers connect? |
Codecov Report
@@ Coverage Diff @@
## master #1877 +/- ##
=========================================
+ Coverage 31.64% 33% +1.35%
=========================================
Files 235 208 -27
Lines 6658 6039 -619
Branches 1196 1074 -122
=========================================
- Hits 2107 1993 -114
+ Misses 3824 3409 -415
+ Partials 727 637 -90
Continue to review full report at Codecov.
|
|
Closing in favor of #3741. |

Work continues in #3741!!!
Please note this is incomplete and is currently being updated.
Detailed Description:
We create a grtc constructor inside middleware.
Middleware is used to listen to all the actions being dispatched so that we can send those to P2P data channel. Few states are filtered in middleware that we don't send.
For peer colors, we use a different action which is always dispatched when you select a block shown on the basis of peerID which is unique to each peer.
Locking also happens on the basis of borders. If border for collaboration is visible on one peer side it is locked.
The module used is: https://github.com/abhishekgahlot/gutenberg-rtc
How GRTC works: https://github.com/abhishekgahlot/gutenberg-rtc/blob/master/DESIGN.md
TODO tasks
@sincein PHP file ( Collaborative Editing using WebRTC ( Only 2 peers support ) #1877 (comment)).withCoeditingHOC to wrap the visual-block component (Collaborative Editing using WebRTC ( Only 2 peers support ) #1877 (comment)).Blockers
Improvements