socket.io
socket.io copied to clipboard
inter-server comm not really a replacement to customHook / customRequest
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?
You are right, the behavior is slightly different. We can indeed add a switch to include the current node :+1:
any update on this?
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 || []));
}