2020angular .module (' knalli.angular-vertxbus' )
2121.provider (' vertxEventBusService' , () ->
2222
23+ CONSTANTS =
24+ MODULE : ' angular-vertxbus'
25+ COMPONENT : ' service'
26+
2327 DEFAULT_OPTIONS =
2428 loginRequired : false
2529 loginBlockForSession : false # NYI
@@ -88,16 +92,19 @@ angular.module('knalli.angular-vertxbus')
8892 @ requireLogin = (value = options .loginRequired ) ->
8993 options .loginRequired = value
9094 return this
95+ @requireLogin .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : requireLogin"
9196
9297 # private: NYI
9398 @ blockForSession = (value = options .loginBlockForSession ) ->
9499 options .loginBlockForSession = value
95100 return this
101+ @blockForSession .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : blockForSession"
96102
97103 # private: NYI
98104 @ skipUnauthorizeds = (value = options .skipUnauthorizeds ) ->
99105 options .skipUnauthorizeds = value
100106 return this
107+ @skipUnauthorizeds .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : skipUnauthorizeds"
101108
102109 @ $get = ($rootScope , $q , $interval , $timeout , vertxEventBus ) ->
103110 # Extract options (with defaults)
@@ -131,6 +138,7 @@ angular.module('knalli.angular-vertxbus')
131138 vertxEventBus .onclose = ->
132139 wrapped .getConnectionState (true )
133140 $rootScope .$broadcast " #{ prefix} system.disconnected"
141+ vertxEventBus .onclose .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : 'onclose' handler"
134142
135143 ensureOpenConnection = (fn ) ->
136144 if wrapped .getConnectionState () is vertxEventBus .EventBus .OPEN
@@ -140,20 +148,24 @@ angular.module('knalli.angular-vertxbus')
140148 messageQueueHolder .push (fn)
141149 return true
142150 return false
151+ ensureOpenConnection .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : ensureOpenConnection"
143152
144153 ensureOpenAuthConnection = (fn ) ->
145154 unless options .loginRequired
146155 # easy: no login required
147156 ensureOpenConnection fn
148157 else
149- ensureOpenConnection ->
158+ wrapFn = ->
150159 if validSession
151160 fn ()
152161 return true
153162 else
154163 # ignore this message
155164 console .debug (" [VertX EB Service] Message was not sent because login is required" ) if debugEnabled
156165 return false
166+ wrapFn .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : ensureOpenAuthConnection function wrapper"
167+ ensureOpenConnection wrapFn
168+ ensureOpenAuthConnection .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : ensureOpenAuthConnection"
157169
158170 # All utility methods working directly on the event bus object.
159171 # The object "vertxEventBus" must be available.
@@ -163,10 +175,11 @@ angular.module('knalli.angular-vertxbus')
163175 return unless typeof callback is ' function'
164176 console .debug (" [VertX EB Service] Register handler for #{ address} " ) if debugEnabled
165177 return fnWrapperMap .get (callback) if fnWrapperMap .containsKey (callback) # already known
166- fnWrapperMap . put (callback, (message , replyTo ) ->
178+ deconstructor = (message , replyTo ) ->
167179 callback (message, replyTo)
168180 $rootScope .$digest ()
169- )
181+ deconstructor .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.registerHandler (deconstructor)"
182+ fnWrapperMap .put (callback, deconstructor)
170183 vertxEventBus .registerHandler address, fnWrapperMap .get (callback)
171184 # Remove a callback handler for the specified address match.
172185 unregisterHandler : (address , callback ) ->
@@ -181,36 +194,48 @@ angular.module('knalli.angular-vertxbus')
181194 # @param timeout an optional number for a timout after which the promise will be rejected
182195 send : (address , message , timeout = 10000 ) ->
183196 deferred = $q .defer ()
184- dispatched = ensureOpenAuthConnection ->
197+ next = ->
185198 vertxEventBus .send address, message, (reply ) ->
186199 if deferred then deferred .resolve reply
187200 # Register timeout for promise rejecting.
188201 if deferred then $timeout (-> deferred .reject ()), timeout
202+ next .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.send (ensureOpenAuthConnection callback)"
203+ dispatched = ensureOpenAuthConnection next
189204 if deferred and ! dispatched then deferred .reject ()
190205 return deferred ? .promise
191206 # Publish a message to the specified address (using EventBus.publish).
192207 # @param address a required string for the targeting address in the bus
193208 # @param message a required piece of message data
194209 publish : (address , message ) ->
195- dispatched = ensureOpenAuthConnection ->
210+ next = ->
196211 vertxEventBus .publish address, message
212+ next .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.publish (ensureOpenAuthConnection callback)"
213+ dispatched = ensureOpenAuthConnection next
197214 return dispatched
198215 # Send a login message
199216 # @param username
200217 # @param password
201218 # @param timeout
202219 login : (username , password , timeout = 5000 ) ->
203220 deferred = $q .defer ()
204- vertxEventBus . login username, password, (reply ) ->
221+ next = (reply ) ->
205222 if reply ? .status is ' ok'
206223 deferred .resolve reply
207224 $rootScope .$broadcast " #{ prefix} system.login.succeeded" , (status : reply ? .status )
208225 else
209226 deferred .reject reply
210227 $rootScope .$broadcast " #{ prefix} system.login.failed" , (status : reply ? .status )
228+ next .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.login (callback)"
229+ vertxEventBus .login username, password, next
211230 $timeout (-> deferred .reject ()), timeout
212231 return deferred .promise
213232
233+ util .registerHandler .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.registerHandler"
234+ util .unregisterHandler .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.unregisterHandler"
235+ util .send .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.send"
236+ util .publish .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.publish"
237+ util .login .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : util.login"
238+
214239 # Wrapping methods for the api
215240 wrapped =
216241 # Store of all handlers using as a cache when the event bus is not online
@@ -266,8 +291,18 @@ angular.module('knalli.angular-vertxbus')
266291 validSession = false
267292 return reply
268293
294+ wrapped .registerHandler .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.registerHandler"
295+ wrapped .unregisterHandler .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.unregisterHandler"
296+ wrapped .send .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.send"
297+ wrapped .publish .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.publish"
298+ wrapped .getConnectionState .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.getConnectionState"
299+ wrapped .isValidSession .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.isValidSession"
300+ wrapped .login .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : wrapped.login"
301+
269302 # Update the current connection state periodially.
270- $interval (-> wrapped .getConnectionState (true )), sockjsStateInterval
303+ connectionIntervalCheck = -> wrapped .getConnectionState (true )
304+ connectionIntervalCheck .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : periodic connection check"
305+ $interval connectionIntervalCheck, sockjsStateInterval
271306
272307 ### building and exposing the actual service API ###
273308 return (
@@ -284,6 +319,7 @@ angular.module('knalli.angular-vertxbus')
284319 isValidSession : -> validSession
285320 login : wrapped .login
286321 )
322+ @$get .displayName = " #{ CONSTANTS .MODULE } /#{ CONSTANTS .COMPONENT } : initializer"
287323
288324 return # void
289325)
0 commit comments