omar foudhaili
omar foudhaili

Reputation: 67

Signal r client reconnection with the same connection Id

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.

Upvotes: 0

Views: 1870

Answers (1)

Kiril1512
Kiril1512

Reputation: 3611

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.

Upvotes: 1

Related Questions