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

Make emitWithAck for a room say which socket(s) failed to ack #4967

Open
rhoot opened this issue Mar 6, 2024 · 1 comment
Open

Make emitWithAck for a room say which socket(s) failed to ack #4967

rhoot opened this issue Mar 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@rhoot
Copy link

rhoot commented Mar 6, 2024

Is your feature request related to a problem? Please describe.

I'm trying to make use of io.to("room").emitWithAck(...) to make clients all proceed to the next stage of a game, but I'm not quite sure what I could reasonably do if an ack fails. Ideally I'd re-send the data to that client, forcefully disconnect it, or notify the rest of the room that the client is having connectivity issues.

But as far as I could tell browsing the socket.io and memory adapter source, it's currently not possible to determine which socket(s) failed to ack?

Describe the solution you'd like

Using something like:

try {
    const responses = await io.to("room").emitWithAck("event");
} catch (e) {

}

It would be great if I could find out in the catch block which socket(s) failed to ack.

Describe alternatives you've considered

The first alternative I could think of would be to emitWithAck to each socket individually, and then emit an "ok go ahead" event to the room, but that has the same problem: Not every client may get the follow-up event.

Another alternative I can think of would be to emitWithAck and if it fails, emit a message to each client individually and seeing which one (if any) fails to respond. It seems a bit tedious though, especially considering socket.io already knows which socket(s) it was that failed.

And an idea I got while typing this (and may be the option I'll go with) would be that I make the client respond to the event with an identifier unique to the client. Then the failed socket would be the one whose identifier was not in any of the ack responses, after which I could look up that ID in some object.

@rhoot rhoot added the enhancement New feature or request label Mar 6, 2024
@darrachequesne
Copy link
Member

But as far as I could tell browsing the socket.io and memory adapter source, it's currently not possible to determine which socket(s) failed to ack?

That's right.

but I'm not quite sure what I could reasonably do if an ack fails

Do you really need an acknowledgement from every client? If the ack fails, this usually means that a client has been disconnected. In that case, you can send the updated state of the world upon reconnection. Or do you need some manual acknowledgement from the users?

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

No branches or pull requests

2 participants