Hi all I've an application that until now was only doing http request to retrieve data...now the problem is that we have also a websocket but I've no idea how to combine both of them:
This is my http request:
public stock(): Observable<any> {
if (!this._stock) {
// rest api
this._stock = this.http.get(url)
.map((stock: Response) => {
// cache the value
stock.json().items.forEach((item) => {
this._stock[item.productKey] = item;
});
return this._stock;
})
.publishReplay(1)
.refCount();
}
return this._stock;
}
This is the websocket:
public getStockMessages(): Observable<any> {
return new Observable(obs => this.inventoryChannel.on(`STOCK`, (data) => {
return obs.next(data);
}));
}
Given what you've said above, it seems like you're looking to:
stock().concat(getStockMessages())
... is probably what you want.
But honestly I'm still having a hard time figuring out exactly what you're trying to do... but I think this will solve your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With