DoStuffWithUmbraco icon indicating copy to clipboard operation
DoStuffWithUmbraco copied to clipboard

connection id undefined

Open skartknet opened this issue 5 years ago • 0 comments

Hey Kevin, first thank you for this great repo. There's lot of good stuff in here ;)

I have been using the SignalR hub and I was having issues getting the client IDas it was undefined.

My code looked like this:

signalRHub.initHub(hubCallbacks);

    function hubCallbacks(hub) {
        hub.start();

        var id = hub.clientId; //this id is always undefined
    }

To make it work I had to return the call to the start method in the hub:

start: function () {

                    if ($.connection.hub.state !== $.connection.connectionState.disconnected) {                
                        $.connection.hub.stop(true, true)
                    }
                    return $.connection.hub.start(); //returns the promise here
                }

So then I could use it like this:

  hub.start().done(function () {
            clientId = $.connection.hub.id; //this clientId is correct
        });

skartknet avatar Sep 10 '20 23:09 skartknet