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

How do I respond to an incoming event with data? #292

Open
mars1211 opened this issue Mar 15, 2023 · 2 comments
Open

How do I respond to an incoming event with data? #292

mars1211 opened this issue Mar 15, 2023 · 2 comments

Comments

@mars1211
Copy link

I think the problem is not solved. I also came across this and did not find an answer.
When receiving an event, you need to respond to it with data, for example, how it is implemented in the JS version:

socket.on("hello", (arg, callback) => {
  console.log(arg); // "world"
  callback("got it");
});

https://socket.io/docs/v4/#acknowledgements

Can you tell me how to implement this?

Please help, this is a critical thing for me.

Originally posted by @mars1211 in #95 (comment)

@mars1211
Copy link
Author

I made this future, and create request as example - #293

@rageshkrishna
Copy link
Contributor

@1c3t3a Would an implementation with the following API be an acceptable solution?

.on("some_message", |payload, client| {
    async move {
        match payload {
            Payload::Binary(_) => todo!(),
            Payload::Text(t) => todo!(),
            Payload::TextAck(t, ack) => {
                client.send_ack(json!({ "ack": "yes" }), ack).await.ok();
            }
        };
    }.boxed()
})

Basically, new TextAck and BinaryAck payload types that indicate the sender expects an acknowledgement to be sent.

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

No branches or pull requests

2 participants