Skip to content

Commit

Permalink
refactor client.connect() arguments
Browse files Browse the repository at this point in the history
fix client.connect() method to allow to pass additional headers (e.g. a
client-id header in issue #32).

The change is backwards compatible so that Web applications should not
have to change their call to work.
  • Loading branch information
jmesnil committed Aug 8, 2013
1 parent 73118c2 commit 3252061
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ data
dist/test dist/test
TODO.txt TODO.txt
node_modules node_modules
doc/public
2 changes: 2 additions & 0 deletions browsertests/index.html
Expand Up @@ -15,6 +15,8 @@
<script src="unit/websocket.js"></script> <script src="unit/websocket.js"></script>
<!-- check Stomp frame marshalling --> <!-- check Stomp frame marshalling -->
<script src="unit/frame.js"></script> <script src="unit/frame.js"></script>
<!-- check connect method arguments -->
<script src="unit/parse_connect.js"></script>
<!-- check connection/disconnection --> <!-- check connection/disconnection -->
<script src="unit/connection.js"></script> <script src="unit/connection.js"></script>
<!-- check send/receive messages --> <!-- check send/receive messages -->
Expand Down
10 changes: 6 additions & 4 deletions browsertests/integration/integration.js
Expand Up @@ -17,10 +17,12 @@ $(document).ready(function(){
// the client is notified when it is connected to the server. // the client is notified when it is connected to the server.
var onconnect = function(frame) { var onconnect = function(frame) {
debug("connected to Stomp"); debug("connected to Stomp");
client.subscribe(destination, {receipt: 1234}, function(frame) { client.subscribe(destination,
client.unsubscribe(destination); function(frame) {
client.disconnect(); client.unsubscribe(destination);
}); client.disconnect();
},
{ receipt: 1234 });
}; };
client.onerror = function(frame) { client.onerror = function(frame) {
debug("connected to Stomp"); debug("connected to Stomp");
Expand Down
76 changes: 76 additions & 0 deletions browsertests/unit/parse_connect.js
@@ -0,0 +1,76 @@
(function() {
module("Parse connect method arguments", {

setup: function() {
// prepare something for all following tests
myConnectCallback = function() {
// called back when the client is connected to STOMP broker
};

myErrorCallback = function() {
// called back if the client can not connect to STOMP broker
};

client = Stomp.client(TEST.url);

checkArgs = function(args, expectedHeaders, expectedConnectCallback, expectedErrorCallback) {
var headers = args[0];
var connectCallback = args[1];
var errorCallback = args[2];

deepEqual(headers, expectedHeaders);
strictEqual(connectCallback, expectedConnectCallback);
strictEqual(errorCallback, expectedErrorCallback);
}
}
});

test("connect(login, passcode, connectCallback)", function() {
checkArgs(
client._parseConnect("jmesnil", "wombats", myConnectCallback),

{login: 'jmesnil', passcode: 'wombats'},
myConnectCallback,
undefined);
});

test("connect(login, passcode, connectCallback, errorCallback)", function() {
checkArgs(
client._parseConnect("jmesnil", "wombats", myConnectCallback, myErrorCallback),

{login: 'jmesnil', passcode: 'wombats'},
myConnectCallback,
myErrorCallback);
});

test("connect(login, passcode, connectCallback, errorCallback, vhost)", function() {
checkArgs(
client._parseConnect("jmesnil", "wombats", myConnectCallback, myErrorCallback, "myvhost"),

{login: 'jmesnil', passcode: 'wombats', vhost: 'myvhost'},
myConnectCallback,
myErrorCallback);
});

test("connect(headers, connectCallback)", function() {
var headers = {login: 'jmesnil', passcode: 'wombats', vhost: 'myvhost'};

checkArgs(
client._parseConnect(headers, myConnectCallback),

headers,
myConnectCallback,
undefined);
});

test("connect(headers, connectCallback, errorCallback)", function() {
var headers = {login: 'jmesnil', passcode: 'wombats', vhost: 'myvhost'};

checkArgs(
client._parseConnect(headers, myConnectCallback, myErrorCallback),

headers,
myConnectCallback,
myErrorCallback);
});
})();
52 changes: 34 additions & 18 deletions dist/stomp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/stomp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3252061

Please sign in to comment.