Permalink
Browse files

refactor client.connect() arguments

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...
1 parent 73118c2 commit 3252061236be00ed186d9ee5587267ed969f7fdc @jmesnil committed Aug 8, 2013
Showing with 185 additions and 46 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 browsertests/index.html
  3. +6 −4 browsertests/integration/integration.js
  4. +76 −0 browsertests/unit/parse_connect.js
  5. +34 −18 dist/stomp.js
  6. +1 −1 dist/stomp.min.js
  7. +30 −11 doc/index.html
  8. +35 −12 src/stomp.coffee
View
@@ -5,3 +5,4 @@ data
dist/test
TODO.txt
node_modules
+doc/public
View
@@ -15,6 +15,8 @@
<script src="unit/websocket.js"></script>
<!-- check Stomp frame marshalling -->
<script src="unit/frame.js"></script>
+ <!-- check connect method arguments -->
+ <script src="unit/parse_connect.js"></script>
<!-- check connection/disconnection -->
<script src="unit/connection.js"></script>
<!-- check send/receive messages -->
@@ -17,10 +17,12 @@ $(document).ready(function(){
// the client is notified when it is connected to the server.
var onconnect = function(frame) {
debug("connected to Stomp");
- client.subscribe(destination, {receipt: 1234}, function(frame) {
- client.unsubscribe(destination);
- client.disconnect();
- });
+ client.subscribe(destination,
+ function(frame) {
+ client.unsubscribe(destination);
+ client.disconnect();
+ },
+ { receipt: 1234 });
};
client.onerror = function(frame) {
debug("connected to Stomp");
@@ -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);
+ });
+})();
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 3252061

Please sign in to comment.