1

Im trying to use State of hub connectivity to avoid multiple connect per tab. what ive done

so far :

   var connection = $.hubConnection("/signalr", { useDefaultPath: false });
    connection.client = function () { };
    var hub = connection.createHubProxy("NotificationHub");
    hub.on("AddMessage", Method);
    if (hub && hub.state === $.signalR.connectionState.disconnected) {
        connection.start({ jsonp: true })
            .done(function () {
                hub.invoke("FakeLiveState");

                hub.invoke('ConnectionConnectedSaveDB', controllerNameSignalR).done(function () {
                }).fail(function (error) {

                });

            })
            .fail(function (a) {
            });
        connection.disconnected(function () {
            setTimeout(function () {
                connection.start({ jsonp: true })
                    .done(function () {
                        hub.invoke('ConnectionConnectedSaveDB', controllerNameSignalR).done(function () {

                        }).fail(function (error) {
                        });

                    })
                    .fail(function (a) {
                    });;
            }, 5000);
        });
    }

but result of hub.state isnt the number that mentioned in documentation :

https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client

stateChanged: Raised when the connection state changes. Provides the old state and the new state (Connecting, Connected, Reconnecting, or Disconnected).

the hub.state :

enter image description here

Ahad Porkar
  • 1,666
  • 2
  • 33
  • 68

0 Answers0