Skip to content

Commit

Permalink
updated messages logic to only send messages to user's in the same room
Browse files Browse the repository at this point in the history
  • Loading branch information
bhubie committed Jul 22, 2017
1 parent 90f724c commit 991c44a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 0 additions & 1 deletion public/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ jQuery('#message-form').on('submit', function(e){
var messageTextBox = jQuery('[name=message]');

socket.emit('createMessage', {
from: 'User',
text: messageTextBox.val()
}, function(){

Expand Down
17 changes: 13 additions & 4 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,23 @@ io.on('connection', (socket) => {
callback();
});

socket.on('createMessage', (message, callback) =>{
console.log('createMesse', message);
io.emit('newMessage', generateMessage(message.from, message.text));
socket.on('createMessage', (message, callback) => {
var user = users.getUser(socket.id);

if(user && isRealString(message.text)) {
io.to(user.room).emit('newMessage', generateMessage(user.name, message.text));
}

callback();
});

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 991c44a

Please sign in to comment.