feat: add ws link

This commit is contained in:
MingLiang Wang
2023-01-10 11:18:04 +08:00
parent 4b39acbba2
commit 9b875d19d2
2 changed files with 16 additions and 2 deletions
+1
View File
@@ -128,6 +128,7 @@ export class DataCenter {
const provider = this.providerMap.get(providerId);
assert(provider, `provide '${providerId}' is not registered`);
await provider.auth();
provider.loadWorkspaces();
}
/**
@@ -76,7 +76,12 @@ export class AffineProvider extends BaseProvider {
}
let ws = this._wsMap.get(room);
if (!ws) {
ws = new WebsocketProvider('/', room, doc);
const wsUrl = `${
window.location.protocol === 'https:' ? 'wss' : 'ws'
}://${window.location.host}/api/sync/`;
ws = new WebsocketProvider(wsUrl, room, doc, {
params: { token: this._apis.token.refresh },
});
this._wsMap.set(room, ws);
}
// close all websocket links
@@ -262,7 +267,15 @@ export class AffineProvider extends BaseProvider {
const nw = new BlocksuiteWorkspace({
room: id,
}).register(BlockSchema);
nw.meta.setName(meta.name);
const { doc } = nw;
const updates = await this._apis.downloadWorkspace(id);
if (updates && updates.byteLength) {
await new Promise(resolve => {
doc.once('update', resolve);
applyUpdate(doc, new Uint8Array(updates));
});
}
// nw.meta.setName(meta.name);
this.linkLocal(nw);
const workspaceInfo: WorkspaceInfo = {