mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-22 19:53:48 +08:00
feat(nbstore): allow polling protocol (#11160)
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
} from './socket';
|
} from './socket';
|
||||||
|
|
||||||
interface CloudAwarenessStorageOptions {
|
interface CloudAwarenessStorageOptions {
|
||||||
|
isSelfHosted: boolean;
|
||||||
serverBaseUrl: string;
|
serverBaseUrl: string;
|
||||||
type: SpaceType;
|
type: SpaceType;
|
||||||
id: string;
|
id: string;
|
||||||
@@ -22,7 +23,10 @@ export class CloudAwarenessStorage extends AwarenessStorageBase {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = new SocketConnection(this.options.serverBaseUrl);
|
connection = new SocketConnection(
|
||||||
|
this.options.serverBaseUrl,
|
||||||
|
this.options.isSelfHosted
|
||||||
|
);
|
||||||
|
|
||||||
private get socket() {
|
private get socket() {
|
||||||
return this.connection.inner.socket;
|
return this.connection.inner.socket;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
|
|
||||||
interface CloudDocStorageOptions extends DocStorageOptions {
|
interface CloudDocStorageOptions extends DocStorageOptions {
|
||||||
serverBaseUrl: string;
|
serverBaseUrl: string;
|
||||||
|
isSelfHosted: boolean;
|
||||||
type: SpaceType;
|
type: SpaceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +186,7 @@ class CloudDocStorageConnection extends SocketConnection {
|
|||||||
private readonly options: CloudDocStorageOptions,
|
private readonly options: CloudDocStorageOptions,
|
||||||
private readonly onServerUpdate: ServerEventsMap['space:broadcast-doc-update']
|
private readonly onServerUpdate: ServerEventsMap['space:broadcast-doc-update']
|
||||||
) {
|
) {
|
||||||
super(options.serverBaseUrl);
|
super(options.serverBaseUrl, options.isSelfHosted);
|
||||||
}
|
}
|
||||||
|
|
||||||
idConverter: IdConverter | null = null;
|
idConverter: IdConverter | null = null;
|
||||||
|
|||||||
@@ -165,10 +165,10 @@ class SocketManager {
|
|||||||
socket: Socket;
|
socket: Socket;
|
||||||
refCount = 0;
|
refCount = 0;
|
||||||
|
|
||||||
constructor(endpoint: string) {
|
constructor(endpoint: string, isSelfHosted: boolean) {
|
||||||
this.socketIOManager = new SocketIOManager(endpoint, {
|
this.socketIOManager = new SocketIOManager(endpoint, {
|
||||||
autoConnect: false,
|
autoConnect: false,
|
||||||
transports: ['websocket'],
|
transports: isSelfHosted ? ['websocket', 'polling'] : ['websocket'], // self-hosted server may not support websocket
|
||||||
secure: new URL(endpoint).protocol === 'https:',
|
secure: new URL(endpoint).protocol === 'https:',
|
||||||
// we will handle reconnection by ourselves
|
// we will handle reconnection by ourselves
|
||||||
reconnection: false,
|
reconnection: false,
|
||||||
@@ -205,10 +205,10 @@ class SocketManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SOCKET_MANAGER_CACHE = new Map<string, SocketManager>();
|
const SOCKET_MANAGER_CACHE = new Map<string, SocketManager>();
|
||||||
function getSocketManager(endpoint: string) {
|
function getSocketManager(endpoint: string, isSelfHosted: boolean) {
|
||||||
let manager = SOCKET_MANAGER_CACHE.get(endpoint);
|
let manager = SOCKET_MANAGER_CACHE.get(endpoint);
|
||||||
if (!manager) {
|
if (!manager) {
|
||||||
manager = new SocketManager(endpoint);
|
manager = new SocketManager(endpoint, isSelfHosted);
|
||||||
SOCKET_MANAGER_CACHE.set(endpoint, manager);
|
SOCKET_MANAGER_CACHE.set(endpoint, manager);
|
||||||
}
|
}
|
||||||
return manager;
|
return manager;
|
||||||
@@ -218,9 +218,12 @@ export class SocketConnection extends AutoReconnectConnection<{
|
|||||||
socket: Socket;
|
socket: Socket;
|
||||||
disconnect: () => void;
|
disconnect: () => void;
|
||||||
}> {
|
}> {
|
||||||
manager = getSocketManager(this.endpoint);
|
manager = getSocketManager(this.endpoint, this.isSelfHosted);
|
||||||
|
|
||||||
constructor(private readonly endpoint: string) {
|
constructor(
|
||||||
|
private readonly endpoint: string,
|
||||||
|
private readonly isSelfHosted: boolean
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ServerDeploymentType } from '@affine/graphql';
|
||||||
import {
|
import {
|
||||||
IndexedDBDocStorage,
|
IndexedDBDocStorage,
|
||||||
IndexedDBDocSyncStorage,
|
IndexedDBDocSyncStorage,
|
||||||
@@ -64,6 +65,9 @@ export class UserDBEngine extends Entity<{
|
|||||||
id: this.userId,
|
id: this.userId,
|
||||||
serverBaseUrl: serverService.server.baseUrl,
|
serverBaseUrl: serverService.server.baseUrl,
|
||||||
type: 'userspace',
|
type: 'userspace',
|
||||||
|
isSelfHosted:
|
||||||
|
serverService.server.config$.value.type ===
|
||||||
|
ServerDeploymentType.Selfhosted,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
deleteWorkspaceMutation,
|
deleteWorkspaceMutation,
|
||||||
getWorkspaceInfoQuery,
|
getWorkspaceInfoQuery,
|
||||||
getWorkspacesQuery,
|
getWorkspacesQuery,
|
||||||
|
ServerDeploymentType,
|
||||||
} from '@affine/graphql';
|
} from '@affine/graphql';
|
||||||
import type {
|
import type {
|
||||||
BlobStorage,
|
BlobStorage,
|
||||||
@@ -468,6 +469,9 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
|||||||
type: 'workspace',
|
type: 'workspace',
|
||||||
id: workspaceId,
|
id: workspaceId,
|
||||||
serverBaseUrl: this.server.serverMetadata.baseUrl,
|
serverBaseUrl: this.server.serverMetadata.baseUrl,
|
||||||
|
isSelfHosted:
|
||||||
|
this.server.config$.value.type ===
|
||||||
|
ServerDeploymentType.Selfhosted,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
blob: {
|
blob: {
|
||||||
@@ -483,6 +487,9 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
|
|||||||
type: 'workspace',
|
type: 'workspace',
|
||||||
id: workspaceId,
|
id: workspaceId,
|
||||||
serverBaseUrl: this.server.serverMetadata.baseUrl,
|
serverBaseUrl: this.server.serverMetadata.baseUrl,
|
||||||
|
isSelfHosted:
|
||||||
|
this.server.config$.value.type ===
|
||||||
|
ServerDeploymentType.Selfhosted,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user