Skip to content

Commit 0307688

Browse files
committed
minor fixes, changed 'scope' to thisObj to avoid confusion, documentation, all test green
1 parent 5eb1ee6 commit 0307688

8 files changed

+31
-27
lines changed

README

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Introduction in blog post:
44

55
http://blog.higher-order.net/2010/06/01/stomple-rc1-combining-websockets-and-reliable-messaging/
66

7+
Note the word: scope is replaced by thisObj to avoid confusion
8+
79
Quick Demo:
810
1) Start hornetq
911
krukow:~/Projects/private/stomple$ ./hornetq/bin/run.sh ./hornetq/examples/jms/stomp-websockets/server0

build/stomple-min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/stomple-min.js.gz

-2 Bytes
Binary file not shown.

src/stomple.js

+22-20
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
if (!Object.create) {
7575
/**
7676
* Modified version of Crockford/Cornford/Lasse Reichstein Nielsen's
77-
* object function Modified to match EcmaScript 5th edtion Object.create
77+
* object function. Modified to match EcmaScript 5th edtion Object.create
7878
* (no support for setting other properties than value, though).
7979
*
8080
* @see http://www.ecma-international.org/publications/standards/Ecma-262.htm
@@ -270,7 +270,7 @@
270270
autoConnect: true,
271271

272272
/**
273-
* true to have Stomple automatically set a 'content-lenght'
273+
* true to have Stomple automatically set a 'content-length'
274274
* Stomp header. Stomple computes this by computing the number of
275275
* bytes in the UTF-8 encoding of the frame's body.
276276
*/
@@ -315,19 +315,19 @@
315315
onReceipt: emptyFn,
316316

317317
/**
318-
* Low-level callback: called with WebSocket opens.
318+
* Low-level callback: called when WebSocket opens.
319319
*/
320320
socketOpen: emptyFn,
321321
/**
322-
* Low-level callback: called with WebSocket receives a message.
322+
* Low-level callback: called when WebSocket receives a message.
323323
*/
324324
socketMessage: emptyFn,
325325
/**
326-
* Low-level callback: called with WebSocket closes.
326+
* Low-level callback: called when WebSocket closes.
327327
*/
328328
socketClose: emptyFn,
329329
/**
330-
* Low-level callback: called with WebSocket has an error.
330+
* Low-level callback: called when WebSocket has an error.
331331
*/
332332
socketError: emptyFn,
333333

@@ -372,7 +372,7 @@
372372
* {
373373
* 'jms.topic.chat' : [{
374374
* handler: function(msg) {...},
375-
* scope: anObject
375+
* thisObj: anObject
376376
* }, ... ]
377377
* 'jms.topic.another': [...]
378378
* }
@@ -613,7 +613,7 @@
613613
spec = spec || {};
614614
var that = this,
615615
closefn = function(){that.close();};
616-
if (this.connected && this.disconnectOnClose || spec.disconnectOnClose) {
616+
if (this.connected && (this.disconnectOnClose || spec.disconnectOnClose)) {
617617
this.disconnect({
618618
success:closefn,
619619
failure: closefn
@@ -652,21 +652,20 @@
652652
*/
653653
doConnect: function(spec) {
654654
var that = this,
655-
w = this.websocket = new WebSocket(this.url),
655+
w = that.websocket = new WebSocket(that.url),
656656
f = make_frame({
657657
command:"CONNECT",
658658
headers: {
659-
login: spec.login || this.login,
660-
passcode: spec.passcode || this.passcode
659+
login: spec.login || that.login,
660+
passcode: spec.passcode || that.passcode
661661
}
662662
});
663663
if (Stomple.debug && logAvailable) {
664664
console.log(">>>>\n"+f.toString());//TODO: devel only
665665
}
666-
this.connectTimeoutId = setTimeout(function(){
667-
that.connectTimeoutId = null;
668-
that.handleConnectFailed({reason: 'timeout', frame: f, websocket: this.websocket});
669-
}, spec.timeout || this.timeout);
666+
that.connectTimeoutId = setTimeout(function(){
667+
that.handleConnectFailed({reason: 'timeout', frame: f, websocket: w});
668+
}, spec.timeout || that.timeout);
670669

671670
w.onopen = function() {that.handleOpen(f, spec);};
672671
w.onmessage = function(msg) {that.handleMessage(msg);};
@@ -921,15 +920,18 @@
921920
clearTimeout(this.connectTimeoutId);
922921
this.connectTimeoutId = null;
923922
}
924-
this.connected = false;
925-
this.session = null;
926-
this.msgid = null;
927-
this.transid = null;
928923
this.connectFailed(info);
929924
if (this.connectConfig &&
930925
typeof this.connectConfig.failure === 'function') {
931926
this.connectConfig.failure(info);
932927
}
928+
this.connected = false;
929+
this.session = null;
930+
this.msgid = null;
931+
this.transid = null;
932+
if (this.closeOnError) {
933+
this.websocket.close();
934+
}
933935
},
934936

935937
/**
@@ -1051,7 +1053,7 @@
10511053
if (subs) {
10521054
for (i=0,N=subs.length;i<N;i+=1) {
10531055
sub = subs[i];
1054-
sub.handler.call(sub.scope || globalObject,f);
1056+
sub.handler.call(sub.thisObj || globalObject,f);
10551057
}
10561058
}
10571059
break;

test/tests/test-client-ack.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ YUI({ logInclude: { TestRunner: true } }).use("test",'console', function(Y){
5454
Y.Assert.fail("received "+count+" messages");
5555
}
5656
},
57-
scope: this
57+
thisObj: this
5858
});
5959
this.wait(function(){
6060
Y.Assert.isTrue(ok, "Success was not called within 500 ms.");

test/tests/test-send.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ YUI({ logInclude: { TestRunner: true } }).use("test",'console', function(Y){
3434
handler: function(msg) {
3535
received = msg.body;
3636
},
37-
scope: this
37+
thisObj: this
3838
});
3939

4040
this.wait(function(){

test/tests/test-transaction.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ YUI({ logInclude: { TestRunner: true } }).use("test",'console', function(Y){
3535
handler: function(msg) {
3636
received.push(msg.body);
3737
},
38-
scope: this.client
38+
thisObj: this.client
3939
});
4040

4141
this.wait(function(){
@@ -107,7 +107,7 @@ YUI({ logInclude: { TestRunner: true } }).use("test",'console', function(Y){
107107
}
108108

109109
},
110-
scope: this.client
110+
thisObj: this.client
111111
});
112112

113113
this.wait(function(){
@@ -191,7 +191,7 @@ YUI({ logInclude: { TestRunner: true } }).use("test",'console', function(Y){
191191
handler: function(msg) {
192192
received.push(msg.body);
193193
},
194-
scope: this.client
194+
thisObj: this.client
195195
});
196196

197197
this.wait(function(){

test/tests/test-unsubscribe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ YUI({ logInclude: { TestRunner: true } }).use("test",'console', function(Y){
3333
handler: function(msg) {
3434
Y.Assert.fail("received unexpected message on "+this.destination);
3535
},
36-
scope: this.client
36+
thisObj: this.client
3737
});
3838

3939
this.wait(function(){

0 commit comments

Comments
 (0)