- 首先在聊天室中添加用户,以便在您的私人聊天室中轻松找到用户
您用于加入私人会议室的客户端代码
<input type="text" id="user_email" placeholder="user_email" />
您在客户端的Javascript代码
function a(){io.emit('privatechatroom', {email:document.getElementById('user_email').value});}
您的服务器端代码以在您的房间中添加用户
socket.on('privatechatroom',function(data){socket.join(data.email);io.emit('res',{mes:"you are added"})});
现在您可以向最近添加到此会议室客户端的那个人发送私人消息
function b() { io.emit('sendmail', { email: document.getElementById('sender_mail').value, message: document.getElementById('message').value }); $('#message').val('');}socket.on('sendmail', function (data) { io.sockets.in(data.email).emit('new_msg', { msg: data.message }); console.log(data.email);});


