mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
feat: sync with keck
This commit is contained in:
@@ -17,7 +17,7 @@ function getCollaborationPoint() {
|
||||
const { protocol, host } = getLocation();
|
||||
const ws = protocol.startsWith('https') ? 'wss' : 'ws';
|
||||
const isOnline = host.endsWith('affine.pro');
|
||||
const site = isOnline ? host : 'localhost:4200';
|
||||
const site = isOnline ? host : 'localhost:3000';
|
||||
return `${ws}://${site}/collaboration/`;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,13 +120,13 @@ async function _initYjsDatabase(
|
||||
[name]: p,
|
||||
};
|
||||
}),
|
||||
p({
|
||||
awareness,
|
||||
doc: binaries,
|
||||
token,
|
||||
workspace: `${workspace}_binaries`,
|
||||
emitState,
|
||||
}).then(p => ({ [`${name}_binaries`]: p })),
|
||||
// p({
|
||||
// awareness,
|
||||
// doc: binaries,
|
||||
// token,
|
||||
// workspace: `${workspace}_binaries`,
|
||||
// emitState,
|
||||
// }).then(p => ({ [`${name}_binaries`]: p })),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,39 @@ export const getYjsProviders = (
|
||||
}
|
||||
) as any; // TODO: type is erased after cascading references
|
||||
|
||||
// Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
// TODO: synced will also be triggered on reconnection after losing sync
|
||||
// There needs to be an event mechanism to emit the synchronization state to the upper layer
|
||||
ws.once('synced', () => resolve());
|
||||
ws.once('lost-connection', () => resolve());
|
||||
ws.once('connection-error', () => reject());
|
||||
ws.on('synced', () => instances.emitState('connected'));
|
||||
ws.on('lost-connection', () =>
|
||||
instances.emitState('retry')
|
||||
);
|
||||
ws.on('connection-error', () =>
|
||||
instances.emitState('retry')
|
||||
);
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
keck: async (instances: YjsDefaultInstances) => {
|
||||
if (options.enabled.includes('ws')) {
|
||||
if (instances.token) {
|
||||
const ws = new WebsocketProvider(
|
||||
instances.token,
|
||||
options.backend,
|
||||
instances.workspace,
|
||||
instances.doc,
|
||||
{
|
||||
params: options.params,
|
||||
}
|
||||
) as any; // TODO: type is erased after cascading references
|
||||
|
||||
// Wait for ws synchronization to complete, otherwise the data will be modified in reverse, which can be optimized later
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
// TODO: synced will also be triggered on reconnection after losing sync
|
||||
|
||||
Reference in New Issue
Block a user