Signal r client reconnection with the same connection Id

1.5k views Asked by At

i have a signalig issue in my app, im workin with signar R, some times my app lose the connection so and i try to reconnect. the problem is that i need to reconnect with my first connection id , but the server return another id for my new connection. this is my code

this.hubConnection.onclose(async () => {
  console.log(' Restart connection after 5 seconds.')
  setTimeout(async () => {
    await this.hubConnection
      .start();
  }, 5000); // Restart connection after 5 seconds.

});

i want to have another session with my first connection Id , any help please.

1

There are 1 answers

2
Kiril1512 On

You can read more about the connection lifetime and as you can see, when your connection is dropped, you are starting a new connection, you are not reconnecting here.

What you can try is using the .withAutomaticReconnect(), so if connection is closed not by the user, it will try reconnect but not with the same connectionId. This method is avaliable in the @microsoft/signalr package.