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

webSocket docs are contradictory #7309

Closed
skelly-energid opened this issue Jul 19, 2023 · 3 comments
Closed

webSocket docs are contradictory #7309

skelly-energid opened this issue Jul 19, 2023 · 3 comments

Comments

@skelly-energid
Copy link

Describe the bug

https://rxjs.dev/api/webSocket/webSocket contains this text:

" next sends a value to the server, so bear in mind that this value will not be serialized beforehand. Because of This, JSON.stringify will have to be called on a value by hand, before calling next with a result."

It also contains this text:

"Note that both messages will be sent as returned by the functions, they are by default serialized using JSON.stringify, just as messages pushed via next."

This is a contradiction.

I'm new to RxJs, but as far as I know, the first claim in the docs is wrong.

Expected behavior

Correct docs

Reproduction code

No response

Reproduction URL

No response

Version

latest

Environment

No response

Additional context

No response

@kwonoj
Copy link
Member

kwonoj commented Jul 20, 2023

You are mixing text in sections for websocketsubject and multiplex operator's.

@kwonoj kwonoj closed this as completed Jul 20, 2023
@skelly-energid
Copy link
Author

skelly-energid commented Jul 24, 2023

I don't know the distinction you're making. You should probably clarify the docs.

I can't seem to reopen this issue.

@rob4226
Copy link

rob4226 commented Feb 16, 2024

@skelly-energid is right, the docs for webSocket say you must call JSON.stringify on the value passed to .next() but the docblock on WebSocketSubjectConfig.serializer says JSON.stringy is called by default: A serializer used to create messages from passed values before the messages are sent to the server. Defaults to JSON.stringify.

webSocket docs:

* By virtue of being a {@link Subject}, `WebSocketSubject` allows for receiving and sending messages from the server. In order
* to communicate with a connected endpoint, use `next`, `error` and `complete` methods. `next` sends a value to the server, so bear in mind
* that this value will not be serialized beforehand. Because of This, `JSON.stringify` will have to be called on a value by hand,
* before calling `next` with a result. Note also that if at the moment of nexting value

WebSocketSubject docs:

/**
* A serializer used to create messages from passed values before the
* messages are sent to the server. Defaults to JSON.stringify.
*/
serializer?: (value: In) => WebSocketMessage;

So the WebSocketSubject returned by webSocket calls JSON.stringify by default. I found by using webSocket that the next() function does indeed call JSON.stringify for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants