ReactiveX/rxjs

webSocket docs are contradictory

skelly-energid opened this issue · 3 comments

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 commented

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

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

I can't seem to reopen this issue.

@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.