SignalR State is object when hub used in proxy mode

200 Views Asked by At

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

0

There are 0 best solutions below