Comparing version 1.0.4 to 1.0.5
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
416288
89
7157
2
143
21
13