Skip to content Skip to sidebar Skip to footer

Reconnecting A Websocket With A Shared Rxjs Observable

I have an observable like this: const records$ = Rx.DOM.fromWebSocket('ws://192.168.2.4:9001/feed/', null) .map(ev => parseRecord(ev.data)) .share(); I have many su

Solution 1:

I believe in rxjs v5, share does allow you to reconnect but not in Rxjs v4.

In Rxjs 4, share is bascially multicast.refCount and once the subject used for the multicast is completed, it cannot be reused (per Rxjs grammar rules, have a look at What are the semantics of different RxJS subjects? too), leading to the behaviour you observed.

In Rxjs 5, it uses a subject factory (something like multicast(() => new Rx.Suject().refCount())), so a subject is recreated when necessary.

See issues here and here for more details.

In short, if you can't do with the current behavior, you can switch to the v5 (note that it is still in beta and there are some breaking changes).

Post a Comment for "Reconnecting A Websocket With A Shared Rxjs Observable"