Created
October 11, 2023 10:51
-
-
Save fecoderchinh/abfc19f33da0fcb4059c412fc70daedd to your computer and use it in GitHub Desktop.
Nestjs Websocket - Emitting an event within a service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@WebSocketGateway() | |
export class ChatGateway | |
implements OnGatewayInit | |
{ | |
constructor( | |
private roomService: RoomService | |
) {} | |
@WebSocketServer() | |
public server: Server = new Server(); | |
afterInit(server: Server) { | |
this.roomService.server = server | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class RoomService { | |
constructor() {} | |
public server: Server | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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