免責聲明:我是新來的網絡發展如此忍受我...WebSocketSubject - 優勢?
堆棧:角前端,龍捲風(基於Python-)的後端
Web服務器使用我RxJs一直和WebSocket成功地與後端進行通信,基於這個非常流行的教程:https://medium.com/@lwojciechowski/websockets-with-angular2-and-rxjs-8b6c5be02fac
我剛剛在RxJs 5上偶然發現了WebSocketSubject,我想知道這些優點是什麼?
到目前爲止,我已經能夠用它來連接,發送和接收,但我無法弄清楚如何使用典型RxJs運營商,我用一個主題得到...所以在某種程度上,它只是似乎很難使用。
我錯過了什麼?
這裏是我的工作代碼:我覺得我的困惑來自於缺乏RxJs基本面的理解
//create the socket
this.pubsubSubject = WebSocketSubject.create("ws://" + this.hostName + ":" + connection_info.port + "/" + connection_info.ps);
//output a message when it's open
this.pubsubSubject.openObserver = {
next: value => {
console.log("ps socket is " + (this.pubsubSubject.socket.readyState == WebSocket.OPEN ? "OPEN" : "NOT OPEN"));
}
}
//send the authentication token through the socket
this.pubsubSubject.next(JSON.stringify(authenticate_request));
//subscribe to specific events from server
var subscription = {
"subscribe": events
}
this.pubsubSubject.next(JSON.stringify(subscription));
//start getting messages
this.pubsubSubject.subscribe(
(msg: any) => {
console.log("msg: " + msg);
}
)