fix: websocket should be link to blocksuiteWorkspace, not workspace id (#735)
This commit is contained in:
@@ -37,7 +37,7 @@ const {
|
|||||||
export class AffineProvider extends BaseProvider {
|
export class AffineProvider extends BaseProvider {
|
||||||
public id = 'affine';
|
public id = 'affine';
|
||||||
private _onTokenRefresh?: Callback = undefined;
|
private _onTokenRefresh?: Callback = undefined;
|
||||||
private _wsMap: Map<string, WebsocketProvider> = new Map();
|
private _wsMap: Map<BlocksuiteWorkspace, WebsocketProvider> = new Map();
|
||||||
private _apis: Apis;
|
private _apis: Apis;
|
||||||
private _channel?: WebsocketClient;
|
private _channel?: WebsocketClient;
|
||||||
// private _idbMap: Map<string, IndexedDBProvider> = new Map();
|
// private _idbMap: Map<string, IndexedDBProvider> = new Map();
|
||||||
@@ -147,7 +147,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
const { doc, room } = workspace;
|
const { doc, room } = workspace;
|
||||||
assert(room);
|
assert(room);
|
||||||
assert(doc);
|
assert(doc);
|
||||||
let ws = this._wsMap.get(room);
|
let ws = this._wsMap.get(workspace);
|
||||||
if (!ws) {
|
if (!ws) {
|
||||||
const wsUrl = `${
|
const wsUrl = `${
|
||||||
window.location.protocol === 'https:' ? 'wss' : 'ws'
|
window.location.protocol === 'https:' ? 'wss' : 'ws'
|
||||||
@@ -155,7 +155,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
ws = new WebsocketProvider(wsUrl, room, doc, {
|
ws = new WebsocketProvider(wsUrl, room, doc, {
|
||||||
params: { token: this._apis.token.refresh },
|
params: { token: this._apis.token.refresh },
|
||||||
});
|
});
|
||||||
this._wsMap.set(room, ws);
|
this._wsMap.set(workspace, ws);
|
||||||
}
|
}
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
@@ -182,8 +182,8 @@ export class AffineProvider extends BaseProvider {
|
|||||||
this.linkLocal(workspace);
|
this.linkLocal(workspace);
|
||||||
const ws = this._getWebsocketProvider(workspace);
|
const ws = this._getWebsocketProvider(workspace);
|
||||||
// close all websocket links
|
// close all websocket links
|
||||||
Array.from(this._wsMap.entries()).forEach(([id, ws]) => {
|
Array.from(this._wsMap.entries()).forEach(([blocksuiteWorkspace, ws]) => {
|
||||||
if (id !== room) {
|
if (blocksuiteWorkspace !== workspace) {
|
||||||
ws.disconnect();
|
ws.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -279,7 +279,13 @@ export class AffineProvider extends BaseProvider {
|
|||||||
public override async closeWorkspace(id: string) {
|
public override async closeWorkspace(id: string) {
|
||||||
// const idb = this._idbMap.get(id);
|
// const idb = this._idbMap.get(id);
|
||||||
// idb?.destroy();
|
// idb?.destroy();
|
||||||
const ws = this._wsMap.get(id);
|
const workspaceUnit = this._workspaces.get(id);
|
||||||
|
const ws = workspaceUnit?.blocksuiteWorkspace
|
||||||
|
? this._wsMap.get(workspaceUnit?.blocksuiteWorkspace)
|
||||||
|
: null;
|
||||||
|
if (!ws) {
|
||||||
|
console.error('close workspace websocket which not exist.');
|
||||||
|
}
|
||||||
ws?.disconnect();
|
ws?.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user