Comparing version 0.0.12 to 0.0.13
@@ -24,3 +24,4 @@ function Whiteboard(canvasId) { | ||
this.socket = new WebSocket(url, 'whiteboard-example'); | ||
var wsCtor = MozWebSocket ? MozWebSocket : WebSocket; | ||
this.socket = new wsCtor(url, 'whiteboard-example'); | ||
@@ -27,0 +28,0 @@ this.socket.onmessage = this.handleWebsocketMessage.bind(this); |
@@ -7,3 +7,3 @@ module.exports = { | ||
"request" : require('./WebSocketRequest'), | ||
"version" : "0.0.12" | ||
"version" : "0.0.13" | ||
}; |
@@ -32,3 +32,2 @@ var crypto = require('crypto'); | ||
this.currentFrame = new WebSocketFrame(this.maskBytes, this.frameHeader, this.config); | ||
this.fragmentationOpcode = 0; | ||
this.fragmentationSize = 0; // data received so far... | ||
@@ -102,2 +101,8 @@ this.frameQueue = []; | ||
// For now since we don't support extensions, all RSV bits are illegal | ||
if (this.currentFrame.rsv1 || this.currentFrame.rsv2 || this.currentFrame.rsv3) { | ||
this.drop(WebSocketConnection.CLOSE_REASON_PROTOCOL_ERROR, | ||
"Unsupported usage of rsv bits without negotiated extension."); | ||
} | ||
if (!this.assembleFragments) { | ||
@@ -198,2 +203,11 @@ this.emit('frame', this.currentFrame); | ||
// Any non-control opcode besides 0x00 (continuation) received in the | ||
// middle of a fragmented message is illegal. | ||
if (this.frameQueue.length !== 0 && (frame.opcode > 0x00 && frame.opcode < 0x08)) { | ||
this.drop(WebSocketConnection.CLOSE_REASON_PROTOCOL_ERROR, | ||
"Illegal frame opcode 0x" + frame.opcode.toString(16) + " " + | ||
"received in middle of fragmented message."); | ||
return; | ||
} | ||
switch(frame.opcode) { | ||
@@ -209,13 +223,7 @@ case 0x02: // WebSocketFrame.BINARY_FRAME | ||
} | ||
else if (this.frameQueue.length === 0) { | ||
else { | ||
// beginning of a fragmented message | ||
this.frameQueue.push(frame); | ||
this.fragmentationOpcode = frame.opcode; | ||
this.fragmentationSize = frame.length; | ||
} | ||
else { | ||
this.drop(WebSocketConnection.CLOSE_REASON_PROTOCOL_ERROR, | ||
"Illegal BINARY_FRAME received in the middle of a fragmented message. Expected a continuation or control frame."); | ||
return; | ||
} | ||
} | ||
@@ -232,14 +240,6 @@ break; | ||
} | ||
else if (this.frameQueue.length === 0) { | ||
if (this.assembleFragments) { | ||
// beginning of a fragmented message | ||
this.frameQueue.push(frame); | ||
this.fragmentationOpcode = frame.opcode; | ||
this.fragmentationSize = frame.length; | ||
} | ||
} | ||
else { | ||
this.drop(WebSocketConnection.CLOSE_REASON_PROTOCOL_ERROR, | ||
"Illegal TEXT_FRAME received in the middle of a fragmented message. Expected a continuation or control frame."); | ||
return; | ||
// beginning of a fragmented message | ||
this.frameQueue.push(frame); | ||
this.fragmentationSize = frame.length; | ||
} | ||
@@ -250,3 +250,3 @@ } | ||
if (this.assembleFragments) { | ||
if (this.fragmentationOpcode === 0x00 && frame.opcode === 0x00) { | ||
if (this.frameQueue.length === 0) { | ||
this.drop(WebSocketConnection.CLOSE_REASON_PROTOCOL_ERROR, | ||
@@ -253,0 +253,0 @@ "Unexpected Continuation Frame"); |
@@ -22,2 +22,3 @@ var ctio = require('../vendor/node-ctype/ctio-faster'); | ||
this.parseState = DECODE_HEADER; | ||
this.closeStatus = -1; | ||
}; | ||
@@ -43,2 +44,16 @@ | ||
// Control frame sanity check | ||
if (this.opcode >= 0x08) { | ||
if (this.length > 125) { | ||
this.protocolError = true; | ||
this.dropReason = "Illegal control frame longer than 125 bytes." | ||
return true; | ||
} | ||
if (!this.fin) { | ||
this.protocolError = true; | ||
this.dropReason = "Control frames must not be fragmented."; | ||
return true; | ||
} | ||
} | ||
if (this.length === 126) { | ||
@@ -45,0 +60,0 @@ this.parseState = WAITING_FOR_16_BIT_LENGTH; |
@@ -6,3 +6,3 @@ { | ||
"author": "Brian McKelvey <brian@worlize.com>", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -8,2 +8,4 @@ WebSocket Client & Server Implementation for Node | ||
***If you need to simultaneously support older production browser versions that had implemented draft-75/draft-76/draft-00, take a look here: https://gist.github.com/1148686*** | ||
Overview | ||
@@ -132,3 +134,5 @@ -------- | ||
connection.on('message', function(message) { | ||
console.log("Received: '" + message.utf8Data + "'"); | ||
if (message.type === 'utf8') { | ||
console.log("Received: '" + message.utf8Data + "'"); | ||
} | ||
}); | ||
@@ -135,0 +139,0 @@ |
@@ -8,2 +8,20 @@ #!/usr/bin/env node | ||
var args = { /* defaults */ | ||
port: '8080' | ||
}; | ||
/* Parse command line options */ | ||
var pattern = /^--(.*?)(?:=(.*))?$/; | ||
process.argv.forEach(function(value) { | ||
var match = pattern.exec(value); | ||
if (match) { | ||
args[match[1]] = match[2] ? match[2] : true; | ||
} | ||
}); | ||
var port = parseInt(args.port, 10); | ||
console.log("WebSocket-Node: echo-server"); | ||
console.log("Usage: ./echo-server.js [--port=8080]"); | ||
var server = http.createServer(function(request, response) { | ||
@@ -14,4 +32,4 @@ console.log((new Date()) + " Received request for " + request.url); | ||
}); | ||
server.listen(8080, function() { | ||
console.log((new Date()) + " Server is listening on port 8080"); | ||
server.listen(port, function() { | ||
console.log((new Date()) + " Server is listening on port " + port); | ||
}); | ||
@@ -21,3 +39,8 @@ | ||
httpServer: server, | ||
autoAcceptConnections: true | ||
autoAcceptConnections: true, | ||
maxReceivedFrameSize: 64*1024*1024, // 64MiB | ||
maxReceivedMessageSize: 64*1024*1024, // 64MiB | ||
fragmentOutgoingMessages: false, | ||
keepalive: false, | ||
disableNagleAlgorithm: false | ||
}); | ||
@@ -29,3 +52,3 @@ | ||
if (message.type === 'utf8') { | ||
console.log("Received Message: " + message.utf8Data); | ||
console.log("Received utf-8 message of " + message.utf8Data.length + " characters."); | ||
connection.sendUTF(message.utf8Data); | ||
@@ -32,0 +55,0 @@ } |
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
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
264538
6933
164