JavaScript socket.io rooms repeating same message per client

I'm using rooms to send a 'private' message to a client and it works however the message being sent is duplicated by the number of clients I have and I believe this is because of my .on('message') since this is still triggering for every client but only emitting to the correct client (but multiple times..)

server

io.sockets.on('connection', function(socket {
    socket.on('join', function(data)
    {
        console.log('enter');
        socket.join(data.user);
});

var rClient =   redis.createClient();
rClient.subscribe('messagex');

rClient.on('message', function(channel, message) {
    io.in(message.user).emit('messagex', {content: message.content});
});

socket.on('disconnect', function() {
    rClient.quit();
});

});

receiver client

<script>
var username = prompt("test");
var socket  =   io.connect('http://localhost:8100');
socket.emit('join', {user: username});

socket.on('messagex', function(data) {
    $('#messages').append('<p>' + data.content + '</p>');
});

So I have 3 clients (each with different users/rooms open) at the receiver page and I send a message from the sender to say user user1, then I will only receive the message on user1 client but it will receive 3 of the same message each time and the number of times duplicated seems to be the number of clients I have..

Answer:1

try this

subscribe.unsubscribe(channel); 

when connection disconnect unsubscribe

io.sockets.on('connection', function(socket {
socket.on('join', function(data)
{
    console.log('enter');
    socket.join(data.user);
});

var rClient =   redis.createClient();
rClient.subscribe('messagex');

rClient.on('message', function(channel, message) {
    io.in(message.user).emit('messagex', {content: message.content});
});

socket.on('disconnect', function() {

rClient.unsubscribe('messagex'); 
  rClient.quit();
});
});
Answer:2

Why are there two sets of parenthesis here? return state.filter(({ id }) => { return id !== action.id }); I'm having such a tough time wrapping my head around this one ...

Why are there two sets of parenthesis here? return state.filter(({ id }) => { return id !== action.id }); I'm having such a tough time wrapping my head around this one ...

I have search a lot on Internet, but i did not found any good example for what i am looking. It may be due to i am new in angularjs. What i am looking, I have some common function which i need to ...

I have search a lot on Internet, but i did not found any good example for what i am looking. It may be due to i am new in angularjs. What i am looking, I have some common function which i need to ...

  1. angularjs calling directive function from controller
  2. angularjs calling directive from controller
  3. angularjs calling directive method
  4. angularjs call directive function from outside
  5. angularjs call directive function
  6. angularjs call directive
  7. angularjs call directive on button click
  8. angularjs call directive method from controller
  9. angularjs call directive function from parent controller
  10. angularjs call directive link function from controller
  11. angularjs call directive function from html
  12. angularjs call directive after render
  13. angularjs call directive from javascript
  14. angularjs call directive function from parent
  15. angularjs call directive on load
  16. angularjs call directive from html
  17. angularjs call directive from service
  18. angularjs call directive callback
  19. angularjs directive call controller function with parameters
  20. angularjs directive call function with parameters

So I have this function inside a Component: clickedResultHandler = (embedLink) => { this.setState({embedSrcLink: embedLink}); } this function is called inside a descendant like this: <div ...

So I have this function inside a Component: clickedResultHandler = (embedLink) => { this.setState({embedSrcLink: embedLink}); } this function is called inside a descendant like this: <div ...

  1. different values of r
  2. different values and beliefs
  3. different values in life
  4. different values of a single hue
  5. different values of r gas constant
  6. different values in art
  7. different values of r in chemistry
  8. different values in cultures
  9. different values of i
  10. different values relationship
  11. different values of infinity
  12. different values to have
  13. different values of one color
  14. different values of pi
  15. different values meaning
  16. different values of the same hue
  17. different values in the workplace
  18. different values around the world
  19. different values between generations
  20. different values from parents

I'm working with auth in Nextjs, I'm wondering what is the best strategy to handle authentication in NextJS ? Here my services structure : If I understand well I have to handle the server side ...

I'm working with auth in Nextjs, I'm wondering what is the best strategy to handle authentication in NextJS ? Here my services structure : If I understand well I have to handle the server side ...

  1. next js auth
  2. next js with auth
  3. next js authentication
  4. next js with authentication