fix duplicated status

This commit is contained in:
hjlarry 2026-01-13 15:59:59 +08:00
parent bd597497e7
commit 0c18d4e058
1 changed files with 4 additions and 25 deletions

View File

@ -956,7 +956,7 @@ export class CollaborationManager {
}
})
socket.on('status', (data: any) => {
socket.on('status', (data: { isLeader: boolean }) => {
try {
if (!data || typeof data.isLeader !== 'boolean') {
console.warn('Invalid status data:', data)
@ -966,6 +966,9 @@ export class CollaborationManager {
const wasLeader = this.isLeader
this.isLeader = data.isLeader
if (wasLeader !== this.isLeader)
console.log(`Collaboration: I am now the ${this.isLeader ? 'Leader' : 'Follower'}.`)
if (this.isLeader)
this.pendingInitialSync = false
else
@ -979,30 +982,6 @@ export class CollaborationManager {
}
})
socket.on('status', (data: { isLeader: boolean }) => {
if (this.isLeader !== data.isLeader) {
this.isLeader = data.isLeader
console.log(`Collaboration: I am now the ${this.isLeader ? 'Leader' : 'Follower'}.`)
this.eventEmitter.emit('leaderChange', this.isLeader)
}
if (this.isLeader)
this.pendingInitialSync = false
else
this.requestInitialSyncIfNeeded()
})
socket.on('status', (data: { isLeader: boolean }) => {
if (this.isLeader !== data.isLeader) {
this.isLeader = data.isLeader
console.log(`Collaboration: I am now the ${this.isLeader ? 'Leader' : 'Follower'}.`)
this.eventEmitter.emit('leaderChange', this.isLeader)
}
if (this.isLeader)
this.pendingInitialSync = false
else
this.requestInitialSyncIfNeeded()
})
socket.on('connect', () => {
console.log('WebSocket connected successfully')
this.eventEmitter.emit('stateChange', { isConnected: true })