Skip to content

Instantly share code, notes, and snippets.

@fecoderchinh
Created October 11, 2023 10:51
Show Gist options
  • Save fecoderchinh/abfc19f33da0fcb4059c412fc70daedd to your computer and use it in GitHub Desktop.
Save fecoderchinh/abfc19f33da0fcb4059c412fc70daedd to your computer and use it in GitHub Desktop.
Nestjs Websocket - Emitting an event within a service
@WebSocketGateway()
export class ChatGateway
implements OnGatewayInit
{
constructor(
private roomService: RoomService
) {}
@WebSocketServer()
public server: Server = new Server();
afterInit(server: Server) {
this.roomService.server = server
}
// ...
}
@Injectable()
export class RoomService {
constructor() {}
public server: Server
// ...
}
@Module({
imports: [ChatModule, RoomModule],
})
export class SocketsModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment