Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should getDataStream.subscribe continue to fire after re-connection? #78

Closed
NadavK opened this issue Apr 21, 2017 · 4 comments
Closed

Comments

@NadavK
Copy link

NadavK commented Apr 21, 2017

I create a $websocket instance with the reconnect param: {"reconnectIfNotNormalClose": true} and the stream nicely reconnects on failures.

I have a problem with incoming messages:
ws.getDataStream().subscribe correctly fires on incoming messages until the websocket reconnects, after which it stops firing.

Am I missing a step so ws.getDataStream().subscribe continues firing after an automatic reconnection?

here is the code (comments welcome, I am new to js):

this.ws = new $WebSocket('wss://...', null, JSON.parse('{"reconnectIfNotNormalClose": true}'));
this.ws.getDataStream().subscribe(
  (msg: MessageEvent) => console.log('message received: ', msg),
  (err) => console.log('incoming websocket err', err),
  () => console.log('incoming websocket complete')
);

I also tried moving the subscribe into the stream's onOpen, but it behaves the same as above (fires only for the initial connection):

this.ws = new $WebSocket('wss://...', null, JSON.parse('{"reconnectIfNotNormalClose": true}'));
this.stream.onOpen(
  this.ws.getDataStream().subscribe(
    (msg: MessageEvent) => console.log('message received: ', msg),
    (err) => console.log('incoming websocket err', err),
    () => console.log('incoming websocket complete')
  )
);
@NadavK
Copy link
Author

NadavK commented Apr 25, 2017

Can anyone provide a hint?

@godzie44
Copy link
Contributor

godzie44 commented Jun 11, 2017

Do you finded the solution of this? Looks like this code in source

this.socket.onerror = (ev: ErrorEvent) => { // console.log('onError ', ev); self.onErrorHandler(ev); this.dataStream.error(ev); };

will internally finalize the observable.

@NadavK
Copy link
Author

NadavK commented Jun 12, 2017

No, I don't have a solution.
Maybe I am not using the package correctly - is there a working sample code?

@godzie44
Copy link
Contributor

I'm fixed this problem by adding stream for error messages. You can watch my solution in fork.

afrad pushed a commit that referenced this issue Jun 12, 2017
* fix wrong dataStream behaviour after reconnect

* change d.ts
@afrad afrad closed this as completed Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants