Notification when a user forcibly disconnect from current room

This commit is contained in:
Hexagon 2014-09-18 23:08:13 +02:00
parent 78ffdf2d66
commit 6352d3ee94
1 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,7 @@ app.io.route('room', {
req.socket.emit('room:joined',req.data);
req.socket.join(req.data);
req.socket.broadcast.to(req.data).emit('message:server', 'A person joined this room');
req.socket.current_room = req.data;
}
},
leave: function(req) {
@ -23,6 +24,7 @@ app.io.route('room', {
req.socket.emit('room:left');
req.socket.leave(req.data);
req.socket.broadcast.to(req.data).emit('message:server', 'A person left this room');
req.socket.current_room = undefined;
}
}
});
@ -34,6 +36,16 @@ app.io.route('message', {
}
});
app.io.sockets.on('connection', function(socket) {
socket.on('disconnect', function() {
// Notify other users of the room
if( socket.current_room !== undefined ) {
socket.broadcast.to(socket.current_room).emit('message:server', 'A person left this room');
console.log('Person left' + socket.current_room);
}
});
});
app.listen(8080, function(){
console.log('listening on *:8080');
});