I am trying to configure the socket.io chat server. I received it for sending and receiving messages from the server and client. I was interested in showing users if someone is typing. I know that I can emit when someone prints from the client to the server, I can also transfer it to other users. But will it effectively do this on every keyboard? How can I deal with this situation? Below is my code:
$("#textbox").keyup(function (e) { if (e.keyCode == 13) { socket.emit('send', {nickname: $('#nickname').val() , msg: $("#textbox").val()}); $('#textbox').val(''); } else{ socket.emit('is typing', {nickname: $('#nickname').val()}); } });
and server side:
socket.on('is typing', function(data){ socket.broadcast.emit('typing', {nickname: data.nickname}); });
source share