Signalr check if hub already started

后端 未结 3 890
甜味超标
甜味超标 2020-12-14 06:50

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

$.connection.hub.st

3条回答
  •  我在风中等你
    2020-12-14 07:20

    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");
    };
    
    $.connection.hub.start()
                    .done(function() {
                        myHub.server.SomeFunction(SomeParam) //e.g. a login or init
                             .done(connectionReady); 
                    })
                    .fail(function() {
                        alert("Could not Connect!");
                     });
    

提交回复
热议问题