-
I am creating a chatapp with node.js express and react. The application working and sending message all users but when i try send message to specific room, it's not working. Code in below socket.on('login', (data) => {
socket.join("room1");
})
socket.on('sendMessage', (data) => {
socket.emit('messageResponse', data); // **this is working**
socket.to("room1").emit('messageResponse', data); // **this is not working**
}) Edit by @darrachequesne: code formatting |
Beta Was this translation helpful? Give feedback.
Answered by
uyarhamit
Sep 22, 2023
Replies: 1 comment 1 reply
-
Hi! That's weird, this should totally work. Please note that // to all clients in "room1" except the socket
socket.to("room1").emit('messageResponse', data);
// to all clients in "room1"
io.to("room1").emit('messageResponse', data); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Thank you for your answer but i just fixed the bug. The problem is about frontend socket.io-client. I was sending socket as a prop to other components. That was a mistake. When i create socket file and import in the pages, my app works.