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
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:
rxjs/packages/rxjs/src/internal/observable/dom/webSocket.ts
Lines 30 to 33 in c666574
WebSocketSubject
docs:
rxjs/packages/rxjs/src/internal/observable/dom/WebSocketSubject.ts
Lines 109 to 113 in c666574
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.