Skip to content
This repository was archived by the owner on Jun 14, 2019. It is now read-only.

Commit 8732351

Browse files
committed
Merge branch 'canary' as 0.11.1
2 parents 0a48288 + 501f738 commit 8732351

File tree

5 files changed

+66
-13
lines changed

5 files changed

+66
-13
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Jan Philipp",
33
"name": "angular-vertxbus",
44
"description": "AngularJS facade and service acting as a Vert.x SockJS client",
5-
"version": "0.11.0",
5+
"version": "0.11.1",
66
"homepage": "http://github.com/knalli/angular-vertxbus",
77
"main": "./dist/angular-vertxbus.js",
88
"keywords": ["angular", "vertx", "facade", "websocket"],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-vertxbus",
3-
"version": "0.11.0",
3+
"version": "0.11.1",
44
"description": "AngularJS facade and service acting as a Vert.x SockJS client",
55
"main": "dist/angular-vertxbus.js",
66
"keywords": ["angular", "vertx", "facade", "websocket"],

src/service.coffee

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ angular.module('knalli.angular-vertxbus')
137137
loginPromise = null
138138
# internal store of buffered messages
139139
messageQueue = new Queue(messageBuffer)
140-
# internal map of deconstructors
141-
deconstructors = new SimpleMap()
140+
# internal map of callbacks
141+
callbackMap = new SimpleMap()
142142

143143
if enabled and vertxEventBus
144144
vertxEventBus.onopen = ->
@@ -194,20 +194,19 @@ angular.module('knalli.angular-vertxbus')
194194
registerHandler : (address, callback) ->
195195
return unless typeof callback is 'function'
196196
$log.debug("[Vert.x EB Service] Register handler for #{address}") if debugEnabled
197-
return deconstructors.get(callback) if deconstructors.containsKey(callback) # already known
198-
deconstructor = (message, replyTo) ->
197+
callbackWrapper = (message, replyTo) ->
199198
callback(message, replyTo)
200199
$rootScope.$digest()
201200
return #void
202-
deconstructor.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: util.registerHandler (deconstructor)"
203-
deconstructors.put(callback, deconstructor)
204-
vertxEventBus.registerHandler address, deconstructors.get(callback)
201+
callbackWrapper.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: util.registerHandler (callback wrapper)"
202+
callbackMap.put(callback, callbackWrapper)
203+
vertxEventBus.registerHandler address, callbackWrapper
205204
# Remove a callback handler for the specified address match.
206205
unregisterHandler : (address, callback) ->
207206
return unless typeof callback is 'function'
208207
$log.debug("[Vert.x EB Service] Unregister handler for #{address}") if debugEnabled
209-
vertxEventBus.unregisterHandler address, deconstructors.get(callback)
210-
deconstructors.remove(callback)
208+
vertxEventBus.unregisterHandler address, callbackMap.get(callback)
209+
callbackMap.remove(callback)
211210
return #void
212211
# Send a message to the specified address (using EventBus.send).
213212
# @param address a required string for the targeting address in the bus

test/unit/angularVertxbusAdapterSpec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,60 @@ describe('knalli.angular-vertxbus', function () {
590590

591591
});
592592

593+
describe('reconnect', function () {
594+
var $timeout, vertxEventBus, vertxEventBusService;
595+
beforeEach(inject(function (_vertxEventBus_, _vertxEventBusService_, _$timeout_) {
596+
$timeout = _$timeout_;
597+
vertxEventBus = _vertxEventBus_;
598+
vertxEventBusService = _vertxEventBusService_;
599+
// Mock bus is closed
600+
_vertxEventBus_.readyState = function () {
601+
return _vertxEventBus_.EventBus.OPEN;
602+
};
603+
var sendCalls = 0;
604+
_vertxEventBus_.send = function () {
605+
// do nothing, let it timeout
606+
};
607+
// extend object
608+
vertxEventBus.getSendCalls = function () {
609+
return sendCalls;
610+
};
611+
}));
612+
it('should be a function', function () {
613+
expect(typeof vertxEventBus.reconnect).to.be('function');
614+
});
615+
// Reconnect should be switch the connectivity, onopen() and onclose()
616+
// must be delegated transparently
617+
it('should re-add handler after a reconnet', function (done) {
618+
this.timeout(20000);
619+
var okHandler = false;
620+
var myHandler = function () {
621+
//$log.debug('[TEST] onhandle() called');
622+
okHandler = true;
623+
};
624+
625+
setTimeout(function () {
626+
vertxEventBusService.addListener('lalelu', myHandler);
627+
vertxEventBus.reconnect();
628+
setTimeout(function () {
629+
setTimeout(function () {
630+
SockJS.currentMockInstance.onmessage({
631+
data: JSON.stringify({
632+
address: 'lalelu',
633+
body: {
634+
data: '1x'
635+
},
636+
replyAddress: undefined
637+
})
638+
});
639+
expect(okHandler).to.be(true);
640+
done();
641+
}, 2100);
642+
$timeout.flush();
643+
}, 100);
644+
}, 100);
645+
});
646+
});
593647

594648
describe('after adding and removing a handler via "registerHandler"', function () {
595649

test/unit/mock/sockjs.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class SockJS
2222
else
2323
window.setTimeout fn, 1
2424

25-
log: ->
25+
log: (args...)->
2626
log = SockJS.currentMockInstance?.$log or window.console
27-
log.debug.apply(this, arguments)
27+
log.debug(args...)
2828

2929
close: (mockOptions)->
3030
@log "[MOCK] SockJS.close()"

0 commit comments

Comments
 (0)