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