[WIP] refactoring of y-webrtc in typescript #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For a different project, I had to make some modifications to y-webrtc. To understand the code and to be able to make some modifications, I decided to implement a refactoring and convert the existing code to Typescript.
There might not be any desire to migrate y-webrtc to TypeScript, so I understand if there is no appetite for this PR to be merged. Still opening this issue as it might be useful for other community members to understand the internals of y-webrtc, but feel free to close it.
This PR is a conversion to typescript + a refactoring of y-webrtc. The following concepts have been refactored:
BaseWebrtcProvider.ts
provider which handles setting up these connection. Then, the only yjs specific code is implemented inWebrtcProvider.ts
. Messages passed over the channels specific to connections / peers are handled in 'Room.ts'. Application / yjs specific messages are then wrapped in acustomMessage
and handled inWebrtcProvider.ts:onCustomMessage
:onPeerConnected
andonCustomMessage
callback that are implemented inWebrtcProvider.ts
to send messages in response to initiating a new connection, and in response to custom messages from peers. This means yjs specific logic for broadcast channel vs webrtc peers are now using the same code. The original code had custom behaviour for initiating broadcastchannels (writing messageQueryAwareness, and immediately writing syncstep2). This has now been removed. I don't think this has any impact, but this should be verifiedTODOs:
[ ] "synced" event has not been implemented yet
[ ] I'm not an expert of rollup, so have now moved to microbundle. Maybe sticking to rollup is better
[ ] related to the previous point; the demo and test have not been converted