Fix check of readyState for immediate close

This commit is contained in:
Greg Soltis
2012-10-15 11:34:44 -07:00
parent 64b52a0be2
commit 3280f38c27
+11 -9
View File
@@ -57,9 +57,7 @@ var API = {
close: function(code, reason, ack) {
if (this.readyState === API.CLOSING ||
this.readyState === API.CLOSED) return;
this.readyState = API.CLOSING;
var close = function() {
this.readyState = API.CLOSED;
if (this._pingLoop) clearInterval(this._pingLoop);
@@ -68,15 +66,19 @@ var API = {
event.initEvent('close', false, false);
this.dispatchEvent(event);
};
if (this.readyState === API.CONNECTING) {
close.call(this);
} else if (ack !== false) {
if (this._parser.close) this._parser.close(code, reason, close, this);
else close.call(this);
} else {
if (this._parser.close) this._parser.close(code, reason);
close.call(this);
this.readyState = API.CLOSING;
if (ack !== false) {
if (this._parser.close) this._parser.close(code, reason, close, this);
else close.call(this);
} else {
if (this._parser.close) this._parser.close(code, reason);
close.call(this);
}
}
}
};