developing #10
|
|
@ -605,6 +605,8 @@ function FlowchartEditorInner({ projectId, projectName, userId, userDisplayName,
|
|||
...prev,
|
||||
{ id: nanoid(), displayName: user.displayName, type: 'join', color: getUserColor(user.userId) },
|
||||
])
|
||||
// Send full CRDT state so the joining client gets caught up
|
||||
crdtManager.broadcastFullState()
|
||||
},
|
||||
onPresenceLeave: (user) => {
|
||||
setCollaborationNotifications((prev) => [
|
||||
|
|
|
|||
|
|
@ -63,6 +63,19 @@ export class CRDTManager {
|
|||
/** Connect to a Supabase Realtime channel for outbound broadcasts */
|
||||
connectChannel(channel: RealtimeChannel): void {
|
||||
this.channel = channel
|
||||
// Broadcast full state so other clients merge any updates they missed
|
||||
this.broadcastFullState()
|
||||
}
|
||||
|
||||
/** Broadcast the full Yjs document state to sync all connected clients */
|
||||
broadcastFullState(): void {
|
||||
if (!this.channel || this.isDestroyed) return
|
||||
const state = Y.encodeStateAsUpdate(this.doc)
|
||||
this.channel.send({
|
||||
type: 'broadcast',
|
||||
event: BROADCAST_EVENT,
|
||||
payload: { update: Array.from(state) },
|
||||
})
|
||||
}
|
||||
|
||||
/** Apply a remote CRDT update received via broadcast */
|
||||
|
|
|
|||
Loading…
Reference in New Issue