Created
January 9, 2016 08:40
-
-
Save khle/847b0676f8a9d23f23ab to your computer and use it in GitHub Desktop.
Server sourceDisconnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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