mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-03 04:22:04 +03:00
fix(workspace): leave workspace correctly (#5379)
This commit is contained in:
parent
1ce4dd0497
commit
77d239ff81
@ -92,7 +92,7 @@ export class SyncEngine {
|
||||
}
|
||||
|
||||
canGracefulStop() {
|
||||
return !!this.status.local && this.status.local.pendingPushUpdates > 0;
|
||||
return !!this.status.local && this.status.local.pendingPushUpdates === 0;
|
||||
}
|
||||
|
||||
async waitForGracefulStop(abort?: AbortSignal) {
|
||||
|
@ -76,6 +76,11 @@ export function createCloudAwarenessProvider(
|
||||
removeAwarenessStates(awareness, [awareness.clientID], 'window unload');
|
||||
};
|
||||
|
||||
function handleConnect() {
|
||||
socket.emit('client-handshake-awareness', workspaceId);
|
||||
socket.emit('awareness-init', workspaceId);
|
||||
}
|
||||
|
||||
return {
|
||||
connect: () => {
|
||||
socket.on('server-awareness-broadcast', awarenessBroadcast);
|
||||
@ -86,16 +91,19 @@ export function createCloudAwarenessProvider(
|
||||
|
||||
socket.connect();
|
||||
|
||||
socket.on('connect', handleConnect);
|
||||
|
||||
socket.emit('client-handshake-awareness', workspaceId);
|
||||
socket.emit('awareness-init', workspaceId);
|
||||
},
|
||||
disconnect: () => {
|
||||
removeAwarenessStates(awareness, [awareness.clientID], 'disconnect');
|
||||
awareness.off('update', awarenessUpdate);
|
||||
socket.emit('client-leave-awareness', workspaceId);
|
||||
socket.off('server-awareness-broadcast', awarenessBroadcast);
|
||||
socket.off('new-client-awareness-init', newClientAwarenessInitHandler);
|
||||
socket.off('connect', handleConnect);
|
||||
window.removeEventListener('unload', windowBeforeUnloadHandler);
|
||||
socket.disconnect();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -51,8 +51,7 @@ export function createAffineStorage(
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: handle error
|
||||
socket.on('connect', () => {
|
||||
function handleConnect() {
|
||||
socket.emit(
|
||||
'client-handshake-sync',
|
||||
workspaceId,
|
||||
@ -62,10 +61,22 @@ export function createAffineStorage(
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('connect', handleConnect);
|
||||
|
||||
socket.connect();
|
||||
|
||||
socket.emit(
|
||||
'client-handshake-sync',
|
||||
workspaceId,
|
||||
(response: { error?: any }) => {
|
||||
if (!response.error) {
|
||||
syncSender.start();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
name: 'affine-cloud',
|
||||
async pull(docId, state) {
|
||||
@ -124,14 +135,6 @@ export function createAffineStorage(
|
||||
await syncSender.send(docId, update);
|
||||
},
|
||||
async subscribe(cb, disconnect) {
|
||||
const response: { error?: any } = await socket
|
||||
.timeout(10000)
|
||||
.emitWithAck('client-handshake-sync', workspaceId);
|
||||
|
||||
if (response.error) {
|
||||
throw new Error('client-handshake error, ' + response.error);
|
||||
}
|
||||
|
||||
const handleUpdate = async (message: {
|
||||
workspaceId: string;
|
||||
guid: string;
|
||||
@ -157,7 +160,7 @@ export function createAffineStorage(
|
||||
disconnect() {
|
||||
syncSender.stop();
|
||||
socket.emit('client-leave-sync', workspaceId);
|
||||
socket.disconnect();
|
||||
socket.off('connect', handleConnect);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user