I'm having trouble getting the below code to work.
I can get the data using just SocketIO but not with RxJS 6.
class App extends Component {
constructor(props){
super(props);
}
state = {
clusterdata: {}
}
componentDidMount(){
const socket = io('http://localhost:5000',{
path: '/stream',
transports: ['websocket']
});
socket.emit('json', 'my-ecs-cluster');
const clusterStream = Observable.create(observer => {
socket.on('connect', socket => {
console.log(socket);
socket.on('json', data => {
observer.next(data)
})
})
this.clusterStreamObserver = clusterStream.subscribe(this.setClusterData.bind(this));
})
... the setState part
setClusterData(clusterdata){
if (!clusterdata || clusterdata.length === 0) {
return;
this.setState({clusterdata: clusterdata});
}
}
... the render part
render() {
return (
<div className="App">
<header className="App-header">
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
{JSON.stringify(this.state.clusterdata)}
</p>
</div>
);
}
}
export default App;