developing #10
|
|
@ -1143,6 +1143,9 @@ function FlowchartEditorInner({ projectId, projectName, userId, userDisplayName,
|
|||
// Update last saved data ref to mark as not dirty
|
||||
lastSavedDataRef.current = flowchartData
|
||||
|
||||
// Broadcast full CRDT state so other connected clients sync up
|
||||
crdtRef.current?.broadcastFullState()
|
||||
|
||||
setToast({ message: 'Project saved successfully', type: 'success' })
|
||||
} catch (error) {
|
||||
console.error('Failed to save project:', error)
|
||||
|
|
|
|||
|
|
@ -173,6 +173,17 @@ export class CRDTManager {
|
|||
this.callbacks.onEdgesChange(this.getEdges())
|
||||
}
|
||||
|
||||
/** Broadcast the full document state to sync all connected clients */
|
||||
broadcastFullState(): void {
|
||||
if (!this.channel || this.isDestroyed) return
|
||||
const fullState = Y.encodeStateAsUpdate(this.doc)
|
||||
this.channel.send({
|
||||
type: 'broadcast',
|
||||
event: BROADCAST_EVENT,
|
||||
payload: { update: Array.from(fullState) },
|
||||
})
|
||||
}
|
||||
|
||||
private broadcastUpdate(update: Uint8Array): void {
|
||||
if (!this.channel || this.isDestroyed) return
|
||||
this.channel.send({
|
||||
|
|
|
|||
Loading…
Reference in New Issue