mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 05:01:15 +10:00
* feat: adding family 6 in uri to configure for both 4 and 6 * feat: adding redis family in websocket config
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { Hocuspocus, Server as HocuspocusServer } from '@hocuspocus/server';
|
|
import { IncomingMessage } from 'http';
|
|
import WebSocket from 'ws';
|
|
import { AuthenticationExtension } from './extensions/authentication.extension';
|
|
import { PersistenceExtension } from './extensions/persistence.extension';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { Redis } from '@hocuspocus/extension-redis';
|
|
import { EnvironmentService } from '../integrations/environment/environment.service';
|
|
import {
|
|
createRetryStrategy,
|
|
parseRedisUrl,
|
|
RedisConfig,
|
|
} from '../common/helpers';
|
|
|
|
@Injectable()
|
|
export class CollaborationGateway {
|
|
private hocuspocus: Hocuspocus;
|
|
private redisConfig: RedisConfig;
|
|
|
|
constructor(
|
|
private authenticationExtension: AuthenticationExtension,
|
|
private persistenceExtension: PersistenceExtension,
|
|
private environmentService: EnvironmentService,
|
|
) {
|
|
this.redisConfig = parseRedisUrl(this.environmentService.getRedisUrl());
|
|
|
|
this.hocuspocus = HocuspocusServer.configure({
|
|
debounce: 10000,
|
|
maxDebounce: 20000,
|
|
unloadImmediately: false,
|
|
extensions: [
|
|
this.authenticationExtension,
|
|
this.persistenceExtension,
|
|
...(this.environmentService.isCollabDisableRedis()
|
|
? []
|
|
: [
|
|
new Redis({
|
|
host: this.redisConfig.host,
|
|
port: this.redisConfig.port,
|
|
options: {
|
|
password: this.redisConfig.password,
|
|
db: this.redisConfig.db,
|
|
family: this.redisConfig.family,
|
|
retryStrategy: createRetryStrategy(),
|
|
},
|
|
}),
|
|
]),
|
|
],
|
|
});
|
|
}
|
|
|
|
handleConnection(client: WebSocket, request: IncomingMessage): any {
|
|
this.hocuspocus.handleConnection(client, request);
|
|
}
|
|
|
|
getConnectionCount() {
|
|
return this.hocuspocus.getConnectionsCount();
|
|
}
|
|
|
|
getDocumentCount() {
|
|
return this.hocuspocus.getDocumentsCount();
|
|
}
|
|
|
|
async destroy(): Promise<void> {
|
|
await this.hocuspocus.destroy();
|
|
}
|
|
}
|