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