Use Extensions.close(callback) to make sure close follows all pending messages.

viz.: https://github.com/faye/websocket-extensions-node/commit/1b77290e8279f654089eac963942309fb19b9312
This commit is contained in:
James Coglan
2015-02-15 13:18:21 +00:00
parent bdc081ab57
commit cc5e5c245e
+12 -6
View File
@@ -153,14 +153,17 @@ var instance = {
},
text: function(message) {
if (this.readyState > 1) return false;
return this.frame(message, 'text');
},
binary: function(message) {
if (this.readyState > 1) return false;
return this.frame(message, 'binary');
},
ping: function(message, callback) {
if (this.readyState > 1) return false;
message = message || '';
if (callback) this._pingCallbacks[message] = callback;
return this.frame(message, 'ping');
@@ -175,8 +178,8 @@ var instance = {
this.emit('close', new Base.CloseEvent(code, reason));
return true;
} else if (this.readyState === 1) {
this.frame(reason, 'close', code);
this.readyState = 2;
this._extensions.close(function() { this.frame(reason, 'close', code) }, this);
return true;
} else {
return false;
@@ -185,7 +188,7 @@ var instance = {
frame: function(data, type, code) {
if (this.readyState <= 0) return this._queue([data, type, code]);
if (this.readyState !== 1) return false;
if (this.readyState > 2) return false;
if (data instanceof Array) data = new Buffer(data);
@@ -288,13 +291,16 @@ var instance = {
},
_shutdown: function(code, reason) {
this.frame(reason, 'close', code);
delete this._frame;
delete this._message;
this.readyState = 3;
this.readyState = 2;
this._stage = 5;
this.emit('close', new Base.CloseEvent(code, reason));
this._extensions.close();
this._extensions.close(function() {
this.frame(reason, 'close', code);
this.readyState = 3;
this.emit('close', new Base.CloseEvent(code, reason));
}, this);
},
_fail: function(type, message) {