#Socket.io Callback Argument?
34 messages · Page 1 of 1 (latest)
What is that callback on the server supposed to be? Are you looking for how to send back events to the client?
According to socket.io docs, there allowed to using more arguments
Can you point to the docs specifically so I can help clarify?
What is it you're trying to achieve?
In your current example, you only send one argument
What callback? The callback argument you set up on the client side?
That will never be sent to the server. Functions do not normally serialize well
And besides, the callback is a way to tell the function how to behave when it receives a response
Yahh, callback arg from client side, so server side can passing response / data from callback
The server will emit a message basck to the client, and the client can use the callback to know what to do
Yeah, that's not how callbacks work
Server will emit a response, using a certain key (I'd have to refind how socket.io expects this to be defined per event) and the client will match that key to the original call, and call its callback
Okay, I will try to understand this for a moment and conduct some experiments first before marking it as solved.
So the payload value here is serialized?
Serialized and deserialized. HTTP and WS have no clue about types or anyting like that, so the data gets translated into strings, which gets translated to binary and sent off as packets. The server then hears those packets, takes the binary to strings, and then uses some sort of smart parsing (usually) to get them from strings to the appropriate JS type (this is also why we have tools like class-transformer, to even further help with the deserialization)
Actually I'am not understand to using class transformer for this section.
But this my code from the lastest project
So I will migrate to Nest.js
How I do callback from payload? Can you give me an example?
I'm sorry, what? You're just needing to know how to "call" this callback that you have?
If that's the case, just return true or return error.resposnse?.data
Nest will emit the value back for you
Really? return it to observable and rxjs will process?