In general, such problems, it was necessary to realize that when typing a message, the interlocutor was sent a notification that you were typing the message, but I get that when I’m showing that I’m typing only me, but the interlocutor doesn’t, as I understand it does not send, send? and how best to "keydown" - "keyup" or "keypress"?
var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res) { res.sendfile('index.html'); }); // socket.on - приём сообщения // io.emit - отправка сообщения io.on('connection', function(socket) { socket.on('chat message', function(msg, name, dodo) { io.emit('chat message', msg, name, dodo); }); }); http.listen(3000, function() { console.log('listening on *:3000'); }); <!doctype html> <html> <head> <title>Socket.IO chat</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font: 13px Helvetica, Arial; } form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } form button { width: 20%; background: rgb(130, 224, 255); border: none; padding: 10px; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } </style> </head> <body> <span id="dodo"></span> <ul id="messages"></ul> <form action=""> <input type="text" id="user" placeholder="Who are you?"> <input type="text" id="message" placeholder="What do you want to say?"> <button type="submit">Send</button> </form> <script src="/socket.io/socket.io.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> <script> $(function() { var socket = io(); var $messages = $('#messages'); var $message = $('#message'); var $user = $('#user'); var dodo = $('#dodo'); $('form').submit(function() { // Отправка сообщения socket.emit('chat message', $message.val(), $user.val(), dodo.val()); // Очищаем текстовое окно сообщения $message.val(''); return false; }); // Приём сообщения с сервера socket.on('chat message', function(msg, name, dodo) { $messages.append($('<li>').text(dodo + name + ':' + msg)); $messages.append($('#dodo').text(dodo)); }); $($message).keydown(function() { $("#dodo").empty(); var mes = $("<b>пользователь печатает сообщение...</b>"); $("#dodo").last().append(mes); }); $($message).keyup(function() { $("#dodo").empty(); var mes = $("<b></b>"); $("#dodo").last().append(mes); }); }); </script> </body> </html>