Skip to content

Is there a way to "transform" an event before being emitted to a member of a room? #4050

Answered by darrachequesne
mikecann asked this question in Q&A
Discussion options

You must be logged in to vote

I think the easiest way to achieve this is to use two rooms, one for the full payload and one for the restricted one:

// full payload
io.to("user:abc:admin").emit("updated", { id: "abc", name: "newname", balance: 123456 });

// restricted payload
io.to("user:abc").emit("updated", { id: "abc", name: "newname" });

Reference: https://socket.io/docs/v4/rooms/

This can also be achieved with a namespace:

io.of("/admin").to("user:abc").emit("updated", { id: "abc", name: "newname", balance: 123456 });

Reference: https://socket.io/docs/v4/namespaces/

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mikecann
Comment options

Answer selected by darrachequesne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants