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.3.6 to 0.3.7

.npmignore

8

History.md

@@ -1,4 +0,10 @@

v0.3.6 - Dec 15th 2011
v0.3.7 - Dec 25nd 2011
======================
* Added a browser based API which uses EventEmitters internally [3rd-Eden]
* Expose request information from upgrade event for websocket server clients [mmalecki]
v0.3.6 - Dec 19th 2011
======================
* Added option to let WebSocket.Server use an already existing http server [mmalecki]

@@ -5,0 +11,0 @@ * Migrating various option structures to use options.js module [einaros]

10

lib/BufferPool.js

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

if (this._buffer == null || this._offset + length > this._buffer.length) {
// detaches previous buffer, activates a new area
// may cause leak-like effects, although not actually to be considered leaks
// ideally the allocation should check a map of vacant slots, so that detached
// buffers still are useful
var newBuf = new Buffer(this._growStrategy(length));

@@ -52,5 +48,5 @@ this._buffer = newBuf;

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

@@ -60,2 +56,2 @@ this._used = 0;

module.exports = BufferPool;
module.exports = BufferPool;

@@ -33,6 +33,7 @@ /*!

this.overflow = [];
var prevUsed = -1;
this.bufferPool = new BufferPool(1024, function(db, length) {
return db.used + length;
}, function(db) {
return db.prevUsed = (typeof db.prevUsed == 'undefined' ? (db.prevUsed + db.used) / 2 : db.used);
return prevUsed = prevUsed >= 0 ? (prevUsed + db.used) / 2 : db.used;
});

@@ -39,0 +40,0 @@ this.expectOffset = 0;

@@ -38,8 +38,20 @@ /*!

}).merge(options);
// Exposed properties
Object.defineProperty(this, 'protocol', {
value: options.value.protocol
value: options.value.protocol,
configurable: false,
enumerable: true
});
Object.defineProperty(this, 'protocolVersion', {
value: options.value.protocolVersion
value: options.value.protocolVersion,
configurable: false,
enumerable: true
});
Object.defineProperty(this, 'upgradeReq', {
value: address[0],
configurable: false,
enumerable: true
});
this._state = 'connecting';

@@ -56,3 +68,3 @@ this._isServer = true;

*/
this._isServer = false;

@@ -143,2 +155,7 @@

}
Object.defineProperty(this, 'state', {
value: this._state,
configurable: false,
enumerable: true
});
}

@@ -241,7 +258,4 @@

sendStream(this, data, options, function(error) {
if (typeof cb == 'function') {
cb(error);
return;
}
executeQueueSends(self);
process.nextTick(function() { executeQueueSends(self); });
if (typeof cb == 'function') cb(error);
});

@@ -310,4 +324,55 @@ }

}
}
};
/**
* Emulates the Browser based WebSocket interface.
*
* @see http://dev.w3.org/html5/websockets/#the-websocket-interface
* @api public
*/
['open', 'error', 'close', 'message'].forEach(function(method) {
Object.defineProperty(WebSocket.prototype, 'on' + method, {
/**
* Returns the current listener
*
* @returns {Mixed} the set function or undefined
* @api public
*/
get: function get() {
var listener = this.listeners(method)[0];
return listener ? (listener._listener ? listener._listener : listener) : undefined;
},
/**
* Start listening for events
*
* @param {Function} listener the listener
* @returns {Mixed} the set function or undefined
* @api public
*/
set: function set(listener) {
this.removeAllListeners(method);
if (typeof listener === 'function') {
// Special case for messages as we need to wrap the response here to
// emulate a WebSocket event response.
if (method === 'message') {
function message (data) {
listener.call(this, { data: data });
}
// store a reference so we can return the origional function again
message._listener = listener;
this.on(method, message);
} else {
this.on(method, listener);
}
}
}
});
});
module.exports = WebSocket;

@@ -314,0 +379,0 @@

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

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

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

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

srv.close();
done();
done();
});

@@ -603,3 +603,3 @@ });

srv.close();
done();
done();
});

@@ -935,2 +935,63 @@ });

})
describe('API emulation', function() {
it('should not throw errors when getting and setting', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
var listener = function () {};
ws.onmessage = listener;
ws.onerror = listener;
ws.onclose = listener;
ws.onopen = listener;
assert.ok(ws.onopen === listener);
assert.ok(ws.onmessage === listener);
assert.ok(ws.onclose === listener);
assert.ok(ws.onerror === listener);
srv.close();
ws.terminate();
done();
});
});
it('should work the same as the EventEmitter api', function(done) {
server.createServer(++port, function(srv) {
var ws = new WebSocket('ws://localhost:' + port);
var listener = function() {};
var message = 0;
var close = 0;
var open = 0;
ws.onmessage = function(data) {
assert.ok(!!data.data);
++message;
ws.close();
};
ws.onopen = function() {
++open;
}
ws.onclose = function() {
++close;
}
ws.on('open', function() {
ws.send('foo');
});
ws.on('close', function() {
process.nextTick(function() {
assert.ok(message === 1);
assert.ok(open === 1);
assert.ok(close === 1);
srv.close();
ws.terminate();
done();
});
})
});
});
})
})

Sorry, the diff of this file is not supported yet

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