Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Message Preprocessor in WS Adapter #14027

Open
1 task done
CodyTseng opened this issue Sep 23, 2024 · 0 comments
Open
1 task done

Add Message Preprocessor in WS Adapter #14027

CodyTseng opened this issue Sep 23, 2024 · 0 comments
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@CodyTseng
Copy link
Contributor

Is there an existing issue that is already proposing this?

  • 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 CodyTseng added needs triage This issue has not been looked into type: enhancement 🐺 labels Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

1 participant