0

I am emitting socket from express server whenever successful submission occurs and show toast to other user. But React-Toastify is showing toast to all members in room.

React Code -

useEffect(() => {
    socket.on('successful submission', (data) => {
        toast.success('Opponent Successfully Submitted')
    })
}, [])

Express Code

io.on("connection", (socket: Socket) => {
    socket.on('joinroom', ({ roomId }) => {
        socket.join(roomId)
        socket.broadcast.to(roomId).emit('userjoined', roomId)
    })

    socket.on('successful submission', ({ roomId }) => {
        socket.broadcast.to(roomId).emit('successful submission', true)
    })
})

Please Help and thanks to those who helped!!

  • You're broadcasting your message to the room `socket.broadcast.to(roomId)` so everyone in the room will receive it. – Rob Bailey Jul 01 '21 at 14:30
  • https://socket.io/docs/v3/emit-cheatsheet/index.html it says that above command is used when we dont want sender to receive this message. – Satyam Kulkarni Jul 02 '21 at 06:41

0 Answers0