Notification when a user forcibly disconnect from current room
This commit is contained in:
parent
78ffdf2d66
commit
6352d3ee94
12
server.js
12
server.js
|
@ -16,6 +16,7 @@ app.io.route('room', {
|
||||||
req.socket.emit('room:joined',req.data);
|
req.socket.emit('room:joined',req.data);
|
||||||
req.socket.join(req.data);
|
req.socket.join(req.data);
|
||||||
req.socket.broadcast.to(req.data).emit('message:server', 'A person joined this room');
|
req.socket.broadcast.to(req.data).emit('message:server', 'A person joined this room');
|
||||||
|
req.socket.current_room = req.data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
leave: function(req) {
|
leave: function(req) {
|
||||||
|
@ -23,6 +24,7 @@ app.io.route('room', {
|
||||||
req.socket.emit('room:left');
|
req.socket.emit('room:left');
|
||||||
req.socket.leave(req.data);
|
req.socket.leave(req.data);
|
||||||
req.socket.broadcast.to(req.data).emit('message:server', 'A person left this room');
|
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(){
|
app.listen(8080, function(){
|
||||||
console.log('listening on *:8080');
|
console.log('listening on *:8080');
|
||||||
});
|
});
|
Loading…
Reference in New Issue