🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ws

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ws - npm Package Compare versions

Comparing version

to
0.3.3

6

History.md
v0.3.2 - Dec 11th 2011
======================
* Compile fix for Linux
* Rewrote parts of WebSocket.js, to avoid try/catch and thus avoid optimizer bailouts.
v0.3.2 - Dec 11th 2011
======================
* Further performance updates, including the additions of a native BufferUtil module, which deals with several of the cpu intensive WebSocket operations.

@@ -5,0 +11,0 @@

85

lib/WebSocket.js

@@ -200,3 +200,11 @@ /*!

WebSocket.prototype.send = function(data, options, cb) {
if (this._state != 'connected') throw new Error('not connected');
if (typeof options == 'function') {
cb = options;
options = {};
}
if (this._state != 'connected') {
if (typeof cb == 'function') cb(new Error('not connected'));
else throw new Error('not connected');
return;
}
if (!data) data = '';

@@ -208,6 +216,2 @@ if (this._queue) {

}
if (typeof options === 'function') {
cb = options;
options = {};
}
options = options || {};

@@ -220,3 +224,3 @@ options.fin = true;

sendStream(this, data, options, function(error) {
if (typeof cb === 'function') {
if (typeof cb == 'function') {
cb(error);

@@ -228,5 +232,3 @@ return;

}
else {
this._sender.send(data, options, cb);
}
else this._sender.send(data, options, cb);
}

@@ -238,4 +240,3 @@

* @param {Object} Members - mask: boolean, binary: boolean
* @param {function} 'function (error, send)' which is executed on successive ticks,
* of which send is 'function (data, final)'.
* @param {function} 'function (error, send)' which is executed on successive ticks of which send is 'function (data, final)'.
* @api public

@@ -245,3 +246,12 @@ */

WebSocket.prototype.stream = function(options, cb) {
if (this._state != 'connected') throw new Error('not connected');
if (typeof options == 'function') {
cb = options;
options = {};
}
if (typeof cb != 'function') throw new Error('callback must be provided');
if (this._state != 'connected') {
if (typeof cb == 'function') cb(new Error('not connected'));
else throw new Error('not connected');
return;
}
if (this._queue) {

@@ -252,7 +262,2 @@ var self = this;

}
if (typeof options === 'function') {
cb = options;
options = {};
}
if (typeof cb != 'function') throw new Error('callback must be provided');
options = options || {};

@@ -344,3 +349,3 @@ if (typeof options.mask == 'undefined') options.mask = !this._isServer;

this._sender.on('error', function(error) {
self.emit('error', e);
self.emit('error', error);
});

@@ -358,36 +363,30 @@ this._state = 'connected';

function executeQueueSends(instance) {
try {
var queue = instance._queue;
if (typeof queue == 'undefined') return;
delete instance._queue;
queue.forEach(function(method) { method(); });
var queue = instance._queue;
if (typeof queue == 'undefined') return;
delete instance._queue;
for (var i = 0, l = queue.length; i < l; ++i) {
queue[i]();
}
catch (e) {
instance.emit('error', e);
}
}
function sendStream(self, stream, options, cb) {
function sendStream(instance, stream, options, cb) {
stream.on('data', function(data) {
try {
if (self._state != 'connected') throw new Error('not connected');
options.fin = false;
self._sender.send(data, options);
if (instance._state != 'connected') {
if (typeof cb == 'function') cb(new Error('not connected'));
else instance.emit('error', new Error('not connected'));
return;
}
catch (e) {
if (typeof cb == 'function') cb(e);
else self.emit('error', e);
}
options.fin = false;
instance._sender.send(data, options);
});
stream.on('end', function() {
try {
options.fin = true;
self._sender.send(null, options);
if (typeof cb === 'function') cb(null);
if (instance._state != 'connected') {
if (typeof cb == 'function') cb(new Error('not connected'));
else instance.emit('error', new Error('not connected'));
return;
}
catch (e) {
if (typeof cb == 'function') cb(e);
else self.emit('error', e);
}
options.fin = true;
instance._sender.send(null, options);
if (typeof cb == 'function') cb(null);
});
}

@@ -5,3 +5,3 @@ {

"description": "simple and very fast websocket protocol client for node.js",
"version": "0.3.2",
"version": "0.3.3",
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -262,2 +262,14 @@ var assert = require('assert')

})
it('before connect should pass error through callback, if present', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
ws.on('error', function() {});
ws.send('hi', function(error) {
assert.ok(error instanceof Error);
ws.terminate();
srv.close();
done();
});
});
})
it('without data should be successful', function(done) {

@@ -582,17 +594,15 @@ server.createServer(++port, function(srv) {

})
it('stream before connect should fail', function(done) {
it('before connect should pass error through callback', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
ws.on('error', function() {});
try {
ws.stream(function() {});
}
catch (e) {
ws.stream(function(error) {
assert.ok(error instanceof Error);
ws.terminate();
srv.close();
done();
}
done();
});
});
})
it('stream without callback should fail', function(done) {
it('without callback should fail', function(done) {
server.createServer(++port, function(srv) {

@@ -599,0 +609,0 @@ var ws = new WebSocket('ws://localhost:' + port);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet