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

Commit 90bf569

Browse files
committed
Merge branch 'canary'
2 parents a69dc7c + 0b79b3f commit 90bf569

File tree

10 files changed

+163
-25
lines changed

10 files changed

+163
-25
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
language: node_js
22
node_js:
3-
- "0.10"
3+
- "0.12"
44

55
addons:
66
code_climate:
77
repo_token: 94ea5ac76984c311dcbadb53a52dd219400775e20402587a0063d8b9d3a66bca
88

99
before_install:
10+
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@1.4.28'
11+
- npm install -g npm@latest
1012
- npm install -g grunt-cli codeclimate-test-reporter
1113

1214
before_script:
@@ -20,3 +22,4 @@ env:
2022
- TEST_SCOPE=
2123
- TEST_SCOPE=angular_1.2.x
2224
- TEST_SCOPE=angular_1.3.x
25+
- TEST_SCOPE=angular_1.4.x

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ If you have a standard non AMD styled project, use `dist/angular-vertxbus.js` or
2020

2121
In case of an AMD styled project, there is also a package available at `dist/requirejs/angular-vertxbus.js`. In addition, because of the lack of vertxbus package, there is a Vert.X Event Bus package at `dist/requirejs/vertxbus.js` which includes the version of the Event Bus defined in the `bower.json`.
2222

23+
Alternatively you can use the cdnjs: [cdnjs.com/libraries/angular-vertxbus](https://cdnjs.com/libraries/angular-vertxbus).
24+
2325
## How to use
2426

2527
You have to define the module dependency, this module is named `knalli.angular-vertxbus`.
@@ -185,4 +187,4 @@ The *end-to-end tests* start and utilize a full Vert.X node and a NodeJS based w
185187

186188
## License
187189

188-
Copyright 2014 by Jan Philipp. Licensed under MIT.
190+
Copyright 2015 by Jan Philipp. Licensed under MIT.

bower.json

Lines changed: 2 additions & 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": "1.0.0",
5+
"version": "1.1.0",
66
"homepage": "http://github.com/knalli/angular-vertxbus",
77
"main": "./dist/angular-vertxbus.js",
88
"keywords": ["angular", "vertx", "facade", "websocket"],
@@ -11,6 +11,7 @@
1111
".jshintrc",
1212
".travis.yml",
1313
"karma.conf.js",
14+
"/build-data-for-requirejs/",
1415
"/temp/",
1516
"/test/",
1617
"/test_scopes/",

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": "1.0.0",
3+
"version": "1.1.0",
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: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,18 @@ angular.module('knalli.angular-vertxbus')
217217
# Send a message to the specified address (using EventBus.send).
218218
# @param address a required string for the targeting address in the bus
219219
# @param message a required piece of message data
220-
# @param timeout an optional number for a timout after which the promise will be rejected
221-
send : (address, message, timeout = 10000) ->
220+
# @param timeout an optional number for a timeout after which the promise will be rejected
221+
# @param expectReply boolean specifying whether a replyHandler should be created or not
222+
send : (address, message, timeout = 10000, expectReply = yes) ->
222223
deferred = $q.defer()
223224
next = ->
224-
vertxEventBus.send address, message, (reply) ->
225-
if deferred then deferred.resolve reply
226-
# Register timeout for promise rejecting.
227-
if deferred then $interval (-> deferred.reject()), timeout, 1
225+
if expectReply
226+
vertxEventBus.send(address, message, (reply) -> deferred.resolve(reply))
227+
# Register timeout for promise rejecting.
228+
$interval (-> deferred.reject()), timeout, 1
229+
else
230+
vertxEventBus.send(address, message)
231+
deferred.resolve()
228232
next.displayName = "#{CONSTANTS.MODULE}/#{CONSTANTS.COMPONENT}: util.send (ensureOpenAuthConnection callback)"
229233
dispatched = ensureOpenAuthConnection next
230234
if deferred and !dispatched then deferred.reject()
@@ -297,8 +301,8 @@ angular.module('knalli.angular-vertxbus')
297301
# Remove from real instance
298302
if connectionState is vertxEventBus.EventBus.OPEN then util.unregisterHandler(address, callback)
299303
# Stub for util.send
300-
send : (address, message, timeout = 10000) ->
301-
util.send(address, message, timeout)
304+
send : (address, message, timeout = 10000, expectReply = yes) ->
305+
util.send(address, message, timeout, expectReply)
302306
# Stub for util.publish
303307
publish : (address, message) ->
304308
util.publish(address, message)

src/wrapper.coffee

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,35 @@ angular.module('knalli.angular-vertxbus')
115115
# Because we have rebuild an EventBus object (because it have to rebuild a SockJS object)
116116
# we must wrap the object. Therefore, we have to mimic the behavior of onopen and onclose each time.
117117
eventBus = null
118+
disconnectTimeoutEnabled = yes
119+
118120
connect = ->
119121
eventBus = new EventBusOriginal url, undefined, sockjsOptions
120122
eventBus.onopen = ->
121123
$log.debug("[Vert.x EB Stub] Connected") if debugEnabled
122124
EventBusStub.onopen() if typeof EventBusStub.onopen is 'function'
123125
return #void
124126
eventBus.onclose = ->
125-
$log.debug("[Vert.x EB Stub] Reconnect in #{sockjsReconnectInterval}ms") if debugEnabled
126127
EventBusStub.onclose() if typeof EventBusStub.onclose is 'function'
127-
$timeout(connect, sockjsReconnectInterval) if reconnectEnabled
128+
unless disconnectTimeoutEnabled
129+
$log.debug("[Vert.x EB Stub] Reconnect immediately") if debugEnabled
130+
disconnectTimeoutEnabled = yes
131+
connect()
132+
else
133+
if reconnectEnabled
134+
$log.debug("[Vert.x EB Stub] Reconnect in #{sockjsReconnectInterval}ms") if debugEnabled
135+
$timeout(connect, sockjsReconnectInterval)
128136
return #void
129137
return #void
130138
connect()
131139

132140
EventBusStub =
133-
reconnect: ->
134-
eventBus.close()
141+
reconnect: (immediately = no) ->
142+
if eventBus.readyState() is EventBusStub.EventBus.OPEN
143+
disconnectTimeoutEnabled = no if immediately
144+
eventBus.close()
145+
else
146+
connect()
135147
close: ->
136148
eventBus.close()
137149
login: (username, password, replyHandler) ->

test/unit/angularVertxbusAdapterSpec.js

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ describe('knalli.angular-vertxbus', function () {
55

66
beforeEach(module('knalli.angular-vertxbus'));
77

8+
beforeEach(module('knalli.angular-vertxbus', function($provide) {
9+
$provide.value('$log', window.console);
10+
}));
11+
812
it('should have vertxEventBus', function () {
913
inject(function (vertxEventBus) {
1014
expect(vertxEventBus).not.to.be(undefined);
@@ -112,6 +116,29 @@ describe('knalli.angular-vertxbus', function () {
112116
});
113117
});
114118

119+
describe('reconnect(true)', function () {
120+
it('should call the onclose and onopen function if previously connected', function (done) {
121+
this.timeout(20000);
122+
var onopenCount = 0;
123+
vertxEventBus.onopen = function () {
124+
onopenCount++;
125+
};
126+
var oncloseCount = 0;
127+
vertxEventBus.onclose = function () {
128+
oncloseCount++;
129+
};
130+
setTimeout(function () {
131+
expect(onopenCount, 'onopenCount').to.be(1);
132+
vertxEventBus.reconnect(true);
133+
setTimeout(function () {
134+
expect(oncloseCount).to.be(1);
135+
expect(onopenCount).to.be(2);
136+
done();
137+
}, 1200);
138+
}, 200);
139+
});
140+
});
141+
115142
describe('after adding a handler via "registerHandler"', function () {
116143
it('should be called', function (done) {
117144
var abcCalled, xyzCalled;
@@ -201,6 +228,51 @@ describe('knalli.angular-vertxbus', function () {
201228
});
202229

203230

231+
describe('vertxEventBus without reconnect', function () {
232+
233+
var vertxEventBus, $timeout, $rootScope, $log;
234+
235+
beforeEach(module('knalli.angular-vertxbus', function (vertxEventBusProvider) {
236+
// Override (improve test running time)
237+
vertxEventBusProvider.useDebug(true).useSockJsReconnectInterval(2000).useReconnect(false);
238+
}));
239+
240+
beforeEach(inject(function (_vertxEventBus_, _$timeout_, _$rootScope_, _$log_) {
241+
vertxEventBus = _vertxEventBus_;
242+
$timeout = _$timeout_;
243+
$rootScope = _$rootScope_;
244+
$log = _$log_;
245+
SockJS.currentMockInstance.$log = $log;
246+
}));
247+
248+
it('should call the onopen function if not previously connected', function (done) {
249+
this.timeout(20000);
250+
var onopenCount = 0;
251+
vertxEventBus.onopen = function () {
252+
$log.debug('onopen');
253+
onopenCount++;
254+
};
255+
var oncloseCount = 0;
256+
vertxEventBus.onclose = function () {
257+
$log.debug('onclose');
258+
oncloseCount++;
259+
};
260+
setTimeout(function () {
261+
expect(onopenCount).to.be(1);
262+
$log.debug('reconnecting..');
263+
vertxEventBus.close();
264+
vertxEventBus.reconnect(true);
265+
setTimeout(function () {
266+
$log.debug('check..');
267+
expect(oncloseCount).to.be(1);
268+
expect(onopenCount).to.be(2);
269+
done();
270+
}, 1200);
271+
}, 200);
272+
});
273+
274+
});
275+
204276
describe('vertxEventBusService', function () {
205277

206278
var vertxEventBusService;
@@ -523,21 +595,25 @@ describe('knalli.angular-vertxbus', function () {
523595
});
524596
});
525597

526-
describe('when the service is not connected', function () {
527-
var vertxEventBus, vertxEventBusService, $timeout;
598+
describe('when the service is not connected correctly (stallec connection)', function () {
599+
var $rootScope, vertxEventBus, vertxEventBusService, $timeout;
528600

529601
beforeEach(module('knalli.angular-vertxbus', function (vertxEventBusProvider) {
530602
vertxEventBusProvider.useMessageBuffer(0);
531603
}));
532604

533-
beforeEach(inject(function (_vertxEventBus_, _vertxEventBusService_, _$timeout_) {
605+
beforeEach(inject(function (_$rootScope_, _vertxEventBus_, _vertxEventBusService_, _$timeout_) {
606+
$rootScope = _$rootScope_;
534607
$timeout = _$timeout_;
535608
vertxEventBus = _vertxEventBus_;
536609
vertxEventBusService = _vertxEventBusService_;
537-
// Mock bus is closed
610+
// Mock bus is opened (said to be)
538611
_vertxEventBus_.readyState = function () {
539612
return _vertxEventBus_.EventBus.OPEN;
540613
};
614+
_vertxEventBusService_.getConnectionState = function () {
615+
return true;
616+
};
541617
var sendCalls = 0;
542618
_vertxEventBus_.send = function () {
543619
// do nothing, let it timeout
@@ -560,11 +636,12 @@ describe('knalli.angular-vertxbus', function () {
560636
var successCalled, errorCalled;
561637
setTimeout(function () {
562638
// very short timeout: 10
563-
vertxEventBusService.send('xyz', {data: 1}, true, 10).then(function () {
639+
vertxEventBusService.send('xyz', {data: 1}, 10).then(function () {
564640
successCalled = true;
565641
}, function () {
566642
errorCalled = true;
567643
});
644+
$rootScope.$apply();
568645
setTimeout(function () {
569646
$interval.flush(20); // goto T+20
570647
expect(successCalled).to.be(undefined);
@@ -574,6 +651,25 @@ describe('knalli.angular-vertxbus', function () {
574651
}, 200);
575652
});
576653

654+
it('via promise.then() without expecting reply', function (done) {
655+
var successCalled, errorCalled;
656+
setTimeout(function () {
657+
// very short timeout: 10
658+
vertxEventBusService.send('xyz', {data: 1}, 10, false).then(function () {
659+
successCalled = true;
660+
}, function () {
661+
errorCalled = true;
662+
});
663+
$rootScope.$apply();
664+
setTimeout(function () {
665+
$interval.flush(20); // goto T+20
666+
expect(successCalled).to.be(true);
667+
expect(errorCalled).to.be(undefined);
668+
done();
669+
}, 300);
670+
}, 200);
671+
});
672+
577673
it('via promise.catch()', function (done) {
578674
var successCalled, errorCalled;
579675
setTimeout(function () {
@@ -583,6 +679,7 @@ describe('knalli.angular-vertxbus', function () {
583679
})['catch'](function () {
584680
errorCalled = true;
585681
});
682+
$rootScope.$apply();
586683
setTimeout(function () {
587684
$interval.flush(20); // goto T+20
588685
expect(successCalled).to.be(undefined);

test_scopes/angular_1.2.x/bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"url": "git://github.com/knalli/angular-vertxbus"
1010
},
1111
"dependencies": {
12-
"angular": "~1.2.0",
12+
"angular": "^1.2.0",
1313
"sockjs-client": "~0.3.4",
1414
"vertxbus.js": "http://cdnjs.cloudflare.com/ajax/libs/vertx/2.0.0/vertxbus.js"
1515
},
1616
"devDependencies": {
17-
"angular-mocks": "~1.2.3"
17+
"angular-mocks": "^1.2.0"
1818
}
1919
}

test_scopes/angular_1.3.x/bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"url": "git://github.com/knalli/angular-vertxbus"
1010
},
1111
"dependencies": {
12-
"angular": "~1.3.0",
12+
"angular": "^1.3.0",
1313
"sockjs-client": "~0.3.4",
1414
"vertxbus.js": "http://cdnjs.cloudflare.com/ajax/libs/vertx/2.0.0/vertxbus.js"
1515
},
1616
"devDependencies": {
17-
"angular-mocks": "~1.3.0"
17+
"angular-mocks": "^1.3.0"
1818
}
1919
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"author": "Jan Philipp",
3+
"name": "angular-vertxbus",
4+
"description": "",
5+
"version": "0.0.0",
6+
"homepage": "http://github.com/knalli/angular-vertxbus",
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/knalli/angular-vertxbus"
10+
},
11+
"dependencies": {
12+
"angular": "^1.4.0-beta.5",
13+
"sockjs-client": "~0.3.4",
14+
"vertxbus.js": "http://cdnjs.cloudflare.com/ajax/libs/vertx/2.0.0/vertxbus.js"
15+
},
16+
"devDependencies": {
17+
"angular-mocks": "^1.4.0-beta.5"
18+
}
19+
}

0 commit comments

Comments
 (0)