socket emitting beyond the room

0

All clients are receiving the message through socket.io.     I wish only the users in the room would receive.

Server.js

sockets.on('connection', function (action) {
   action.join('testroom');

   action.on('say to someone', function(msg){
      sockets.to('testroom').emit('some event', msg);
   });

});

Client on which you send the message:

Client

socket.on('connect', function () {
   socket.emit('join', 'testroom');
});

socket.on('some event', function (data) {
    console.log(data);
});

$('form').submit(function () {
   event.preventDefault();
   socket.emit('say to someone', $('#m').val() );
   $('#m').val('');
});

Customer who is receiving the message wrongly:

Client

socket.on('connect',(socket) => {
    socket.on('some event', data => {
      console.log(data);
    });

}); 

Ps: Client B is being used in VueJs.

    
asked by anonymous 30.05.2017 / 21:41

1 answer

0

Friend I'm on the street now but I believe your problem is

sockets.on('connection', function (action) {
   action.join('testroom');

   action.on('say to someone', function(msg){

    //essa parte aqui 
      sockets.to('testroom').emit('some event', msg);


      //Mude para isso// onde o 'io' é a variavel onde voce armazenou o socket.io // Exemplo : var io = require('socket.io')(http);
      
      io.sockets.in('testroom').emit('some event', msg);
      
   });

});
    
14.07.2017 / 17:33