javascript - How to use RxJs with Socket.IO on event -
i want use rxjs inside of socket.on('sense',function(data){});
. stuck , confused few documentation available , lack of understanding rxjs. here problem.
i have distsensor.js
has function pingend()
function pingend(x){ socket.emit("sense", dist); //pingend fired when interrupt generated. }
inside app.js have
io.on('connection', function (socket) { socket.on('sense', function (data) { //console.log('sense app4 called ' + data); }); });
the sense function gets lots of sensor data want filter using rxjs , don't know should next use rxjs here. pointers right docs or sample help.
i think can use rx.observable.fromevent
(https://github.com/reactive-extensions/rxjs/blob/master/doc/api/core/operators/fromevent.md).
here's how did similar thing using bacon.js, has similar api: https://github.com/raimohanska/bacon-minsk-2015/blob/gh-pages/server.js#l13
so in bacon.js go like
io.on('connection', function(socket){ bacon.fromevent(socket, "sense") .filter(function(data) { return true }) .foreach(function(data) { dealwith(data) }) })
and in rxjs you'd replace bacon.fromevent
rx.observable.fromevent
.