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

Commit 4c8ed1e

Browse files
committed
Merge branch 'canary'
2 parents 5eea282 + c849101 commit 4c8ed1e

File tree

10 files changed

+168
-15
lines changed

10 files changed

+168
-15
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1
1+
4.2

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "4.1"
4+
- "4.2"
55

66
addons:
77
code_climate:

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = function (grunt) {
4545
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
4646
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
4747
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
48-
' Licensed <%= _.pluck(pkg.licenses, "name").join(", ") %> */'
48+
' Licensed <%= pkg.license %> */'
4949
},
5050
clean : {
5151
dist : 'dist/',
@@ -172,7 +172,7 @@ module.exports = function (grunt) {
172172
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
173173
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
174174
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
175-
' Licensed <%= _.pluck(pkg.licenses, "name").join(", ") %> */\n'
175+
' Licensed <%= pkg.license %> */\n'
176176
},
177177
'dist-withPolyfill' : {
178178
src : [

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": "3.0.2",
5+
"version": "3.1.0",
66
"homepage": "http://github.com/knalli/angular-vertxbus",
77
"main": "./dist/angular-vertxbus.js",
88
"keywords": [

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-vertxbus",
3-
"version": "3.0.2",
3+
"version": "3.1.0",
44
"description": "AngularJS facade and service acting as a Vert.x SockJS client",
55
"main": "dist/angular-vertxbus.js",
66
"keywords": [
@@ -56,9 +56,9 @@
5656
"grunt-karma": "^0.12.1",
5757
"grunt-ngdocs": "^0.2.9",
5858
"gruntify-eslint": "^1.1.0",
59-
"istanbul": "^0.3.22",
59+
"istanbul": "^0.4.0",
6060
"jasmine-core": "^2.3.4",
61-
"karma": "^0.13.9",
61+
"karma": "^0.13.11",
6262
"karma-babel-preprocessor": "^5.2.2",
6363
"karma-browserify": "^4.3.0",
6464
"karma-chrome-launcher": "^0.2.1",

src/lib/VertxEventBusWrapperProvider.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import EventBusAdapter from './adapter/EventBusAdapter';
22
import NoopAdapter from './adapter/NoopAdapter';
3+
import ConnectionConfigHolder from './support/ConnectionConfigHolder';
34

45
/**
56
* @ngdoc service
@@ -12,6 +13,7 @@ import NoopAdapter from './adapter/NoopAdapter';
1213
const DEFAULTS = {
1314
enabled : true,
1415
debugEnabled : false,
16+
initialConnectEnabled : true,
1517
urlServer : `${location.protocol}//${location.hostname}` + ((() => {
1618
if (location.port) {
1719
return `:${location.port}`;
@@ -45,6 +47,25 @@ let VertxEventBusWrapperProvider = function () {
4547
return this;
4648
};
4749

50+
/**
51+
* @ngdoc method
52+
* @module knalli.angular-vertxbus
53+
* @methodOf knalli.angular-vertxbus.vertxEventBusProvider
54+
* @name .#disableAutoConnect
55+
*
56+
* @description
57+
* Disables the auto connection feature.
58+
*
59+
* This feature will be only available if `enable == true`.
60+
*
61+
* @param {boolean} [value=true] auto connect on startup
62+
* @returns {object} this
63+
*/
64+
this.disableAutoConnect = () => {
65+
options.initialConnectEnabled = false;
66+
return this;
67+
};
68+
4869
/**
4970
* @ngdoc method
5071
* @module knalli.angular-vertxbus
@@ -188,6 +209,15 @@ let VertxEventBusWrapperProvider = function () {
188209
if (instanceOptions.debugEnabled) {
189210
$log.debug('[Vert.x EB Stub] Enabled');
190211
}
212+
213+
// aggregate server connection params
214+
instanceOptions.connectionConfig = new ConnectionConfigHolder({
215+
urlServer : instanceOptions.urlServer,
216+
urlPath : instanceOptions.urlPath
217+
});
218+
delete instanceOptions.urlServer;
219+
delete instanceOptions.urlPath;
220+
191221
return new EventBusAdapter(vertx.EventBus, $timeout, $log, instanceOptions);
192222
} else {
193223
if (instanceOptions.debugEnabled) {

src/lib/adapter/BaseAdapter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export default class BaseAdapter {
33
constructor() {
44
}
55

6+
configureConnection() {
7+
}
8+
69
connect() {
710
}
811

src/lib/adapter/EventBusAdapter.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {moduleName} from '../../config.js';
22

33
import BaseAdapter from './BaseAdapter';
4+
import ConnectionConfigHolder from './../support/ConnectionConfigHolder';
45

56
/**
67
* @ngdoc service
@@ -84,8 +85,8 @@ export default class EventBusAdapter extends BaseAdapter {
8485
constructor(EventBus, $timeout, $log, {
8586
enabled,
8687
debugEnabled,
87-
urlServer,
88-
urlPath,
88+
initialConnectEnabled,
89+
connectionConfig,
8990
reconnectEnabled,
9091
sockjsReconnectInterval,
9192
sockjsOptions
@@ -98,19 +99,38 @@ export default class EventBusAdapter extends BaseAdapter {
9899
this.options = {
99100
enabled,
100101
debugEnabled,
101-
urlServer,
102-
urlPath,
102+
initialConnectEnabled,
103+
connectionConfig,
103104
reconnectEnabled,
104105
sockjsReconnectInterval,
105106
sockjsOptions
106107
};
107108
this.disconnectTimeoutEnabled = true;
108-
// asap create connection
109-
this.connect();
109+
if (initialConnectEnabled) {
110+
// asap create connection
111+
this.connect();
112+
}
113+
}
114+
115+
/**
116+
* @ngdoc method
117+
* @module knalli.angular-vertxbus
118+
* @methodOf knalli.angular-vertxbus.vertxEventBus
119+
* @name .#configureConnect
120+
*
121+
* @description
122+
* Reconfigure the connection details.
123+
*
124+
* @param {string} urlServer
125+
* @param {string} [urlPath=/eventbus]
126+
*/
127+
configureConnection(urlServer, urlPath = '/eventbus') {
128+
this.options.connectionConfig = new ConnectionConfigHolder({urlServer, urlPath});
129+
return this;
110130
}
111131

112132
connect() {
113-
let url = `${this.options.urlServer}${this.options.urlPath}`;
133+
let url = `${this.options.connectionConfig.urlServer}${this.options.connectionConfig.urlPath}`;
114134
if (this.options.debugEnabled) {
115135
this.$log.debug(`[Vert.x EB Stub] Enabled: connecting '${url}'`);
116136
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default class ConnectionConfigHolder {
2+
3+
constructor({urlServer, urlPath}) {
4+
this._urlServer = urlServer;
5+
this._urlPath = urlPath;
6+
}
7+
8+
get urlServer() {
9+
return this._urlServer;
10+
}
11+
12+
get urlPath() {
13+
return this._urlPath;
14+
}
15+
16+
}

test/unit/binding/vertxEventBus.spec.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,88 @@ describe('integration of module::vertxEventBus', function () {
265265

266266
});
267267

268+
describe('vertxEventBus (w/o autoconnect)', function () {
269+
270+
var vertxEventBus, $timeout, $rootScope, $log;
271+
272+
beforeEach(module('knalli.angular-vertxbus', function (vertxEventBusProvider) {
273+
// Override (improve test running time)
274+
vertxEventBusProvider
275+
.useDebug(true)
276+
.useSockJsReconnectInterval(2000)
277+
.useReconnect(false)
278+
.disableAutoConnect();
279+
}));
280+
281+
beforeEach(inject(function (_vertxEventBus_, _$timeout_, _$rootScope_, _$log_) {
282+
vertxEventBus = _vertxEventBus_;
283+
$timeout = _$timeout_;
284+
$rootScope = _$rootScope_;
285+
$log = _$log_;
286+
SockJS.currentMockInstance.$log = $log;
287+
}));
288+
289+
it('should not fail calling close() on non existing connection', function (done) {
290+
this.timeout(20000);
291+
setTimeout(function () {
292+
vertxEventBus.close();
293+
setTimeout(done, 1200);
294+
}, 200);
295+
});
296+
297+
it('should not fail calling reconnect() on non existing connection', function (done) {
298+
this.timeout(20000);
299+
setTimeout(function () {
300+
vertxEventBus.reconnect(true);
301+
setTimeout(done, 1200);
302+
}, 200);
303+
});
304+
305+
it('should not call the onopen function because no automatic connect', function (done) {
306+
this.timeout(20000);
307+
var onopenCount = 0;
308+
vertxEventBus.onopen = function () {
309+
$log.debug('onopen');
310+
onopenCount++;
311+
};
312+
var oncloseCount = 0;
313+
vertxEventBus.onclose = function () {
314+
$log.debug('onclose');
315+
oncloseCount++;
316+
};
317+
setTimeout(function () {
318+
expect(onopenCount).to.be(0); // should be not called!
319+
setTimeout(done, 1200);
320+
}, 200);
321+
});
322+
323+
it('should not call the onopen function because no automatic connect', function (done) {
324+
this.timeout(20000);
325+
var onopenCount = 0;
326+
vertxEventBus.onopen = function () {
327+
$log.debug('onopen');
328+
onopenCount++;
329+
};
330+
var oncloseCount = 0;
331+
vertxEventBus.onclose = function () {
332+
$log.debug('onclose');
333+
oncloseCount++;
334+
};
335+
setTimeout(function () {
336+
expect(onopenCount).to.be(0); // should be not called!
337+
$log.debug('apply connection config..');
338+
vertxEventBus.configureConnection('http://localhost:1234', '/eventbus1');
339+
vertxEventBus.connect();
340+
setTimeout(function () {
341+
$log.debug('check..');
342+
expect(SockJS.currentMockInstance.url).to.be('http://localhost:1234/eventbus1');
343+
expect(onopenCount).to.be(1);
344+
expect(oncloseCount).to.be(0);
345+
done();
346+
}, 1200);
347+
}, 200);
348+
});
349+
350+
});
351+
268352
});

0 commit comments

Comments
 (0)