2

I am trying to send notification to the user when he/she gets a friend request.The problem I am facing is the server is sending the data but it is not able to be shown on the front end.

Here is the server side code

module.exports=function(io) {

  io.on('connection',(socket)=>{
    socket.on('joinRequest',(myRequest,callback)=>{
       socket.join(myRequest.sender);
       callback();
    });

    socket.on('friendRequest',(friend,callback)=>{
      io.to(friend.receiver).emit('newFriendRequest',{
        from:friend.sender,
        to:friend.receiver
      });
      console.log('new friend request sent');
      callback();
    });
  });
}

Here is the code on the client side

socket.on('newFriendRequest',function(friend){
  console.log('heyy got you');
  console.log(friend);
});
Barış Uşaklı
  • 13,440
  • 7
  • 40
  • 66
  • It does not show any error on the client side as well. – sudo_shreyas Jun 15 '18 at 15:24
  • Take a look at this answer: https://stackoverflow.com/questions/10058226/send-response-to-all-clients-except-sender – Rocco Musolino Jun 15 '18 at 15:54
  • @RoccoMusolino thanks for sharing.i went through the link but i don't thing it is solving my problem.If in this line of code io.to(friend.receiver).emit('newFriendRequest',{ if i change it to friend.sender then it shows the output in the browser console but it is not going to show for friend.receiver. – sudo_shreyas Jun 15 '18 at 16:10
  • Are found a workaround? – Oliver D Sep 01 '20 at 23:34

0 Answers0