Skip to content

Instantly share code, notes, and snippets.

@khle
Created January 9, 2016 08:26
Show Gist options
  • Save khle/89908614d020eed6a50e to your computer and use it in GitHub Desktop.
Save khle/89908614d020eed6a50e to your computer and use it in GitHub Desktop.
Server sourceConnect
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