fix: retrieve awareness states after reconnect

This commit is contained in:
Hans Pagel 2020-12-02 15:35:33 +01:00
parent e46c4a85ff
commit 12d994275c

View File

@ -49,8 +49,8 @@ const CollaborationCursor = Extension.create({
*/
user: (attributes: { [key: string]: any }): Command => () => {
this.options.user = attributes
this.options.provider.awareness.setLocalStateField('user', this.options.user)
this.options.onUpdate(awarenessStatesToArray(this.options.provider.awareness.states))
return true
},
@ -66,6 +66,19 @@ const CollaborationCursor = Extension.create({
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))
return this.options.provider.awareness