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

Allow a consumer to switch between JSON and binary encoding for awareness #27

Merged
merged 2 commits into from
Mar 31, 2023

Conversation

Myrannas
Copy link

This PR is intended to add support for binary awareness encoding as discussed in #26. I'd appreciate any feedback you have!

I have tested it out locally for my use case - and it appears to be working correctly in both modes.

…xported encoding and decoding methods, and add a binary encoding strategy.
…xported encoding and decoding methods, and add a binary encoding strategy.
@dmonad
Copy link
Member

dmonad commented Mar 31, 2023

Thank you, looks great!

@dmonad dmonad merged commit 960d4c2 into yjs:master Mar 31, 2023
Copy link
Member

@dmonad dmonad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I merged to quickly. I just reverted the changes. Could you please make the suggested changes before I make a release? You probably have to create a new PR.

* @param {encoding.Encoder} encoder
* @param {any} update
*/
encodeState (encoder, update) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be static methods. Then there is no need to create an instance of *AwarenessStateEncoder

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, can do.

* @return {Uint8Array}
*/
export const encodeAwarenessUpdate = (awareness, clients, states = awareness.states) => {
export const encodeAwarenessUpdate = (awareness, clients, states = awareness.states, stateEncoder = new DefaultAwarenessStateEncoder()) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be necessary to create a new instance of anything here. *AwarenessEncoder should only have static methods.

@@ -51,3 +52,7 @@ export const testAwareness = tc => {
t.compare(aw1.getStates().get(0), undefined)
t.compare(lastChangeLocal, lastChange)
}

export const testAwareness = testAwarenessWithEncoding()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is the same as the third test and can be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll augment this test a bit, I'd like to add a test to ensure the default behaviour is using the default encoder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants