Socket
Socket
Sign inDemoInstall

ws

Package Overview
Dependencies
Maintainers
1
Versions
169
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 0.4.23 to 0.4.24

5

History.md

@@ -0,1 +1,6 @@

v0.4.24 - December 6th, 2012
=====================
* Yet another intermediate release, to not delay minor features any longer.
* Native support installation issues further circumvented. [einaros]
v0.4.23 - November 19th, 2012

@@ -2,0 +7,0 @@ =====================

@@ -11,1 +11,17 @@ /*!

module.exports.Receiver = require('./lib/Receiver');
module.exports.createServer = function (options, connectionListener) {
var server = new module.exports.Server(options);
if (typeof connectionListener === 'function') {
server.on('connection', connectionListener);
}
return server;
};
module.exports.connect = module.exports.createConnection = function (address, openListener) {
var client = new module.exports(address);
if (typeof openListener === 'function') {
client.on('open', openListener);
}
return client;
};

49

install.js

@@ -1,3 +0,2 @@

var spawn = require('child_process').spawn
, exec = require('child_process').exec
var exec = require('child_process').exec
, tinycolor = require('tinycolor')

@@ -10,21 +9,29 @@ , fs = require('fs')

var gyp = exec('node-gyp rebuild', {cwd: __dirname});
gyp.stdout.on('data', function(data) {
if (verbose) process.stdout.write(data);
});
gyp.stderr.on('data', function(data) {
if (verbose) process.stdout.write(data);
});
gyp.on('exit', function(code) {
if (code !== 0) {
console.log('[ws v%s]'.blue + ' Native code compile failed (but the module will still work):'.yellow, version);
console.log('[ws v%s]'.blue + ' The native extensions are faster, but not required.'.yellow, version);
console.log('[ws v%s]'.blue + ' On Windows, native extensions require Visual Studio and Python.'.yellow, version);
console.log('[ws v%s]'.blue + ' On Unix, native extensions require Python, make and a C++ compiler.'.yellow, version);
console.log('[ws v%s]'.blue + ' Start npm with --ws:verbose to show compilation output (if any).'.yellow, version);
}
else {
console.log('[ws v%s]'.blue + ' Native extension compilation successful!'.green, version);
}
function exitWithWarning() {
console.log('[ws v%s]'.blue + ' Native code compile failed (but the module will still work):'.yellow, version);
console.log('[ws v%s]'.blue + ' The native extensions are faster, but not required.'.yellow, version);
console.log('[ws v%s]'.blue + ' On Windows, native extensions require Visual Studio and Python.'.yellow, version);
console.log('[ws v%s]'.blue + ' On Unix, native extensions require Python, make and a C++ compiler.'.yellow, version);
console.log('[ws v%s]'.blue + ' Start npm with --ws:verbose to show compilation output (if any).'.yellow, version);
process.exit();
});
}
try {
var gyp = exec('node-gyp rebuild', {cwd: __dirname});
gyp.stdout.on('data', function(data) {
if (verbose) process.stdout.write(data);
});
gyp.stderr.on('data', function(data) {
if (verbose) process.stdout.write(data);
});
gyp.on('exit', function(code) {
if (code !== 0) exitWithWarning();
else {
console.log('[ws v%s]'.blue + ' Native extension compilation successful!'.green, version);
}
process.exit();
});
}
catch (e) {
exitWithWarning();
}

@@ -15,2 +15,4 @@ /*!

, BODY = 1;
var BINARYLENGTH = 2
, BINARYBODY = 3;

@@ -53,2 +55,8 @@ /**

}
if (data[0] === 0x80) {
self.messageEnd = 0;
self.state = BINARYLENGTH;
data = data.slice(1);
} else {
if (data[0] !== 0x00) {

@@ -60,3 +68,33 @@ self.error('payload must start with 0x00 byte', true);

self.state = BODY;
}
}
if (self.state === BINARYLENGTH) {
var i = 0;
while ((i < data.length) && (data[i] & 0x80)) {
self.messageEnd = 128 * self.messageEnd + (data[i] & 0x7f);
++i;
}
if (i < data.length) {
self.messageEnd = 128 * self.messageEnd + (data[i] & 0x7f);
self.state = BINARYBODY;
++i;
}
if (i > 0)
data = data.slice(i);
}
if (self.state === BINARYBODY) {
var dataleft = self.messageEnd - self.spanLength;
if (data.length >= dataleft) {
// consume the whole buffer to finish the frame
self.buffers.push(data);
self.spanLength += dataleft;
self.messageEnd = dataleft;
return self.parse();
}
// frame's not done even if we consume it all
self.buffers.push(data);
self.spanLength += data.length;
return;
}
self.buffers.push(data);

@@ -100,2 +138,3 @@ if ((self.messageEnd = bufferIndex(data, 0xFF)) != -1) {

if (this.messageEnd > 0) lastBuffer.copy(output, outputIndex, 0, this.messageEnd);
if (this.state !== BODY) --this.messageEnd;
var tail = null;

@@ -102,0 +141,0 @@ if (this.messageEnd < lastBuffer.length - 1) {

@@ -37,2 +37,3 @@ /*!

if (this.isClosed) return;
/*
if (options && options.binary) {

@@ -42,11 +43,21 @@ this.error('hixie websockets do not support binary');

}
*/
var isString = typeof data == 'string'
, length = isString ? Buffer.byteLength(data) : data.length
, lengthbytes = (length > 127) ? 2 : 1 // assume less than 2**14 bytes
, writeStartMarker = this.continuationFrame == false
, writeEndMarker = !options || !(typeof options.fin != 'undefined' && !options.fin)
, buffer = new Buffer((writeStartMarker ? 1 : 0) + length + (writeEndMarker ? 1 : 0))
, buffer = new Buffer((writeStartMarker ? ((options && options.binary) ? (1 + lengthbytes) : 1) : 0) + length + ((writeEndMarker && !(options && options.binary)) ? 1 : 0))
, offset = writeStartMarker ? 1 : 0;
if (writeStartMarker) buffer.write('\x00', 'binary');
if (writeStartMarker) {
if (options && options.binary) {
buffer.write('\x80', 'binary');
// assume length less than 2**14 bytes
if (lengthbytes > 1)
buffer.write(String.fromCharCode(128+length/128), offset++, 'binary');
buffer.write(String.fromCharCode(length&0x7f), offset++, 'binary');
} else
buffer.write('\x00', 'binary');
}

@@ -57,3 +68,6 @@ if (isString) buffer.write(data, offset, 'utf8');

if (writeEndMarker) {
buffer.write('\xff', offset + length, 'binary');
if (options && options.binary) {
// sending binary, not writing end marker
} else
buffer.write('\xff', offset + length, 'binary');
this.continuationFrame = false;

@@ -60,0 +74,0 @@ }

@@ -91,3 +91,3 @@ /*!

WebSocketServer.prototype.close = function(code, data) {
WebSocketServer.prototype.close = function() {
// terminate all associated clients

@@ -281,3 +281,8 @@ var error = null;

var onClientVerified = function() {
var location = ((req.headers['x-forwarded-proto'] === 'https' || socket.encrypted) ? 'wss' : 'ws') + '://' + req.headers.host + req.url
var wshost;
if (!req.headers['x-forwarded-host'])
wshost = req.headers.host;
else
wshost = req.headers['x-forwarded-host'];
var location = ((req.headers['x-forwarded-proto'] === 'https' || socket.encrypted) ? 'wss' : 'ws') + '://' + wshost + req.url
, protocol = req.headers['sec-websocket-protocol'];

@@ -284,0 +289,0 @@

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

"description": "simple to use, blazing fast and thoroughly tested websocket client, server and console for node.js, up-to-date against RFC-6455",
"version": "0.4.23",
"version": "0.4.24",
"repository": {

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

@@ -132,2 +132,28 @@ var assert = require('assert')

});
it('can parse binary messages delivered over multiple frames', function() {
var p = new Receiver();
var packets = [
'80 05 48',
'65 6c 6c',
'6f 80 80 05 48',
'65',
'6c 6c 6f'
];
var gotData = false;
var messages = [];
p.ontext = function(data) {
gotData = true;
messages.push(data);
};
for (var i = 0; i < packets.length; ++i) {
p.add(getBufferFromHexString(packets[i]));
}
expect(gotData).to.equal(true);
for (var i = 0; i < 2; ++i) {
expect(messages[i]).to.equal('Hello');
}
});
});

@@ -49,2 +49,20 @@ var assert = require('assert')

it('frames and sends a binary message', function(done) {
var message = 'Hello world';
var received;
var socket = {
write: function(data, encoding, cb) {
received = data;
process.nextTick(cb);
}
};
var sender = new Sender(socket, {});
sender.send(message, {binary: true}, function() {
received.toString('hex').should.eql(
// 0x80 0x0b H e l l o <sp> w o r l d
'800b48656c6c6f20776f726c64');
done();
});
});
/*
it('throws an exception for binary data', function(done) {

@@ -62,3 +80,3 @@ var socket = {

});
*/
it('can fauxe stream data', function(done) {

@@ -65,0 +83,0 @@ var received = [];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc