fix jump to other page not disconnect websocket

This commit is contained in:
hjlarry 2025-10-10 16:51:57 +08:00
parent 832dabc8a4
commit 6c039be2ca
1 changed files with 14 additions and 2 deletions

View File

@ -19,13 +19,24 @@ export function useCollaboration(appId: string, reactFlowStore?: any) {
if (!appId) return
let connectionId: string | null = null
let isUnmounted = false
if (!cursorServiceRef.current)
cursorServiceRef.current = new CursorService()
const initCollaboration = async () => {
connectionId = await collaborationManager.connect(appId, reactFlowStore)
setState((prev: any) => ({ ...prev, appId, isConnected: collaborationManager.isConnected() }))
try {
const id = await collaborationManager.connect(appId, reactFlowStore)
if (isUnmounted) {
collaborationManager.disconnect(id)
return
}
connectionId = id
setState((prev: any) => ({ ...prev, appId, isConnected: collaborationManager.isConnected() }))
}
catch (error) {
console.error('Failed to initialize collaboration:', error)
}
}
initCollaboration()
@ -54,6 +65,7 @@ export function useCollaboration(appId: string, reactFlowStore?: any) {
})
return () => {
isUnmounted = true
unsubscribeStateChange()
unsubscribeCursors()
unsubscribeUsers()