mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 02:35:23 -04:00

By storing the ydoc state in the database we can reconnect lost clients easier and enable offline editing because we continue using the crdt data that has been used by the client before the connection loss. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
27 lines
760 B
TypeScript
27 lines
760 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import { MessageType } from '../message-transporters/message.js'
|
|
import { YDocSyncAdapter } from './y-doc-sync-adapter.js'
|
|
import { Listener } from 'eventemitter2'
|
|
|
|
export class YDocSyncClientAdapter extends YDocSyncAdapter {
|
|
protected bindDocumentSyncMessageEvents() {
|
|
const destroyCallback = super.bindDocumentSyncMessageEvents()
|
|
|
|
const noteContentUpdateListener = this.messageTransporter.on(
|
|
MessageType.NOTE_CONTENT_UPDATE,
|
|
() => {
|
|
this.markAsSynced()
|
|
},
|
|
{ objectify: true }
|
|
) as Listener
|
|
|
|
return () => {
|
|
destroyCallback()
|
|
noteContentUpdateListener.off()
|
|
}
|
|
}
|
|
}
|