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

Autoreconnect feature #61

Open
Gniarke opened this issue Sep 10, 2020 · 1 comment
Open

Autoreconnect feature #61

Gniarke opened this issue Sep 10, 2020 · 1 comment

Comments

@Gniarke
Copy link

Gniarke commented Sep 10, 2020

Hi,

possible to have the equivalent of js signalr client "@microsoft/signalr" autoreconnect feature ?
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub")
.withAutomaticReconnect()
.build();
I didn't find any disconnect catcher, so after a while, when connection is lost, i can't do anything to reconnect the user.

@jamesdward
Copy link

jamesdward commented Oct 16, 2020

Hi @Gniarke

I'd advise looking at the actual SignalR docs

Although a disconnect method isn't mentioned in the react-native-signalr documentation (only on 'connectionSlow'), as it mainly acts as a bridge between react native and jQuery signalR, the other methods also work such as on 'disconnected' and on 'stateChanged' e.g:

connection.disconnected(() => {  
     //connection was fully disconnected   
    });

connection.stateChanged((state) => {
   // Detects any stage change 
   // state = {oldState, newState}
  });

Also a very useful tip - you can access the connection state at any time through connection.state.
Status code 1: Connected
Status code 2: Reconnecting
Status code 4: Disconnected

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

2 participants