diff --git a/public/js/chat.js b/public/js/chat.js index 7304c68..5e92a4a 100644 --- a/public/js/chat.js +++ b/public/js/chat.js @@ -90,7 +90,6 @@ jQuery('#message-form').on('submit',function(e){ e.preventDefault(); socket.emit('createMessage',{ - from:'User', text:jQuery('[name=message]').val() },function(){ diff --git a/server/server.js b/server/server.js index bd6b288..2265f47 100644 --- a/server/server.js +++ b/server/server.js @@ -38,15 +38,23 @@ io.on('connection',(socket)=>{ }) socket.on('createMessage',(message,callback)=>{ - console.log('createMessage',message); + var user = users.getUser(socket.id); - io.emit('newMessage',generateMessage(message.from,message.text)) + if(user && isRealString(message.text)){ + io.to(user.room).emit('newMessage',generateMessage(user.name,message.text)) + + } + callback('This is form server'); }) socket.on('createLocationMessage',(coords)=>{ - io.emit('newLocationMessage',generateLocationMessage('Admin',coords.latitude,coords.longitude)) + var user = users.getUser(socket.id); + if(user){ + io.to(user.room).emit('newLocationMessage',generateLocationMessage(user.name,coords.latitude,coords.longitude)) + + } }) socket.on("disconnect",()=>{