Skip to content

Is there way emit everyone except sender/"person who made request" inside express route #4087

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

You must be logged in to vote

It should be doable with express-session:

io.on("connection", (socket) => {
  // join the room identified by the session ID
  socket.join(socket.request.sessionID);
});

router.post("/test", (req, res) => {
  // send to everyone except those in the given room
  io.except(req.sessionID).emit(/* ... */);
});

For the setup, please see https://socket.io/docs/v4/faq/#usage-with-express-session (until we have a proper example with express-session)

Replies: 1 comment 1 reply

Comment options

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

Answer selected by JuHaNi654
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