I have multiple SignalR \'services\' running and only one UI to access them.
How can I make the client js to talk to multiple connections with different Url? Because
My solution for such occasions:
var SignalRHelpers = function () {
var _connectionDeferred;
var subscribeToConnectionStart = function (callback) {
if (!_connectionDeferred) // start connection if not yet initialized
_connectionDeferred = $.connection.hub.start();
if ($.connection.hub.state == $.connection.connectionState.connected && callback) {
// already connected
callback();
} else if (callback) {
// register handler
_connectionDeferred.done(callback);
}
};
return {
SubscribeToConnectionStart: subscribeToConnectionStart
};
}();
It internally stores the promise object from start() and attaches handlers as needed.
Basically you just call SignalRHelpers.SubscribeToConnectionStart every time you need to connect. For example
SignalRHelpers.SubscribeToConnectionStart(function(){
someHub.server.executeSomething();
});