I am using socket io for my chat application one to one. I am facing the issue right now. When user will disconnect or end chat manually by click the end chat button. But from socket that user not remove. Each time room size remains same. How can i remove that user from socket connection.
socket.on('create or join', function(room)
{
numClients = io.sockets.clients(room).length;
console.log("user joining the room");
console.log(numClients);
if (numClients === 0)
{
socket.join(room);
socket.emit('created', room);
}
else if (numClients == 1)
{
io.sockets. in (room).emit('join', room);
socket.join(room);
socket.emit('joined', room);
}
else
{
socket.emit('full', room);
}
socket.emit('emit(): client ' + socket.id + ' joined room ' + room);
socket.broadcast.emit('broadcast(): client ' + socket.id + ' joined room ' + room);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With