(function () { 'use strict'; //service that allows the server to notify the client of specific events using SignalR var serviceId = 'notifier'; angular.module('app').factory(serviceId, ['Hub', 'common', '$rootScope', 'userAuth', 'config', notifier]); function notifier(Hub, common, $rootScope, userAuth, config) { var service = { start: start }; return service; function start() { var tokenData = userAuth.getAuthToken(); if (tokenData) { //SignalR Hub setup var hub1 = new Hub('notifier', { //these functions are effectively called from the server listeners: { 'notificationsChanged': function (numberNotifications) { common.logger.logSuccess("Notification added", null, true); $rootScope.$broadcast('UpdateNotifications', { notificationsNum: numberNotifications }); } }, errorHandler: function (error) { console.error(error); }, rootPath: config.myShowcaseSiteUrl, useJsonP:true, queryParams: { bearer: tokenData.access_token } //send the bearer token with every SignalR request }); } } } })();