免责声明:我是新来的网络发展如此忍受我...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);
}
)