大家好,我有一个应用程序,目前只能通过http请求来检索数据...现在问题是我们也有一个websocket,但是我不知道如何将它们结合起来使用:
这是我的http请求:
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;
}
这是WebSocket:
public getStockMessages(): Observable<any> {
return new Observable(obs => this.inventoryChannel.on(`STOCK`, (data) => {
return obs.next(data);
}));
}