Skip to content

Commit

Permalink
- W3CWebSocket: close() allows code and reason as in the latest W3C s…
Browse files Browse the repository at this point in the history
…pec (fixes #184).
  • Loading branch information
ibc committed Feb 18, 2015
1 parent 99afb83 commit 327daad
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/W3CWebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ WebSocket.prototype.send = function(data) {
};


WebSocket.prototype.close = function() {
WebSocket.prototype.close = function(code, reason) {
switch(this._readyState) {
case CONNECTING:
// TODO: We don't have the WebSocketConnection instance yet so no
Expand All @@ -145,7 +145,11 @@ WebSocket.prototype.close = function() {
onConnectFailed.call(this);
// And close if it connects after a while.
this._client.on('connect', function(connection) {
connection.close();
if (code) {
connection.close(code, reason);
} else {
connection.close();
}
});
break;
case OPEN:
Expand Down Expand Up @@ -220,7 +224,7 @@ function onConnectFailed() {
function onClose(code, reason) {
destroy.call(this);
this._readyState = CLOSED;

callListener.call(this, 'onclose', new CloseEvent(this, code, reason || ''));
}

Expand Down

0 comments on commit 327daad

Please sign in to comment.