|
@@ -51,7 +51,12 @@ export function useWorkflowLocks(
|
|
|
|
|
|
|
|
// This connection's own id, so a lock held by this editor is distinguishable
|
|
// This connection's own id, so a lock held by this editor is distinguishable
|
|
|
// from one held by the same person in a different tab.
|
|
// from one held by the same person in a different tab.
|
|
|
- const clientIdRef = useRef<string | null>(null)
|
|
|
|
|
|
|
+ //
|
|
|
|
|
+ // Read from the client rather than caught here: auth_success arrives once,
|
|
|
|
|
+ // and an editor opened by navigation rather than a page load has missed it.
|
|
|
|
|
+ // Missing it meant this editor could not recognise its own lock and refused
|
|
|
|
|
+ // to open a node it was itself holding, flashing the holder's name - your own.
|
|
|
|
|
+ const myClientId = () => wsClient.clientId
|
|
|
const lastMoveSentRef = useRef(0)
|
|
const lastMoveSentRef = useRef(0)
|
|
|
const heldRef = useRef<Set<string>>(new Set())
|
|
const heldRef = useRef<Set<string>>(new Set())
|
|
|
|
|
|
|
@@ -71,7 +76,7 @@ export function useWorkflowLocks(
|
|
|
const onMove = (data: any) => {
|
|
const onMove = (data: any) => {
|
|
|
// Your own movement is already on your own canvas; echoing it back would
|
|
// Your own movement is already on your own canvas; echoing it back would
|
|
|
// fight the drag in progress.
|
|
// fight the drag in progress.
|
|
|
- if (data?.clientId && data.clientId === clientIdRef.current) return
|
|
|
|
|
|
|
+ if (data?.clientId && data.clientId === myClientId()) return
|
|
|
const p = data?.position
|
|
const p = data?.position
|
|
|
if (!data?.nodeId || typeof p?.x !== 'number' || typeof p?.y !== 'number') return
|
|
if (!data?.nodeId || typeof p?.x !== 'number' || typeof p?.y !== 'number') return
|
|
|
setLivePositions((current) => ({ ...current, [data.nodeId]: { x: p.x, y: p.y } }))
|
|
setLivePositions((current) => ({ ...current, [data.nodeId]: { x: p.x, y: p.y } }))
|
|
@@ -79,7 +84,7 @@ export function useWorkflowLocks(
|
|
|
|
|
|
|
|
const onEdit = (data: any) => {
|
|
const onEdit = (data: any) => {
|
|
|
// Your own edit is already on your own canvas.
|
|
// Your own edit is already on your own canvas.
|
|
|
- if (data?.clientId && data.clientId === clientIdRef.current) return
|
|
|
|
|
|
|
+ if (data?.clientId && data.clientId === myClientId()) return
|
|
|
onRemoteEditRef.current?.(data)
|
|
onRemoteEditRef.current?.(data)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,15 +93,10 @@ export function useWorkflowLocks(
|
|
|
setDeniedNode({ nodeId: data.nodeId, heldBy: data.heldBy || 'somebody else' })
|
|
setDeniedNode({ nodeId: data.nodeId, heldBy: data.heldBy || 'somebody else' })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const onIdentity = (data: any) => {
|
|
|
|
|
- if (data?.clientId) clientIdRef.current = data.clientId
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
wsClient.on(lockChannel, onLocks)
|
|
wsClient.on(lockChannel, onLocks)
|
|
|
wsClient.on(moveChannel, onMove)
|
|
wsClient.on(moveChannel, onMove)
|
|
|
wsClient.on(editChannel, onEdit)
|
|
wsClient.on(editChannel, onEdit)
|
|
|
wsClient.on('lock_denied', onDenied)
|
|
wsClient.on('lock_denied', onDenied)
|
|
|
- wsClient.on('auth_success', onIdentity)
|
|
|
|
|
wsClient.subscribe([lockChannel, moveChannel, editChannel])
|
|
wsClient.subscribe([lockChannel, moveChannel, editChannel])
|
|
|
|
|
|
|
|
return () => {
|
|
return () => {
|
|
@@ -113,7 +113,6 @@ export function useWorkflowLocks(
|
|
|
wsClient.off(moveChannel, onMove)
|
|
wsClient.off(moveChannel, onMove)
|
|
|
wsClient.off(editChannel, onEdit)
|
|
wsClient.off(editChannel, onEdit)
|
|
|
wsClient.off('lock_denied', onDenied)
|
|
wsClient.off('lock_denied', onDenied)
|
|
|
- wsClient.off('auth_success', onIdentity)
|
|
|
|
|
setLocks({})
|
|
setLocks({})
|
|
|
setLivePositions({})
|
|
setLivePositions({})
|
|
|
setDeniedNode(null)
|
|
setDeniedNode(null)
|
|
@@ -156,7 +155,7 @@ export function useWorkflowLocks(
|
|
|
(nodeId: string): NodeLock | null => {
|
|
(nodeId: string): NodeLock | null => {
|
|
|
const held = locks[nodeId]
|
|
const held = locks[nodeId]
|
|
|
if (!held) return null
|
|
if (!held) return null
|
|
|
- return held.clientId === clientIdRef.current ? null : held
|
|
|
|
|
|
|
+ return held.clientId === myClientId() ? null : held
|
|
|
},
|
|
},
|
|
|
[locks]
|
|
[locks]
|
|
|
)
|
|
)
|