|
74 | 74 | if (!Object.create) {
|
75 | 75 | /**
|
76 | 76 | * 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 |
78 | 78 | * (no support for setting other properties than value, though).
|
79 | 79 | *
|
80 | 80 | * @see http://www.ecma-international.org/publications/standards/Ecma-262.htm
|
|
270 | 270 | autoConnect: true,
|
271 | 271 |
|
272 | 272 | /**
|
273 |
| - * true to have Stomple automatically set a 'content-lenght' |
| 273 | + * true to have Stomple automatically set a 'content-length' |
274 | 274 | * Stomp header. Stomple computes this by computing the number of
|
275 | 275 | * bytes in the UTF-8 encoding of the frame's body.
|
276 | 276 | */
|
|
315 | 315 | onReceipt: emptyFn,
|
316 | 316 |
|
317 | 317 | /**
|
318 |
| - * Low-level callback: called with WebSocket opens. |
| 318 | + * Low-level callback: called when WebSocket opens. |
319 | 319 | */
|
320 | 320 | socketOpen: emptyFn,
|
321 | 321 | /**
|
322 |
| - * Low-level callback: called with WebSocket receives a message. |
| 322 | + * Low-level callback: called when WebSocket receives a message. |
323 | 323 | */
|
324 | 324 | socketMessage: emptyFn,
|
325 | 325 | /**
|
326 |
| - * Low-level callback: called with WebSocket closes. |
| 326 | + * Low-level callback: called when WebSocket closes. |
327 | 327 | */
|
328 | 328 | socketClose: emptyFn,
|
329 | 329 | /**
|
330 |
| - * Low-level callback: called with WebSocket has an error. |
| 330 | + * Low-level callback: called when WebSocket has an error. |
331 | 331 | */
|
332 | 332 | socketError: emptyFn,
|
333 | 333 |
|
|
372 | 372 | * {
|
373 | 373 | * 'jms.topic.chat' : [{
|
374 | 374 | * handler: function(msg) {...},
|
375 |
| - * scope: anObject |
| 375 | + * thisObj: anObject |
376 | 376 | * }, ... ]
|
377 | 377 | * 'jms.topic.another': [...]
|
378 | 378 | * }
|
|
613 | 613 | spec = spec || {};
|
614 | 614 | var that = this,
|
615 | 615 | closefn = function(){that.close();};
|
616 |
| - if (this.connected && this.disconnectOnClose || spec.disconnectOnClose) { |
| 616 | + if (this.connected && (this.disconnectOnClose || spec.disconnectOnClose)) { |
617 | 617 | this.disconnect({
|
618 | 618 | success:closefn,
|
619 | 619 | failure: closefn
|
|
652 | 652 | */
|
653 | 653 | doConnect: function(spec) {
|
654 | 654 | var that = this,
|
655 |
| - w = this.websocket = new WebSocket(this.url), |
| 655 | + w = that.websocket = new WebSocket(that.url), |
656 | 656 | f = make_frame({
|
657 | 657 | command:"CONNECT",
|
658 | 658 | 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 |
661 | 661 | }
|
662 | 662 | });
|
663 | 663 | if (Stomple.debug && logAvailable) {
|
664 | 664 | console.log(">>>>\n"+f.toString());//TODO: devel only
|
665 | 665 | }
|
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); |
670 | 669 |
|
671 | 670 | w.onopen = function() {that.handleOpen(f, spec);};
|
672 | 671 | w.onmessage = function(msg) {that.handleMessage(msg);};
|
|
921 | 920 | clearTimeout(this.connectTimeoutId);
|
922 | 921 | this.connectTimeoutId = null;
|
923 | 922 | }
|
924 |
| - this.connected = false; |
925 |
| - this.session = null; |
926 |
| - this.msgid = null; |
927 |
| - this.transid = null; |
928 | 923 | this.connectFailed(info);
|
929 | 924 | if (this.connectConfig &&
|
930 | 925 | typeof this.connectConfig.failure === 'function') {
|
931 | 926 | this.connectConfig.failure(info);
|
932 | 927 | }
|
| 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 | + } |
933 | 935 | },
|
934 | 936 |
|
935 | 937 | /**
|
|
1051 | 1053 | if (subs) {
|
1052 | 1054 | for (i=0,N=subs.length;i<N;i+=1) {
|
1053 | 1055 | sub = subs[i];
|
1054 |
| - sub.handler.call(sub.scope || globalObject,f); |
| 1056 | + sub.handler.call(sub.thisObj || globalObject,f); |
1055 | 1057 | }
|
1056 | 1058 | }
|
1057 | 1059 | break;
|
|
0 commit comments