mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import './config';
|
|
|
|
import {
|
|
FactoryProvider,
|
|
INestApplicationContext,
|
|
Module,
|
|
Provider,
|
|
} from '@nestjs/common';
|
|
import { IoAdapter } from '@nestjs/platform-socket.io';
|
|
import { Server } from 'socket.io';
|
|
|
|
import { Config } from '../config';
|
|
|
|
export const SocketIoAdapterImpl = Symbol('SocketIoAdapterImpl');
|
|
|
|
export class SocketIoAdapter extends IoAdapter {
|
|
constructor(protected readonly app: INestApplicationContext) {
|
|
super(app);
|
|
}
|
|
|
|
override createIOServer(port: number, options?: any): Server {
|
|
const config = this.app.get(WEBSOCKET_OPTIONS);
|
|
return super.createIOServer(port, { ...config, ...options });
|
|
}
|
|
}
|
|
|
|
const SocketIoAdapterImplProvider: Provider = {
|
|
provide: SocketIoAdapterImpl,
|
|
useValue: SocketIoAdapter,
|
|
};
|
|
|
|
export const WEBSOCKET_OPTIONS = Symbol('WEBSOCKET_OPTIONS');
|
|
|
|
export const websocketOptionsProvider: FactoryProvider = {
|
|
provide: WEBSOCKET_OPTIONS,
|
|
useFactory: (config: Config) => {
|
|
return config.websocket;
|
|
},
|
|
inject: [Config],
|
|
};
|
|
|
|
@Module({
|
|
providers: [SocketIoAdapterImplProvider, websocketOptionsProvider],
|
|
exports: [SocketIoAdapterImplProvider, websocketOptionsProvider],
|
|
})
|
|
export class WebSocketModule {}
|