import { DynamicModule } from '@nestjs/common'; import { SocketModuleConfigOptions } from './domain/interfaces'; /** * Configures a Socket.IO server for real-time communication. * * ### Usage Example: * * 1. **Configure in your main module**: * ```typescript * // app.module.ts * import { Module } from '@nestjs/common'; * import { SocketConfigModule } from 'this-library'; * * @Module({ * imports: [ * SocketConfigModule.config({ * socketOptions: { * cors: { * origin: 'http://localhost:3000', * methods: ['GET', 'POST'], * }, * // Additional Socket.IO options * }, * isGlobal: true, // Make available globally * }), * ], * }) * export class AppModule {} * ``` * * 2. **Create a custom gateway** (in consumer project): * ```typescript * // events.gateway.ts * import { WebSocketGateway, WebSocketServer, OnGatewayInit } from '@nestjs/websockets'; * import { Server } from 'socket.io'; * import { Inject } from '@nestjs/common'; * import { SOCKET_SERVER } from 'this-library'; * * @WebSocketGateway() * export class EventsGateway implements OnGatewayInit { * @WebSocketServer() * private server: Server; * * constructor(@Inject(SOCKET_SERVER) private readonly io: Server) {} * * afterInit() { * console.log('Socket.IO server initialized'); * } * * handleConnection(client: any) { * this.io.emit('user-connected', { id: client.id }); * } * } * ``` * * 3. **Emit events from any service**: * ```typescript * // notification.service.ts * import { Injectable } from '@nestjs/common'; * import { SOCKET_SERVICE, SocketServicePort } from 'this-library'; * * @Injectable() * export class NotificationService { * constructor( * @Inject(SOCKET_SERVICE) private readonly socketService: SocketServicePort * ) {} * * sendGlobalNotification(message: string) { * this.socketService.emit('notification', { * timestamp: new Date(), * message * }); * } * } * ``` * * 4. **Advanced: Access server directly**: * ```typescript * // room.service.ts * import { Injectable } from '@nestjs/common'; * import { SOCKET_SERVER } from 'this-library'; * import { Server } from 'socket.io'; * * @Injectable() * export class RoomService { * constructor(@Inject(SOCKET_SERVER) private readonly io: Server) {} * * joinRoom(clientId: string, room: string) { * this.io.sockets.sockets.get(clientId)?.join(room); * } * * broadcastToRoom(room: string, event: string, data: any) { * this.io.to(room).emit(event, data); * } * } * ``` * */ export declare class WebsocketsConfigModule { /** * Socket.IO configuration module * * @param options.socketOptions Required. Socket.IO server configuration * @param options.isGlobal Required. Whether to register globally. Default: false * @returns DynamicModule with configured Socket.IO server and service */ static config(options: SocketModuleConfigOptions): DynamicModule; } //# sourceMappingURL=websockets.module.d.ts.map