🚀 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.9

test/fixtures/certificate.pem

10

bench/WebSocket.benchmark.js

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

sender = new Sender();
sender._socket = { write: function() {} };
});

@@ -31,2 +32,3 @@

sender = new Sender();
sender._socket = { write: function() {} };
});

@@ -100,7 +102,7 @@

framePacket.fill(99);
suite.add('frameData, unmasked (200 kB)', function () {
sender.frameData(0x2, framePacket, true, false);
suite.add('frameAndSend, unmasked (200 kB)', function () {
sender.frameAndSend(0x2, framePacket, true, false);
});
suite.add('frameData, masked (200 kB)', function () {
sender.frameData(0x2, framePacket, true, true);
suite.add('frameAndSend, masked (200 kB)', function () {
sender.frameAndSend(0x2, framePacket, true, true);
});

@@ -107,0 +109,0 @@

@@ -0,1 +1,12 @@

v0.3.9 - Jan 1st 2012
======================
* Improved protocol framing performance [einaros]
* WSS support [kazuyukitanimura]
* WSS tests [einaros]
* readyState exposed [justinlatimer, tricknotes]
* url property exposed [justinlatimer]
* Removed old 'state' property [einaros]
* Test cleanups [einaros]
v0.3.8 - Dec 27th 2011

@@ -2,0 +13,0 @@ ======================

4

lib/BufferPool.js

@@ -49,6 +49,2 @@ /*!

BufferPool.prototype.reset = function(forceNewBuffer) {
// var len = this._shrinkStrategy();
// this._buffer = len ? new Buffer(len) : null;
// this._offset = 0;
// this._used = 0;
var len = this._shrinkStrategy();

@@ -55,0 +51,0 @@ if (len < this.size) this._changeFactor -= 1;

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

Sender.prototype.frameAndSend = function(opcode, data, finalFragment, maskData, cb) {
var dontModifyData = true;
if (!data) {

@@ -111,2 +112,3 @@ try {

else if (!Buffer.isBuffer(data)) {
dontModifyData = false;
data = (data && typeof data.buffer !== 'undefined') ? getArrayBuffer(data.buffer) : new Buffer(data);

@@ -125,5 +127,5 @@ }

}
var totalLength = maskData ? dataLength + dataOffset : dataOffset;
var totalLength = (maskData && dontModifyData) ? dataLength + dataOffset : dataOffset;
var outputBuffer = (this._sendCache && totalLength <= this._sendCacheSize)
? (totalLength == this._sendCacheSize ? this._sendCache : this._sendCache.slice(0, totalLength))
? ((totalLength == this._sendCacheSize ? this._sendCache : this._sendCache.slice(0, totalLength)))
: new Buffer(totalLength);

@@ -139,2 +141,4 @@ outputBuffer[0] = finalFragment ? opcode | 0x80 : opcode;

}
var sendsDone = 0;
var cbCaller = function() { if (++sendsDone == 2 && typeof cb == 'function') cb(null); }
if (maskData) {

@@ -147,9 +151,22 @@ outputBuffer[1] = secondByte | 0x80;

outputBuffer[dataOffset - 1] = mask[3];
bufferUtil.mask(data, mask, outputBuffer, dataOffset, dataLength);
try {
this._socket.write(outputBuffer, 'binary', cb);
if (dontModifyData) {
bufferUtil.mask(data, mask, outputBuffer, dataOffset, dataLength);
try {
this._socket.write(outputBuffer, 'binary', cb);
}
catch (e) {
if (typeof cb == 'function') cb(e);
else this.emit('error', e);
}
}
catch (e) {
if (typeof cb == 'function') cb(e);
else this.emit('error', e);
else {
bufferUtil.mask(data, mask, data, 0, dataLength);
try {
this._socket.write(outputBuffer, 'binary', cb ? cbCaller : null);
this._socket.write(data, 'binary', cb ? cbCaller : null);
}
catch (e) {
if (typeof cb == 'function') cb(e);
else this.emit('error', e);
}
}

@@ -159,9 +176,5 @@ }

outputBuffer[1] = secondByte;
var done = 0;
function callback() {
if (++done == 2 && typeof cb == 'function') cb(null);
}
try {
this._socket.write(outputBuffer, 'binary', callback);
this._socket.write(data, 'binary', callback);
this._socket.write(outputBuffer, 'binary', cb ? cbCaller : null);
this._socket.write(data, 'binary', cb ? cbCaller : null);
}

@@ -168,0 +181,0 @@ catch (e) {

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

, http = require('http')
, https = require('https')
, crypto = require('crypto')

@@ -73,2 +74,10 @@ , url = require('url')

if (!serverUrl.host) throw new Error('invalid url');
var httpObj = (serverUrl.protocol === 'wss:' || serverUrl.protocol === 'https:') ? https : http;
Object.defineProperty(this, 'url', {
writable: false,
configurable: false,
enumerable: true,
value: address
});

@@ -94,3 +103,3 @@ options = new Options({

isNodeV4 = true;
agent = new http.Agent({
agent = new httpObj.Agent({
host: serverUrl.hostname,

@@ -124,3 +133,3 @@ port: serverUrl.port || 80

var req = http.request(requestOptions);
var req = httpObj.request(requestOptions);
var self = this;

@@ -157,6 +166,15 @@ (isNodeV4 ? agent : req).on('error', function(error) {

Object.defineProperty(this, '_socket', { writable: true, value: null });
Object.defineProperty(this, 'state', {
value: this._state,
configurable: false,
enumerable: true
Object.defineProperty(this, 'readyState', {
get: function() {
switch(this._state) {
case 'connecting':
return WebSocket.CONNECTING;
case 'connected':
return WebSocket.OPEN;
case 'closing':
return WebSocket.CLOSING;
case 'disconnected':
return WebSocket.CLOSED;
}
}
});

@@ -166,2 +184,20 @@ }

/**
* Ready States
*/
(function() {
var readyStates = {
CONNECTING: 0
, OPEN: 1
, CLOSING: 2
, CLOSED: 3
};
for (var state in readyStates) {
if (!readyStates.hasOwnProperty(state)) continue;
Object.defineProperty(WebSocket, state, { enumerable: true, value: readyStates[state]});
}
})();
/**
* Inherits from EventEmitter.

@@ -168,0 +204,0 @@ */

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

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

@@ -11,7 +11,2 @@ "type": "git",

},
"contributors": [
{ "name": "Einar Otto Stangvik", "email": "einaros@gmail.com" },
{ "name": "Maciej Małecki", "email": "maciej.malecki@notimplemented.org" },
{ "name": "Arnout Kazemier", "email": "info@3rd-eden.com" }
],
"bin": {

@@ -22,3 +17,3 @@ "wscat": "./bin/wscat"

"test": "make test",
"preinstall": "make validator"
"preinstall": "make"
},

@@ -33,4 +28,4 @@ "engines": {

"devDependencies": {
"mocha": "0.3.x",
"should": "0.3.2",
"mocha": "0.8.x",
"should": "0.4.2",
"benchmark": "0.3.x",

@@ -37,0 +32,0 @@ "tinycolor": "0.x"

@@ -28,3 +28,3 @@ var WebSocketServer = require('../').Server;

console.log('error', arguments);
})
});
});

@@ -9,4 +9,4 @@ var BufferPool = require('../lib/BufferPool');

db.size.should.eql(1000);
})
})
});
});
describe('#get', function() {

@@ -19,3 +19,3 @@ it('grows the pool if necessary', function() {

buf.length.should.eql(2000);
})
});
it('grows the pool after the first call, if necessary', function() {

@@ -31,3 +31,3 @@ var db = new BufferPool(1000);

buf2.length.should.eql(1000);
})
});
it('grows the pool according to the growStrategy if necessary', function() {

@@ -40,3 +40,3 @@ var db = new BufferPool(1000, function(db, length) {

buf.length.should.eql(2000);
})
});
it('doesnt grow the pool if theres enough room available', function() {

@@ -47,4 +47,4 @@ var db = new BufferPool(1000);

buf.length.should.eql(1000);
})
})
});
});
describe('#reset', function() {

@@ -56,3 +56,3 @@ it('shinks the pool', function() {

db.size.should.eql(1000);
})
});
it('shrinks the pool according to the shrinkStrategy', function() {

@@ -67,4 +67,4 @@ var db = new BufferPool(1000, function(db, length) {

db.size.should.eql(0);
})
})
})
});
});
});

@@ -19,3 +19,3 @@ var assert = require('assert')

gotData.should.be.ok;
})
});
it('can parse close message', function() {

@@ -32,3 +32,3 @@ var p = new Parser();

gotClose.should.be.ok;
})
});
it('can parse masked text message', function() {

@@ -46,3 +46,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a masked text message longer than 125 bytes', function() {

@@ -62,3 +62,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a really long masked text message', function() {

@@ -78,3 +78,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a fragmented masked text message of 300 bytes', function() {

@@ -98,3 +98,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a ping message', function() {

@@ -113,3 +113,3 @@ var p = new Parser();

gotPing.should.be.ok;
})
});
it('can parse a ping with no data', function() {

@@ -126,3 +126,3 @@ var p = new Parser();

gotPing.should.be.ok;
})
});
it('can parse a fragmented masked text message of 300 bytes with a ping in the middle', function() {

@@ -158,3 +158,3 @@ var p = new Parser();

gotPing.should.be.ok;
})
});
it('can parse a fragmented masked text message of 300 bytes with a ping in the middle, which is delievered over sevaral tcp packets', function() {

@@ -194,3 +194,3 @@ var p = new Parser();

gotPing.should.be.ok;
})
});
it('can parse a 100 byte long masked binary message', function() {

@@ -212,3 +212,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a 256 byte long masked binary message', function() {

@@ -230,3 +230,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a 200kb long masked binary message', function() {

@@ -248,3 +248,3 @@ var p = new Parser();

gotData.should.be.ok;
})
});
it('can parse a 200kb long unmasked binary message', function() {

@@ -266,4 +266,4 @@ var p = new Parser();

gotData.should.be.ok;
})
})
});
});

@@ -11,3 +11,3 @@ var assert = require('assert')

sender._sendCache.length.should.eql(10);
})
});

@@ -19,3 +19,3 @@ it('keeps a send cache equal to null if options.sendBufferCacheSize is 0', function() {

(typeof sender._sendCache).should.eql('undefined');
})
});

@@ -27,3 +27,23 @@ it('keeps a send cache equal to null if options.sendBufferCacheSize is -1', function() {

(typeof sender._sendCache).should.eql('undefined');
})
})
});
describe('#frameAndSend', function() {
it('does not modify a masked binary buffer', function() {
var sender = new Sender({ write: function() {} });
var buf = new Buffer([1, 2, 3, 4, 5]);
sender.frameAndSend(2, buf, true, true);
buf[0].should.eql(1);
buf[1].should.eql(2);
buf[2].should.eql(3);
buf[3].should.eql(4);
buf[4].should.eql(5);
});
it('does not modify a masked text buffer', function() {
var sender = new Sender({ write: function() {} });
var text = 'hi there';
sender.frameAndSend(1, text, true, true);
text.should.eql('hi there');
});
});
});

@@ -10,16 +10,16 @@ var assert = require('assert')

Validation.isValidUTF8(validBuffer).should.be.ok;
})
});
it('should return false for an erroneous string', function() {
var invalidBuffer = new Buffer([0xce, 0xba, 0xe1, 0xbd, 0xb9, 0xcf, 0x83, 0xce, 0xbc, 0xce, 0xb5, 0xed, 0xa0, 0x80, 0x65, 0x64, 0x69, 0x74, 0x65, 0x64]);
Validation.isValidUTF8(invalidBuffer).should.not.be.ok;
})
});
it('should return true for valid cases from the autobahn test suite', function() {
Validation.isValidUTF8(new Buffer('\xf0\x90\x80\x80')).should.be.ok;
Validation.isValidUTF8(new Buffer([0xf0, 0x90, 0x80, 0x80])).should.be.ok;
})
});
it('should return false for erroneous autobahn strings', function() {
Validation.isValidUTF8(new Buffer([0xce, 0xba, 0xe1, 0xbd])).should.not.be.ok;
})
})
})
});
});
});

@@ -41,3 +41,3 @@ var assert = require('assert')

});
})
})
});
});
var assert = require('assert')
, https = require('https')
, WebSocket = require('../')
, WebSocketServer = require('../').Server
, fs = require('fs')
, server = require('./testserver');
, server = require('./testserver')
, crypto = require('crypto');

@@ -34,5 +37,88 @@ var port = 20000;

}
})
})
});
});
describe('properties', function() {
it('#url exposes the server url', function(done) {
server.createServer(++port, function(srv) {
var url = 'ws://localhost:' + port;
var ws = new WebSocket(url);
assert.equal(url, ws.url);
ws.terminate();
ws.on('close', function() {
srv.close();
done();
});
});
});
describe('#readyState', function() {
it('defaults to connecting', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
assert.equal(WebSocket.CONNECTING, ws.readyState);
ws.terminate();
ws.on('close', function() {
srv.close();
done();
});
});
});
it('set to connected once connection is established', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
ws.on('open', function() {
assert.equal(WebSocket.OPEN, ws.readyState);
srv.close();
done();
});
});
});
it('set to closed once connection is closed', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
ws.close(1001);
ws.on('close', function() {
assert.equal(WebSocket.CLOSED, ws.readyState);
srv.close();
done();
});
});
});
it('set to closed once connection is terminated', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
ws.terminate();
ws.on('close', function() {
assert.equal(WebSocket.CLOSED, ws.readyState);
srv.close();
done();
});
});
});
});
var readyStates = {
CONNECTING: 0,
OPEN: 1,
CLOSING: 2,
CLOSED: 3
};
Object.keys(readyStates).forEach(function(state) {
describe('.' + state, function() {
it('is enumerable and immutable property', function() {
var propertyDescripter = Object.getOwnPropertyDescriptor(WebSocket, state)
assert.equal(readyStates[state], propertyDescripter.value);
assert.equal(false, propertyDescripter.writable);
assert.equal(true, propertyDescripter.enumerable);
assert.equal(false, propertyDescripter.configurable);
});
});
});
});
it('can disconnect before connection is established', function(done) {

@@ -50,3 +136,3 @@ server.createServer(++port, function(srv) {

});
})
});

@@ -65,3 +151,3 @@ it('can close before connection is established', function(done) {

});
})
});

@@ -76,3 +162,3 @@ it('invalid server key is denied', function(done) {

});
})
});

@@ -87,3 +173,3 @@ it('close event is raised when server closes connection', function(done) {

});
})
});

@@ -104,3 +190,3 @@ describe('#ping', function() {

});
})
});

@@ -119,3 +205,3 @@ it('without message is successfully transmitted to the server', function(done) {

});
})
});

@@ -135,3 +221,3 @@ it('with message is successfully transmitted to the server', function(done) {

});
})
});

@@ -152,4 +238,4 @@ it('with encoded message is successfully transmitted to the server', function(done) {

});
})
})
});
});

@@ -169,3 +255,3 @@ describe('#pong', function() {

});
})
});

@@ -185,3 +271,3 @@ it('with message is successfully transmitted to the server', function(done) {

});
})
});

@@ -202,4 +288,4 @@ it('with encoded message is successfully transmitted to the server', function(done) {

});
})
})
});
});

@@ -223,3 +309,3 @@ describe('#send', function() {

});
})
});

@@ -239,3 +325,3 @@ it('can send and receive text data', function(done) {

});
})
});

@@ -258,3 +344,3 @@ it('send and receive binary data as an array', function(done) {

});
})
});

@@ -276,3 +362,3 @@ it('binary data can be sent and received as buffer', function(done) {

});
})
});

@@ -292,3 +378,3 @@ it('before connect should fail', function(done) {

});
})
});

@@ -306,3 +392,3 @@ it('before connect should pass error through callback, if present', function(done) {

});
})
});

@@ -322,3 +408,3 @@ it('without data should be successful', function(done) {

});
})
});

@@ -336,3 +422,3 @@ it('calls optional callback when flushed', function(done) {

});
})
});

@@ -352,3 +438,3 @@ it('with unencoded message is successfully transmitted to the server', function(done) {

});
})
});

@@ -369,3 +455,3 @@ it('with encoded message is successfully transmitted to the server', function(done) {

});
})
});

@@ -388,3 +474,3 @@ it('with unencoded binary message is successfully transmitted to the server', function(done) {

});
})
});

@@ -408,3 +494,3 @@ it('with encoded binary message is successfully transmitted to the server', function(done) {

});
})
});

@@ -434,3 +520,3 @@ it('with binary stream will send fragmented data', function(done) {

});
})
});

@@ -461,3 +547,3 @@ it('with text stream will send fragmented data', function(done) {

});
})
});

@@ -495,3 +581,3 @@ it('will cause intermittent send to be delayed in order', function(done) {

});
})
});

@@ -529,3 +615,3 @@ it('will cause intermittent stream to be delayed in order', function(done) {

});
})
});

@@ -561,3 +647,3 @@ it('will cause intermittent ping to be delivered', function(done) {

});
})
});

@@ -593,3 +679,3 @@ it('will cause intermittent pong to be delivered', function(done) {

});
})
});

@@ -621,4 +707,4 @@ it('will cause intermittent close to be delivered', function(done) {

});
})
})
});
});

@@ -653,3 +739,3 @@ describe('#stream', function() {

});
})
});

@@ -667,3 +753,3 @@ it('before connect should pass error through callback', function(done) {

});
})
});

@@ -685,3 +771,3 @@ it('without callback should fail', function(done) {

});
})
});

@@ -726,3 +812,3 @@ it('will cause intermittent send to be delayed in order', function(done) {

});
})
});

@@ -773,3 +859,3 @@ it('will cause intermittent stream to be delayed in order', function(done) {

});
})
});

@@ -812,3 +898,3 @@ it('will cause intermittent ping to be delivered', function(done) {

});
})
});

@@ -851,3 +937,3 @@ it('will cause intermittent pong to be delivered', function(done) {

});
})
});

@@ -890,4 +976,4 @@ it('will cause intermittent close to be delivered', function(done) {

});
})
})
});
});

@@ -917,3 +1003,3 @@ describe('#close', function() {

});
})
});

@@ -934,3 +1020,3 @@ it('without invalid first argument throws exception', function(done) {

});
})
});

@@ -951,3 +1037,3 @@ it('without reserved error code 1004 throws exception', function(done) {

});
})
});

@@ -967,3 +1053,3 @@ it('without message is successfully transmitted to the server', function(done) {

});
})
});

@@ -984,3 +1070,3 @@ it('with message is successfully transmitted to the server', function(done) {

});
})
});

@@ -1001,3 +1087,3 @@ it('with encoded message is successfully transmitted to the server', function(done) {

});
})
});

@@ -1019,4 +1105,4 @@ it('ends connection to the server', function(done) {

});
})
})
});
});

@@ -1081,6 +1167,111 @@ describe('API emulation', function() {

});
})
});
});
});
})
})
});
describe('ssl', function() {
it('can connect to secure websocket server', function(done) {
var options = {
key: fs.readFileSync('test/fixtures/key.pem'),
cert: fs.readFileSync('test/fixtures/certificate.pem')
};
var app = https.createServer(options, function (req, res) {
res.writeHead(200);
res.end();
});
var wss = new WebSocketServer({server: app});
app.listen(++port, function() {
var ws = new WebSocket('wss://localhost:' + port);
});
wss.on('connection', function(ws) {
app.close();
ws.terminate();
wss.close();
done();
});
});
it('cannot connect to secure websocket server via ws://', function(done) {
var options = {
key: fs.readFileSync('test/fixtures/key.pem'),
cert: fs.readFileSync('test/fixtures/certificate.pem')
};
var app = https.createServer(options, function (req, res) {
res.writeHead(200);
res.end();
});
var wss = new WebSocketServer({server: app});
app.listen(++port, function() {
var ws = new WebSocket('ws://localhost:' + port);
ws.on('error', function() {
app.close();
ws.terminate();
wss.close();
done();
});
});
});
it('can send and receive text data', function(done) {
var options = {
key: fs.readFileSync('test/fixtures/key.pem'),
cert: fs.readFileSync('test/fixtures/certificate.pem')
};
var app = https.createServer(options, function (req, res) {
res.writeHead(200);
res.end();
});
var wss = new WebSocketServer({server: app});
app.listen(++port, function() {
var ws = new WebSocket('wss://localhost:' + port);
ws.on('open', function() {
ws.send('foobar');
});
});
wss.on('connection', function(ws) {
ws.on('message', function(message, flags) {
message.should.eql('foobar');
app.close();
ws.terminate();
wss.close();
done();
});
});
});
it('can send and receive very long binary data', function(done) {
var options = {
key: fs.readFileSync('test/fixtures/key.pem'),
cert: fs.readFileSync('test/fixtures/certificate.pem')
}
var app = https.createServer(options, function (req, res) {
res.writeHead(200);
res.end();
});
crypto.randomBytes(5 * 1024 * 1024, function(ex, buf) {
if (ex) throw ex;
var wss = new WebSocketServer({server: app});
app.listen(++port, function() {
var ws = new WebSocket('wss://localhost:' + port);
ws.on('open', function() {
ws.send(buf, {binary: true});
});
ws.on('message', function(message, flags) {
flags.binary.should.be.ok;
areArraysEqual(buf, message).should.be.ok;
app.close();
ws.terminate();
wss.close();
done();
});
});
wss.on('connection', function(ws) {
ws.on('message', function(message, flags) {
ws.send(message, {binary: true});
});
});
});
});
});
});

@@ -38,3 +38,3 @@ var assert = require('assert')

gotException.should.be.ok;
})
});

@@ -50,8 +50,8 @@ it('throws an error if no port or server is specified', function() {

gotException.should.be.ok;
})
});
it('emits an error if http server bind fails', function(done) {
var wss = new WebSocketServer({port: 1});
wss.on('error', function() { done(); })
})
wss.on('error', function() { done(); });
});

@@ -72,3 +72,3 @@ it('uses passed server object', function () {

});
})
});

@@ -86,3 +86,3 @@ it('works with a precreated http server', function (done) {

});
})
});

@@ -112,3 +112,3 @@ it('can have two different instances listening on the same http server with two different paths', function(done) {

});
})
});

@@ -126,4 +126,4 @@ it('cannot have two different instances listening on the same http server with two different paths', function(done) {

});
})
})
});
});

@@ -145,3 +145,3 @@ describe('#close', function() {

});
})
});

@@ -164,3 +164,3 @@ it('does not close a precreated server', function(done) {

});
})
});

@@ -181,4 +181,4 @@ it('cleans up websocket data on a precreated server', function(done) {

});
})
})
});
});

@@ -204,3 +204,3 @@ it('does not accept connections with no sec-websocket-key', function(done) {

wss.on('error', function() {});
})
});

@@ -227,3 +227,3 @@ it('does not accept connections with no sec-websocket-version', function(done) {

wss.on('error', function() {});
})
});

@@ -251,3 +251,3 @@ it('does not accept connections with invalid sec-websocket-version', function(done) {

wss.on('error', function() {});
})
});

@@ -279,3 +279,3 @@ it('does not accept connections with invalid sec-websocket-origin (8)', function(done) {

wss.on('error', function() {});
})
});

@@ -307,3 +307,3 @@ it('does not accept connections with invalid origin', function(done) {

wss.on('error', function() {});
})
});

@@ -322,25 +322,38 @@ it('can send data', function(done) {

});
})
});
it('tracks and exposes the client protocol', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port, {protocol: 'hi'});
describe('properties', function() {
it('protocol is exposed', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port, {protocol: 'hi'});
});
wss.on('connection', function(client) {
client.protocol.should.eql('hi');
wss.close();
done();
});
});
wss.on('connection', function(client) {
client.protocol.should.eql('hi');
it('protocolVersion is exposed', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port, {protocolVersion: 8});
});
wss.on('connection', function(client) {
client.protocolVersion.should.eql(8);
wss.close();
done();
});
});
})
it('tracks and exposes the client protocolVersion', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port, {protocolVersion: 8});
});
wss.on('connection', function(client) {
client.protocolVersion.should.eql(8);
it('upgradeReq is the original request object', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port, {protocolVersion: 8});
});
wss.on('connection', function(client) {
client.upgradeReq.httpVersion.should.eql('1.1');
wss.close();
done();
});
});
})
});

@@ -358,3 +371,3 @@ describe('#clients', function() {

});
})
});

@@ -374,3 +387,3 @@ it('is updated when client terminates the connection', function(done) {

});
})
});

@@ -390,5 +403,5 @@ it('is updated when client closes the connection', function(done) {

});
})
})
})
});
});
});

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