Comparing version 1.0.17 to 1.0.18
Changelog | ||
========= | ||
Version 1.0.18 | ||
-------------- | ||
*Released 2015-03-19* | ||
* Resolves [issue #195](https://github.com/theturtle32/WebSocket-Node/pull/179) - passing number to connection.send() causes crash | ||
* [Added close code/reason arguments to W3CWebSocket#close()](https://github.com/theturtle32/WebSocket-Node/issues/184) | ||
Version 1.0.17 | ||
@@ -5,0 +13,0 @@ -------------- |
@@ -62,3 +62,7 @@ WebSocketClient | ||
###abort() | ||
Will cancel an in-progress connection request before either the `connect` event or the `connectFailed` event has been emitted. If the `connect` or `connectFailed` event has already been emitted, calling `abort()` will do nothing. | ||
Events | ||
@@ -65,0 +69,0 @@ ------ |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
/************************************************************************ | ||
* Copyright 2010-2014 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -32,2 +32,4 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
var self = this; | ||
// W3C attributes and listeners. | ||
@@ -53,5 +55,10 @@ this._listeners = { | ||
this._client.on('connect', onConnect.bind(this)); | ||
this._client.on('connectFailed', onConnectFailed.bind(this)); | ||
this._client.on('connect', function(connection) { | ||
onConnect.call(self, connection); | ||
}); | ||
this._client.on('connectFailed', function() { | ||
onConnectFailed.call(self); | ||
}); | ||
this._client.connect(url, protocols, origin, headers, requestOptions); | ||
@@ -141,3 +148,3 @@ } | ||
WebSocket.prototype.close = function() { | ||
WebSocket.prototype.close = function(code, reason) { | ||
switch(this._readyState) { | ||
@@ -151,3 +158,7 @@ case CONNECTING: | ||
this._client.on('connect', function(connection) { | ||
connection.close(); | ||
if (code) { | ||
connection.close(code, reason); | ||
} else { | ||
connection.close(); | ||
} | ||
}); | ||
@@ -157,3 +168,7 @@ break; | ||
this._readyState = CLOSING; | ||
this._connection.close(); | ||
if (code) { | ||
this._connection.close(code, reason); | ||
} else { | ||
this._connection.close(); | ||
} | ||
break; | ||
@@ -201,2 +216,4 @@ case CLOSING: | ||
function onConnect(connection) { | ||
var self = this; | ||
this._readyState = OPEN; | ||
@@ -207,5 +224,10 @@ this._connection = connection; | ||
this._connection.on('close', onClose.bind(this)); | ||
this._connection.on('message', onMessage.bind(this)); | ||
this._connection.on('close', function(code, reason) { | ||
onClose.call(self, code, reason); | ||
}); | ||
this._connection.on('message', function(msg) { | ||
onMessage.call(self, msg); | ||
}); | ||
callListener.call(this, 'onopen', new OpenEvent(this)); | ||
@@ -216,2 +238,4 @@ } | ||
function onConnectFailed() { | ||
var self = this; | ||
destroy.call(this); | ||
@@ -222,4 +246,4 @@ this._readyState = CLOSED; | ||
global.setTimeout(function() { | ||
callListener.call(this, 'onclose', new CloseEvent(this, 1006, 'connection failed')); | ||
}.bind(this)); | ||
callListener.call(self, 'onclose', new CloseEvent(self, 1006, 'connection failed')); | ||
}); | ||
callListener.call(this, 'onerror', new ErrorEvent(this)); | ||
@@ -232,3 +256,3 @@ } | ||
this._readyState = CLOSED; | ||
callListener.call(this, 'onclose', new CloseEvent(this, code, reason || '')); | ||
@@ -235,0 +259,0 @@ } |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -693,6 +693,7 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
WebSocketConnection.prototype.sendUTF = function(data, cb) { | ||
this._debug('sendUTF: %s', data.slice(0,80) + '|...'); | ||
data = new Buffer(data.toString(), 'utf8'); | ||
this._debug('sendUTF: %d bytes', data.length); | ||
var frame = new WebSocketFrame(this.maskBytes, this.frameHeader, this.config); | ||
frame.opcode = 0x01; // WebSocketOpcode.TEXT_FRAME | ||
frame.binaryPayload = new Buffer(data.toString(), 'utf8'); | ||
frame.binaryPayload = data; | ||
this.fragmentAndSend(frame, cb); | ||
@@ -699,0 +700,0 @@ }; |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
/************************************************************************ | ||
* Copyright 2010-2011 Worlize Inc. | ||
* Copyright 2010-2015 Brian McKelvey. | ||
* | ||
@@ -4,0 +4,0 @@ * Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -17,3 +17,3 @@ { | ||
"author": "Brian McKelvey <brian@worlize.com> (https://www.worlize.com/)", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"repository": { | ||
@@ -20,0 +20,0 @@ "type": "git", |
WebSocket Client & Server Implementation for Node | ||
================================================= | ||
[](https://gitter.im/theturtle32/WebSocket-Node?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[](http://badge.fury.io/js/websocket) | ||
@@ -10,2 +12,4 @@ | ||
[ ](https://codeship.com/projects/61106) | ||
Overview | ||
@@ -27,4 +31,9 @@ -------- | ||
***Current Version: 1.0.17*** — Released 2015-01-17 | ||
***Current Version: 1.0.18*** — Released 2015-03-19 | ||
***Version 1.0.18*** | ||
* Resolves [issue #195](https://github.com/theturtle32/WebSocket-Node/pull/179) - passing number to connection.send() causes crash | ||
* [Added close code/reason arguments to W3CWebSocket#close()](https://github.com/theturtle32/WebSocket-Node/issues/184) | ||
***Version 1.0.17*** | ||
@@ -31,0 +40,0 @@ |
Sorry, the diff of this file is not supported yet
192074
2773
306