Skip to content

Instantly share code, notes, and snippets.

@khle
Created January 9, 2016 08:40
Show Gist options
  • Save khle/847b0676f8a9d23f23ab to your computer and use it in GitHub Desktop.
Save khle/847b0676f8a9d23f23ab to your computer and use it in GitHub Desktop.
Server sourceDisconnect
var sourceDisconnect = Rx.Observable.create(function(observer) {
io.on('connection', function(socket) {
socket.on('disconnect', function(data) {
observer.onNext({'socketId': socket.id, 'event': 'client disconnect'});
});
});
});
var observerDisconnect = sourceDisconnect
.subscribe(function(obj) {
var socketId = obj.socketId;
var user = usersMap.get(socketId);
usersMap = usersMap.delete(obj.socketId);
io.emit('all users', usersMap.toArray());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment