Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(ws): introduce message parser for ws adapter #14127

Open
wants to merge 3 commits into
base: 11.0.0
Choose a base branch
from

Conversation

CodyTseng
Copy link
Contributor

@CodyTseng CodyTseng commented Nov 10, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #14027

What is the new behavior?

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 };
});

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build c2aa204b-3107-4901-82ec-903bb6861111

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.243%

Totals Coverage Status
Change from base Build 72f148bc-4145-44b3-a3c4-06a616307114: 0.0%
Covered Lines: 6754
Relevant Lines: 7322

💛 - Coveralls

@CodyTseng CodyTseng changed the title feat: introduce message preprocessor for ws adapter feat(ws): introduce message preprocessor for ws adapter Nov 10, 2024
@CodyTseng CodyTseng marked this pull request as ready for review November 10, 2024 08:38
@@ -138,7 +142,10 @@ export class WsAdapter extends AbstractWsAdapter {
transform: (data: any) => Observable<any>,
): Observable<any> {
try {
const message = JSON.parse(buffer.data);
const message = this.messagePreprocessor(JSON.parse(buffer.data));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should move the "JSON.parse" call to the preprocessor, and just call it parser instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a great idea.

Additionally, should we consider supporting configuration in the constructor, like this:

new WsAdapter(app, {
  messageParser: (data) => ...
})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, sounds good!

@CodyTseng CodyTseng changed the title feat(ws): introduce message preprocessor for ws adapter feat(ws): introduce message parser for ws adapter Nov 13, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants