Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

websocket

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

binding.gyp

2

lib/websocket.js

@@ -9,3 +9,3 @@ module.exports = {

"constants" : require('./Constants'),
"version" : "1.0.4"
"version" : "1.0.5"
};

@@ -529,8 +529,8 @@ /************************************************************************

WebSocketConnection.prototype.send = function(data) {
WebSocketConnection.prototype.send = function(data, cb) {
if (Buffer.isBuffer(data)) {
this.sendBytes(data);
this.sendBytes(data, cb);
}
else if (typeof(data['toString']) === 'function') {
this.sendUTF(data);
this.sendUTF(data, cb);
}

@@ -542,10 +542,10 @@ else {

WebSocketConnection.prototype.sendUTF = function(data) {
WebSocketConnection.prototype.sendUTF = function(data, cb) {
var frame = new WebSocketFrame(this.maskBytes, this.frameHeader, this.config);
frame.opcode = 0x01; // WebSocketOpcode.TEXT_FRAME
frame.binaryPayload = new Buffer(data.toString(), 'utf8');
this.fragmentAndSend(frame);
this.fragmentAndSend(frame, cb);
};
WebSocketConnection.prototype.sendBytes = function(data) {
WebSocketConnection.prototype.sendBytes = function(data, cb) {
if (!Buffer.isBuffer(data)) {

@@ -557,3 +557,3 @@ throw new Error("You must pass a Node Buffer object to WebSocketConnection.prototype.sendBytes()");

frame.binaryPayload = data;
this.fragmentAndSend(frame);
this.fragmentAndSend(frame, cb);
};

@@ -592,3 +592,3 @@

WebSocketConnection.prototype.fragmentAndSend = function(frame) {
WebSocketConnection.prototype.fragmentAndSend = function(frame, cb) {
if (frame.opcode > 0x07) {

@@ -603,2 +603,17 @@ throw new Error("You cannot fragment control frames.");

var numFragments = Math.ceil(length / threshold);
var sentFragments = 0;
var sentCallback = function (err) {
if (err) {
if (typeof cb === 'function') {
// pass only the first error
cb(err);
cb = null;
}
return;
}
++sentFragments;
if ((typeof cb === 'function') && (sentFragments === numFragments)) {
cb();
}
}
for (var i=1; i <= numFragments; i++) {

@@ -620,3 +635,3 @@ var currentFrame = new WebSocketFrame(this.maskBytes, this.frameHeader, this.config);

this.sendFrame(currentFrame);
this.sendFrame(currentFrame, sentCallback);
}

@@ -626,3 +641,3 @@ }

frame.fin = true;
this.sendFrame(frame);
this.sendFrame(frame, cb);
}

@@ -646,6 +661,10 @@ };

WebSocketConnection.prototype.sendFrame = function(frame, force) {
WebSocketConnection.prototype.sendFrame = function(frame, force, cb) {
if (typeof force === 'function') {
cb = force;
force = false;
}
frame.mask = this.maskOutgoingPackets;
var buffer = frame.toBuffer();
this.outgoingFrameQueue.unshift(buffer);
this.outgoingFrameQueue.unshift([buffer, cb]);
this.bytesWaitingToFlush += buffer.length;

@@ -658,9 +677,21 @@ if (!this.outputPaused || force) {

WebSocketConnection.prototype.processOutgoingFrameQueue = function() {
if (this.outputPaused || !this.connected) { return; }
if (this.outputPaused) { return; }
if (this.outgoingFrameQueue.length > 0) {
var buffer = this.outgoingFrameQueue.pop();
var current = this.outgoingFrameQueue.pop();
var buffer = current[0];
var cb = current[1];
// there is no need to accumulate messages in the queue if connection closed
// connection will not be restored and messages will never be sent
// therefore, notify callbacks about it
if (!this.connected && (typeof cb === 'function')) {
cb("Connection closed");
return;
}
try {
var flushed = this.socket.write(buffer);
var flushed = this.socket.write(buffer, cb);
}
catch(e) {
if (typeof cb === 'function') {
cb(e.toString());
}
if (this.listeners('error').length > 0) {

@@ -667,0 +698,0 @@ this.emit("error", "Error while writing to socket: " + e.toString());

@@ -240,3 +240,3 @@ /************************************************************************

output = new Buffer(this.length + headerLength + (this.mask ? 4 : 0));
var output = new Buffer(this.length + headerLength + (this.mask ? 4 : 0));

@@ -243,0 +243,0 @@ // write the frame header

@@ -6,3 +6,3 @@ {

"author": "Brian McKelvey <brian@worlize.com>",
"version": "1.0.4",
"version": "1.0.5",
"repository": {

@@ -13,6 +13,8 @@ "type": "git",

"engines": {
"node": ">=0.4.7"
"node": ">=0.6.0"
},
"scripts": {
"preinstall": "make validator"
"preinstall": "node-gyp configure",
"install": "node-gyp build",
"preuninstall": "node-gyp clean"
},

@@ -19,0 +21,0 @@ "main": "index",

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