#Socket.io Callback Argument?

34 messages · Page 1 of 1 (latest)

tender fiber
#

I trying to make callback argument from client side but here showing undefined

patent jetty
#

What is that callback on the server supposed to be? Are you looking for how to send back events to the client?

tender fiber
patent jetty
#

Can you point to the docs specifically so I can help clarify?

tender fiber
#

In Nest.js, why does socket.io only receive one argument?

patent jetty
#

What is it you're trying to achieve?

patent jetty
tender fiber
#

I confused

#

But I can't use callback from server side

patent jetty
#

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

tender fiber
#

Yahh, callback arg from client side, so server side can passing response / data from callback

patent jetty
#

The server will emit a message basck to the client, and the client can use the callback to know what to do

patent jetty
#

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

tender fiber
#

Okay, I will try to understand this for a moment and conduct some experiments first before marking it as solved.

tender fiber
patent jetty
#

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)

tender fiber
#

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?

patent jetty
#

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

tender fiber
#

Really? return it to observable and rxjs will process?

patent jetty
#

Yep

#

Try it

tender fiber
#

Oh my gosh, it's cool -_-

#

Thanks sir @patent jetty