Open martin-mucha opened 8 years ago
I noticed several nice things in component, so I gave it a more effort to understand it.
I'm quite new to whole js world and not that familiar with rx, but following code from send method ...
return Observable.create((observer) => {
if (self.socket.readyState === self.readyStateConstants.RECONNECT_ABORTED) {
observer.next('Socket connection has been closed');
} else {
self.sendQueue.push({ message: data });
self.fireQueue();
}
});
is surprising for me. Lets assume, that we've been 'sending' messages, but destination was in failure, so messages just accumulated. Now finally destination went up. We send yet another message, using send as with previous messages.
Issues:
"Send message creates observable and does nothing, until we subscribe." I just spent a fair amount of time tracking that down... arg!!!
Looks like the change happened back in july? https://github.com/afrad/angular2-websocket/commit/0e38070f13a22ec4208491e9b8db5f8fbd2fe2e5
See also Issue #41
that's true, but it's not inconvenience. It's fundamentally wrong I believe. Since you're not subscribing to response (what I'd expect, but that would require doing some pairing request/response which is not present). You're subscribing to 'error stream', which is counterintuitive. And this stream produces items rarely and never completes. This made me to rewrite this tool for myself...
I might be reading issue #41 and its comments wrong, but I think the consensus is "it's wrong"
The pattern from the example doesn't work. Only complete ever gets called even though inspecting the traffic you can see the response come back ok. ws.send("some thing").subscribe( (msg)=> { console.log("next", msg.data); }, (msg)=> { console.log("error", msg); }, ()=> { console.log("complete"); } );
Hi,
Can you please add usage example ... I tried to use:
let websocket = new $WebSocket("…"); let observable: Observable = this.websocket.send("test");
observable.subscribe(
value=>console.log("nextValue: " + value),
err=>console.log("error: " + err),
()=>console.log("done.")
);
message arrives to backend, it's returned (to other client), but nothing is logged in console here. Same for using subject.
By using following instead of that:
this.websocket = new $WebSocket("ws://localhost:8280/gerrit-helper/test-websocket-endpoint"); this.websocket.onMessage(function (e) { console.log(e); }, null); let observable: Observable = this.websocket.send("test");
and subscription to cold observable...
this 'works', but seems really wrong. Why does subscription in first excerpt does not work? (when using Observable.range to verify it seems to work as expected).
Thanks.