mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00: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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user