1

My app is about web conference using webrtc. When clients are conferencing and chatting, everything about emitting and receiving events with socket.io works fine. Now i want to inform main page viewers about the current number of rooms and clients, so i added socket to this page too

main page

        var socket = io.connect('https://...................');

        socket.on('connect', function() {
          console.log('check 2', socket.connected);
          socket.emit('check','hello'); // works fine 
        });

            socket.on('numbers',function(data){
                console.log(JSON.stringify(data)); // nothing as output             
            });

            socket.on('error', function (err) {
            console.log(err);
            });

Now, if a client disconnects, server catches disconnection event but no emit takes place

server

  io.on('connection' , function(socket){
              .........

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

             socket.broadcast.emit('numbers','hello');

       });
   });

I cannot figure out what the problem is. Is it that main page viewers are not in the same socket as clients in a room; I think i'm missing something important here. Thanks in advance

  • Possible duplicate of [Socket.IO handling disconnect event](https://stackoverflow.com/questions/17287330/socket-io-handling-disconnect-event) – DatNoHand Nov 13 '17 at 19:24
  • The post you are suggesting proposes an alternative way. It does not give an explanation – Johnk Overlord Nov 14 '17 at 15:00

0 Answers0