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

could we ack when we receive a new event #379

Open
magamal opened this issue May 4, 2024 · 3 comments
Open

could we ack when we receive a new event #379

magamal opened this issue May 4, 2024 · 3 comments
Labels

Comments

@magamal
Copy link

magamal commented May 4, 2024

`socket.on("new_message",(data)=>{

//How to ack this event?
})'`

@magamal
Copy link
Author

magamal commented May 5, 2024

Yes I read it before, but if I'm receiving a string from the server how I can ack this event

socket.on("new_message",(data)=>{
final String messageContent = data;
}

@steveroseik
Copy link

steveroseik commented May 18, 2024

Yes I read it before, but if I'm receiving a string from the server how I can ack this event

socket.on("new_message",(data)=>{ final String messageContent = data; }

Heyy, I had the same issue and figured out the solution.

It's pretty easy, it's the lack of information in the documentation that makes it hard to figure out.

I'll show you my example:

in my server side I send a nudge to the client, when you send it, the client receives a list of data, consists of the data you sent in the emit and an extra callback function that should be used for acks:

so this is how the data might look like if you used my code below:

['Input the data to be sent.', function()]

this.server
        .to(opponentId)
        .timeout(5000)
        .emit(
          'nudge',
          'Input the data to be sent.',
          (err, responses) => {
            if (err) {
              /// handle timeout
            } else {
              // handle responses
            }
          },
        );

That's why in flutter you'll need to treat the data received as a list, and extract from it both data sent from server and the function;

you can handle the data as you like, and the take the last item as Function and run it as described in their code sample:

socket.on('nudge', (data) {
    final dataList = data as List;

    final customData = dataList.first;

    final ack = dataList.last as Function;
    ack(null);
});

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

No branches or pull requests

3 participants