Odonno / ngrx-signalr-core

A library to handle realtime SignalR (.NET Core) events using @angular, rxjs and the @ngrx library
https://www.npmjs.com/package/ngrx-signalr-core
MIT License
27 stars 13 forks source link

Cannot Stop Hub When Using createReconnectEffect helper #19

Closed mccow002 closed 3 years ago

mccow002 commented 3 years ago

Currently, if you're using the createReconnectEffect helper method to handle disconnect events, you cannot stop the hub. Sending the stop event will stop the hub, but then the disconnect action will trigger this effect and reconnect.

The createReconnectEffect is also not hub specific. If you set if up for one hub, it will try to reconnect any hub that get disconnected, whether it's disconnected intentionally or not.

Proposed fix: Add the hub parameter to the createReconnectEffect helper method, and add the following to the createReconnectEffect effect:

this.actions$.pipe(
      ofType(signalrDisconnected),
      ofHub(this.checksheetHub),
      takeUntil(this.actions$.pipe(
        ofType(stopSignalRHub),
        ofHub(this.checksheetHub)
      )),
    ...
Odonno commented 3 years ago

Well, I wanted something to be handle global reconnection. But now I created an options object with a hubName props. if provided, it will filter inside the effect and it will only apply reconnection on the hub you choosed.

About the reconnection even when the hub was stopped. I never thought about that, I also added a takeUntil like you suggested.

You will see the v8.3.0 really soon. Tell me if you need anything.