I think I have a more elegant solution.
Service
app.factory("signalrFactory", function ($rootScope, $http, $timeout) {
var factory = {};
factory.connection = $.connection;
var startDoneFunctions = [];
var debounce;
factory.start = function (done) {
factory.connection.hub.stop();
if (done) {
if (startDoneFunctions.indexOf(done) == -1) {
startDoneFunctions.push(done);
}
}
if (debounce) $timeout.cancel(debounce);
debounce = $timeout(function () {
factory.connection.hub.start().done(function () {
for (var x = 0; x < startDoneFunctions.length; x++) {
startDoneFunctions[x]();
}
});
}, 100);
};
return factory;
});
Use
controller('customerSummary', function ($scope, signalrFactory) {
$scope.customerHub = signalrFactory.connection.customerHub;
$scope.customer;
$scope.beingEditedText = "";
$scope.customerHub.client.beingEdited = function (text) {
$scope.beingEditedText = text;
};
$scope.customerHub.client.doneEditing = function () {
$scope.beingEditedText = "";
};
$scope.customerHub.client.updateCustomer = function (customer) {
$scope.customer = customer;
$scope.$apply();
};
$scope.init = function (id) {
signalrFactory.start(function () {
$scope.customerHub.server.getCustomer(id);
});
};
});
What this way allows is to add when needed and not having to add each hub at bootstrap. I am now able to have different done() methods from anywhere.