socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

inter-server comm not really a replacement to customHook / customRequest

Open fliespl opened this issue 4 years ago • 3 comments

customRequest / customHook were triggered for all servers (including current node).

serverSideEmit only works for "other" nodes.

        if (request.uid === this.uid) {
          debug("ignore same uid");
          return;
        }

Of course - we can execute method locally using js function, but if we want to combine answers from other nodes + current node - that requires some additional logic.

Probably worth adding a switch that would allow emiting to local node as well and collect it's result in same manner as remote ones?

fliespl avatar May 26 '21 07:05 fliespl

You are right, the behavior is slightly different. We can indeed add a switch to include the current node :+1:

darrachequesne avatar May 27 '21 08:05 darrachequesne

any update on this?

spearmootz avatar Nov 08 '23 01:11 spearmootz

BTW meanwhile i did this.

public emitToServers<T extends any[]>(type: string, args?: T) {
    // THIS IS NEEDED BECAUSE SERVER SIDE EMITS ONLY EMITS TO OTHER SERVERS
    this.io.listeners(this.getServerSideEventName(type)).forEach((listener) => {
      listener(...(args || []));
    });
    this.io.serverSideEmit(this.getServerSideEventName(type), ...(args || []));
  }

spearmootz avatar Nov 08 '23 01:11 spearmootz