/** * Created by robin on 12/11/16. */ (function () { 'use strict'; angular.module('luticate2Utils') .factory('luNotificationsDataAccess', ['Hub', function(Hub) { var luNotificationsDataAccess = {}; luNotificationsDataAccess.hub = null; luNotificationsDataAccess.callbacks = {}; luNotificationsDataAccess.addCallback = function (eventName, entityType, callback) { if (luNotificationsDataAccess.callbacks[eventName] == null) { luNotificationsDataAccess.callbacks[eventName] = {}; } var event = luNotificationsDataAccess.callbacks[eventName]; if (event[entityType] == null) { event[entityType] = []; } event[entityType].push(callback); }; luNotificationsDataAccess.init = function () { luNotificationsDataAccess.hub = new Hub('luNotificationsHub', { //client side methods listeners:{ 'notify': function (eventName, entityType, oldEntity, newEntity) { var event = luNotificationsDataAccess.callbacks[eventName]; if (event != null) { var type = event[entityType]; if (type != null) { for (var i = 0; i < type.length; ++i) { type[i](eventName, entityType, oldEntity, newEntity); } } } } }, //server side methods methods: [], //query params sent on initial connection queryParams:{ }, //handle connection error errorHandler: function(error){ console.error(error); }, //specify a non default root // rootPath: 'http://127.0.0.1:8080/signalr/', stateChanged: function(state){ switch (state.newState) { case $.signalR.connectionState.connecting: //your code here break; case $.signalR.connectionState.connected: //your code here break; case $.signalR.connectionState.reconnecting: //your code here break; case $.signalR.connectionState.disconnected: //your code here break; } } }); }; return luNotificationsDataAccess; }]); })();