Skip to content

Commit

Permalink
send messages to people in same room
Browse files Browse the repository at this point in the history
  • Loading branch information
paras151 committed Aug 6, 2019
1 parent d882eba commit 26fb079
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion public/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ jQuery('#message-form').on('submit',function(e){
e.preventDefault();

socket.emit('createMessage',{
from:'User',
text:jQuery('[name=message]').val()
},function(){

Expand Down
14 changes: 11 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",()=>{
Expand Down

0 comments on commit 26fb079

Please sign in to comment.