nest icon indicating copy to clipboard operation
nest copied to clipboard

Add Message Preprocessor in WS Adapter

Open CodyTseng opened this issue 1 year ago • 0 comments
trafficstars

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

The current wsAdapter only supports handling messages in the format { "event": string, "data": any }.

Describe the solution you'd like

I’ve implemented a feature in another-nestjs-ws-adapter that allows preprocessing of messages before routing. This enables the wsAdapter to handle different message formats.

Teachability, documentation, adoption, migration strategy

Add a setMessagePreprocessor method to the wsAdapter to customize how messages are preprocessed.

const wsAdapter = new WsAdapter(app);

wsAdapter.setMessagePreprocessor((message: any) => {
  const [event, ...data] = message;
  return { event, data };
});

What is the motivation / use case for changing the behavior?

I believe this would be a valuable addition to the official @nestjs/websockets package, making it more flexible for various use cases. Would it be possible to consider integrating this functionality?

CodyTseng avatar Sep 23 '24 06:09 CodyTseng