1

When I broadcast message sender client also get notification from NodeJs here is my code, any chance why send get notification

socket.on('Room', function(data) {
   console.log(' Room : '+data);
   socket.broadcast.emit('Room', {'Room': 'Room'});
});
Vipin Sharma
  • 421
  • 5
  • 24

1 Answers1

1

Send response to all clients except sender (Socket.io)

// sending to all clients in 'game' room(channel) except sender
socket.broadcast.to('game').emit('message', 'nice game');
Community
  • 1
  • 1
danday74
  • 52,471
  • 49
  • 232
  • 283
  • Yes, but be aware that there's a bug(?) with broadcast.to().emit()
    var transport = socket.broadcast.to('room');
    setTimeout(function(){
    
     // this works, will send to all expect the socket
     socket.broadcast.to('room).emit(e, data);
     // this doesnt work. bug?
     transport.emit(e, data);
    }, 
    1000);
    
    – Julius Loa Jun 22 '16 at 09:35