You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lu-notifications-dataaccess.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Created by robin on 12/11/16.
  3. */
  4. (function () {
  5. 'use strict';
  6. angular.module('luticate2Utils')
  7. .factory('luNotificationsDataAccess', ['Hub', function(Hub) {
  8. var luNotificationsDataAccess = {};
  9. luNotificationsDataAccess.hub = null;
  10. luNotificationsDataAccess.callbacks = {};
  11. luNotificationsDataAccess.addCallback = function (eventName, entityType, callback) {
  12. if (luNotificationsDataAccess.callbacks[eventName] == null) {
  13. luNotificationsDataAccess.callbacks[eventName] = {};
  14. }
  15. var event = luNotificationsDataAccess.callbacks[eventName];
  16. if (event[entityType] == null) {
  17. event[entityType] = [];
  18. }
  19. event[entityType].push(callback);
  20. };
  21. luNotificationsDataAccess.init = function () {
  22. luNotificationsDataAccess.hub = new Hub('luNotificationsHub', {
  23. //client side methods
  24. listeners:{
  25. 'notify': function (eventName, entityType, oldEntity, newEntity) {
  26. var event = luNotificationsDataAccess.callbacks[eventName];
  27. if (event != null) {
  28. var type = event[entityType];
  29. if (type != null) {
  30. for (var i = 0; i < type.length; ++i) {
  31. type[i](eventName, entityType, oldEntity, newEntity);
  32. }
  33. }
  34. }
  35. }
  36. },
  37. //server side methods
  38. methods: [],
  39. //query params sent on initial connection
  40. queryParams:{
  41. },
  42. //handle connection error
  43. errorHandler: function(error){
  44. console.error(error);
  45. },
  46. //specify a non default root
  47. // rootPath: 'http://127.0.0.1:8080/signalr/',
  48. stateChanged: function(state){
  49. switch (state.newState) {
  50. case $.signalR.connectionState.connecting:
  51. //your code here
  52. break;
  53. case $.signalR.connectionState.connected:
  54. //your code here
  55. break;
  56. case $.signalR.connectionState.reconnecting:
  57. //your code here
  58. break;
  59. case $.signalR.connectionState.disconnected:
  60. //your code here
  61. break;
  62. }
  63. }
  64. });
  65. };
  66. return luNotificationsDataAccess;
  67. }]);
  68. })();