daniel daniel - 1 year ago 267
Javascript Question

Signalr check if hub already started

I have multiple javascript blocks with signalR functions.

I don't know the order of execution so that i want to start the hub with


if it isn't started already.

How can i check if the hub is already started? Starting it multiple times it it throws an error.

Answer Source

You can detect when the hub has started using .done()

$.connection.hub.start().done(function () {

using this method, you can do the following (Taken from docs : https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client-Hubs) you can then keep track of if the connection is open yourself.

function connectionReady() {
    alert("Done calling first hub serverside-function");

                .done(function() {
                    myHub.server.SomeFunction(SomeParam) //e.g. a login or init
                .fail(function() {
                    alert("Could not Connect!");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download