-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
…xported encoding and decoding methods, and add a binary encoding strategy.
…xported encoding and decoding methods, and add a binary encoding strategy.
Thank you, looks great! |
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.
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) { |
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.
These should be static
methods. Then there is no need to create an instance of *AwarenessStateEncoder
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.
Sure, can do.
* @return {Uint8Array} | ||
*/ | ||
export const encodeAwarenessUpdate = (awareness, clients, states = awareness.states) => { | ||
export const encodeAwarenessUpdate = (awareness, clients, states = awareness.states, stateEncoder = new DefaultAwarenessStateEncoder()) => { |
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.
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() |
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.
This test is the same as the third test and can be removed.
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.
I'll augment this test a bit, I'd like to add a test to ensure the default behaviour is using the default encoder.
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.