Created
January 9, 2016 08:26
-
-
Save khle/89908614d020eed6a50e to your computer and use it in GitHub Desktop.
Server sourceConnect
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 io = require('socket.io')(server); | |
var sourceConnect = Rx.Observable.create(function(observer) { | |
io.on('connection', function(socket) { | |
socket.emit('my socketId', {'socketId': socket.id, 'connectTime': Date.now()}); | |
socket.on('client connect', function(data) { | |
observer.onNext({'socket': socket, 'data': data, 'event': 'client connect'}); | |
}); | |
}); | |
}); | |
var observerConnect = sourceConnect | |
.subscribe(function(obj) { | |
var socketId = obj.data.socketId; | |
usersMap = usersMap.set(socketId, obj.data); | |
io.emit('all users', usersMap.toArray()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment