Skip to content

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

Closed

Description

@rhoot

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.

Activity

  1. darrachequesne commented on Mar 12, 2024

    @darrachequesne
    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?

  2. darrachequesne commented on Sep 18, 2024

    @darrachequesne
    Member

    I think this can be closed now. Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions