fix: retrieve awareness states after reconnect
This commit is contained in:
@@ -49,8 +49,8 @@ const CollaborationCursor = Extension.create({
|
|||||||
*/
|
*/
|
||||||
user: (attributes: { [key: string]: any }): Command => () => {
|
user: (attributes: { [key: string]: any }): Command => () => {
|
||||||
this.options.user = attributes
|
this.options.user = attributes
|
||||||
|
|
||||||
this.options.provider.awareness.setLocalStateField('user', this.options.user)
|
this.options.provider.awareness.setLocalStateField('user', this.options.user)
|
||||||
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
@@ -66,6 +66,19 @@ const CollaborationCursor = Extension.create({
|
|||||||
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
|
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.options.provider.awareness.on('update', () => {
|
||||||
|
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
|
||||||
|
})
|
||||||
|
|
||||||
|
this.options.provider.on('status', (event: { status: string }) => {
|
||||||
|
if (event.status === 'connected') {
|
||||||
|
// FIX: Reset the awareness state
|
||||||
|
// PR: https://github.com/yjs/y-protocols/issues/7
|
||||||
|
this.options.provider.awareness.setLocalState({})
|
||||||
|
this.options.provider.awareness.setLocalStateField('user', this.options.user)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
|
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
|
||||||
|
|
||||||
return this.options.provider.awareness
|
return this.options.provider.awareness
|
||||||
|
|||||||
Reference in New Issue
Block a user