Basically I'm trying to create a quick chat room using Node.JS and angular.
I've Used other socket events and they worked I don't quite get why they don't want to work now. The really weird thing is that The login works fine and quite well, but when It comes to the logout, or even using my disconnect method, Nothing happens on the server side, with the disconnect function, the console.log
works fine. But It won't emit.
On the angular side all my console.log
s are running yet no events hit the server when logging out or discconecnting.
Inside of Node I have Three Events
socket.on('chat:userLogin', function(user) {
socket.join('online-users');
chatRoom[user.id] = user
console.log('User Has logged in, chat room contains: ', chatRoom);
io.sockets.in('online-users').emit('chat:usersOnline', chatRoom)
})
socket.on('chat:userLogout', function(userId) {
console.log('User Id ' + userId + 'is logging out');
delete chatRoom[userId]
console.log('User Has logged out, chat room contains: ', chatRoom);
io.sockets.in('online-users').emit('chat:userLeave', chatRoom);
socket.leave('online-users');
})
socket.on('disconnect', function() {
var userRoom = rooms[socket.roomId]
if (chatRoom[socket.userId])
delete chatRoom[socket.userId]
io.sockets.in('online-users').emit('chat:userLeave', socket.userId);
console.log('Emitting that users have left to: ', io.sockets.in('online-users'));
socket.leave('online-users');
}
And in angular I have a Two functions that emit these two events
this.logout = function(userId) {
console.log('Logging user out: ', userId);
Socket.emit('chat:userLogout', userId);
console.log('Logged out user?');
delete this.userStore[userId]
}
this.login = function(userId) {
console.log('Getting online user ', userId);
var self = this;
User.get({id: userId}, function(user) {
self.userStore[userId] = user;
Socket.emit('chat:userLogin', user);
});
}