Repository navigation
Allow arbitrary awareness fields in Collaboration plugin - #4507
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ivailop7
left a comment
There was a problem hiding this comment.
Thank you, Attila. @acywatson and @zurfyx . Could you give it a look as well.
|
I don't think this works since map is not json serializeable, should be plain object like remaining of awareness data. Personal opinion: naming looks a bit odd, as usage will be awareness.getLocalState().awarenessFields, maybe data or extraData would do better, no strong opinion tho. Also can add a unit test (see Collaboration.test), as collab is quite sensitive for changes, so it's better to get it covered |
@fantactuka Thanks for the review! I have changed the type from Map to object and added unit test. |
| expect(client1.awareness.getLocalState().awarenessFields).toEqual( | ||
| awarenessFields1, | ||
| ); |
There was a problem hiding this comment.
Could you use awareness.getStates() instead, to ensure that client1 has proper awareness from client2 and vise versa?
There was a problem hiding this comment.
It looks like here the mock for getStates() only inserts the current client's awareness state. That's why I opted for the getLocalState(). However, I have manually tested and between two collaborating users the awareness is sync correctly.
| name: string, | ||
| color: string, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| awarenessFields?: object, |
There was a problem hiding this comment.
I wonder if we can use { ... } here and remove eslint comment above
There was a problem hiding this comment.
Actually, we don't need the eslint comments anymore - any is not used anymore. Removed all of them.
|
Thanks for updates! @acywatson @zurfyx thoughts on naming? |
I like having awareness in the name, but fields is probably wrong. "awarenessData" or "extraAwaresnessData" seems fine. doc block on the interface would help people know what it's for. |
Renamed the parameter to |
| awareness: { | ||
| getLocalState(): void; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| getLocalState(): any; |
There was a problem hiding this comment.
Can we make this better? Besides the object prop what other types we don't know?
There was a problem hiding this comment.
I have added types for getLocalState(), getStates(), setLocalState(), etc.
Thanks for checking!
| ): void { | ||
| provider.awareness.setLocalState({ | ||
| anchorPos: null, | ||
| awarenessData: awarenessData, |
There was a problem hiding this comment.
| awarenessData: awarenessData, | |
| awarenessData, |
Similar one below
Co-authored-by: Attila Novak <[email protected]>
Summary
This change allows arbitrary data (for example 3rd party UUID) to be added to awareness. Right now user name and color is hard coded in Collaboration plugin. The new parameter
awarenessDatais optional.Usage example
We can specify our arbitrary data like this:
With the new parameter, we can send down our arbitrary data: