is there a way to dynamically subscribe to events in websocket server in nestjs

Viewed 542

I am trying to see if there is a way to dynamically use @SubscribeMessage() decorator.

So far, I have been able to listen to "known events" like in Method(a). But I would like to dynamically generate the event-name <Method (b)> in controller and start listening to it in gateway.

or, I want to listen to all events emitted on that socket and process them as in Method 2

Method(a):

 @SubscribeMessage('event1')
  handleMessage(args[]){
  // DO STUFF
  } 

Method (b):

  @SubscribeMessage(MY_DYNAMIC_EVENT_AT_RUNTIME)
  async handleMessage(client: Socket, payload: string){
    //DO STUFF
 }

Method 2:

@SubscribeMessage(*)
  async handleMessage(client: Socket, payload: string){
    //DO STUFF
  }

I saw some wildcard concepts for socket.io , How can I use it here with NestJs?

0 Answers
Related