From 6352d3ee949ceccb0e1e61ee4af951099adafd44 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Thu, 18 Sep 2014 23:08:13 +0200 Subject: [PATCH] Notification when a user forcibly disconnect from current room --- server.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server.js b/server.js index b0b303e..6a8fe90 100644 --- a/server.js +++ b/server.js @@ -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'); }); \ No newline at end of file