Socket
Socket
Sign inDemoInstall

websocket-driver

Package Overview
Dependencies
1
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.4 to 0.6.0

lib/websocket/driver/stream_reader.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

### 0.6.0 / 2015-07-08
* Allow the parser to recover cleanly if event listeners raise an error
* Add a `pong` method for sending unsolicited pong frames
### 0.5.4 / 2015-03-29

@@ -2,0 +7,0 @@

8

lib/websocket/driver/base.js

@@ -6,3 +6,4 @@ 'use strict';

streams = require('../streams'),
Headers = require('./headers');
Headers = require('./headers'),
Reader = require('./stream_reader');

@@ -14,2 +15,3 @@ var Base = function(request, url, options) {

this._request = request;
this._reader = new Reader();
this._options = options || {};

@@ -101,2 +103,6 @@ this._maxLength = this._options.maxLength || this.MAX_LENGTH;

pong: function() {
return false;
},
close: function(reason, code) {

@@ -103,0 +109,0 @@ if (this.readyState !== 1) return false;

2

lib/websocket/driver/client.js

@@ -82,4 +82,4 @@ 'use strict';

message = 'Error during WebSocket handshake: ' + message;
this.readyState = 3;
this.emit('error', new Error(message));
this.readyState = 3;
this.emit('close', new Base.CloseEvent(this.ERRORS.protocol_error, message));

@@ -86,0 +86,0 @@ },

@@ -29,6 +29,7 @@ 'use strict';

var data, message, value;
for (var i = 0, n = buffer.length; i < n; i++) {
data = buffer[i];
this._reader.put(buffer);
this._reader.eachByte(function(data) {
var message, value;
switch (this._stage) {

@@ -64,5 +65,5 @@ case -1:

if (data === 0xFF) {
this._stage = 0;
message = new Buffer(this._buffer).toString('utf8', 0, this._buffer.length);
this.emit('message', new Base.MessageEvent(message));
this._stage = 0;
}

@@ -81,3 +82,3 @@ else {

}
}
}, this);
},

@@ -84,0 +85,0 @@

@@ -8,4 +8,3 @@ 'use strict';

Frame = require('./hybi/frame'),
Message = require('./hybi/message'),
Reader = require('./hybi/stream_reader');
Message = require('./hybi/message');

@@ -16,3 +15,2 @@ var Hybi = function(request, url, options) {

this._extensions = new Extensions();
this._reader = new Reader();
this._stage = 0;

@@ -138,4 +136,4 @@ this._masking = this._options.masking;

if (buffer) {
this._stage = 4;
this._frame.maskingKey = buffer;
this._stage = 4;
}

@@ -147,4 +145,4 @@ break;

if (buffer) {
this._stage = 0;
this._emitFrame(buffer);
this._stage = 0;
}

@@ -176,2 +174,8 @@ break;

pong: function(message) {
if (this.readyState > 1) return false;
message = message ||'';
return this.frame(message, 'pong');
},
close: function(reason, code) {

@@ -303,9 +307,9 @@ reason = reason || '';

_shutdown: function(code, reason) {
_shutdown: function(code, reason, error) {
delete this._frame;
delete this._message;
this._stage = 5;
var sendCloseFrame = (this.readyState === 1);
this.readyState = 2;
this._stage = 5;

@@ -315,2 +319,3 @@ this._extensions.close(function() {

this.readyState = 3;
if (error) this.emit('error', new Error(reason));
this.emit('close', new Base.CloseEvent(code, reason));

@@ -322,4 +327,3 @@ }, this);

if (this.readyState > 1) return;
this.emit('error', new Error(message));
this._shutdown(this.ERRORS[type], message);
this._shutdown(this.ERRORS[type], message, true);
},

@@ -340,2 +344,4 @@

this._stage = 1;
if (!this._extensions.validFrameRsv(frame))

@@ -355,4 +361,2 @@ return this._fail('protocol_error',

return this._fail('protocol_error', 'Received new data frame but previous continuous frame is unfinished');
this._stage = 1;
},

@@ -362,16 +366,15 @@

var frame = this._frame;
frame.masked = (data & this.MASK) === this.MASK;
if (this._requireMasking && !frame.masked)
return this._fail('unacceptable', 'Received unmasked frame but masking is required');
frame.length = (data & this.LENGTH);
if (frame.length >= 0 && frame.length <= 125) {
this._stage = frame.masked ? 3 : 4;
if (!this._checkFrameLength()) return;
this._stage = frame.masked ? 3 : 4;
} else {
this._stage = 2;
frame.lengthBytes = (frame.length === 126 ? 2 : 8);
this._stage = 2;
}
if (this._requireMasking && !frame.masked)
return this._fail('unacceptable', 'Received unmasked frame but masking is required');
},

@@ -383,2 +386,4 @@

this._stage = frame.masked ? 3 : 4;
if (this.MESSAGE_OPCODES.indexOf(frame.opcode) < 0 && frame.length > 125)

@@ -388,4 +393,2 @@ return this._fail('protocol_error', 'Received control frame having too long payload: ' + frame.length);

if (!this._checkFrameLength()) return;
this._stage = frame.masked ? 3 : 4;
},

@@ -392,0 +395,0 @@

@@ -6,2 +6,3 @@ 'use strict';

util = require('util'),
Base = require('./base'),
Headers = require('./headers'),

@@ -73,3 +74,3 @@ HttpParser = require('../http_parser');

if (this.statusCode === 200) {
this.emit('connect');
this.emit('connect', new Base.ConnectEvent());
} else {

@@ -76,0 +77,0 @@ var message = "Can't establish a connection to the server at " + this._origin.href;

@@ -8,3 +8,3 @@ { "name" : "websocket-driver"

, "version" : "0.5.4"
, "version" : "0.6.0"
, "engines" : {"node": ">=0.6.0"}

@@ -11,0 +11,0 @@ , "main" : "./lib/websocket/driver"

@@ -24,3 +24,3 @@ # websocket-driver [![Build Status](https://travis-ci.org/faye/websocket-driver-node.svg)](https://travis-ci.org/faye/websocket-driver-node)

* Recombine fragmented messages
* Dispatch text, binary, ping and close frames
* Dispatch text, binary, ping, pong and close frames
* Manage the socket-closing handshake process

@@ -263,7 +263,7 @@ * Automatically reply to ping frames with a matching pong

Sets the callback to execute when the socket becomes open.
Adds a callback to execute when the socket becomes open.
#### `driver.on('message', function(event) {})`
Sets the callback to execute when a message is received. `event` will have a
Adds a callback to execute when a message is received. `event` will have a
`data` attribute containing either a string in the case of a text message or a

@@ -277,3 +277,3 @@ `Buffer` in the case of a binary message.

Sets the callback to execute when a protocol error occurs due to the other peer
Adds a callback to execute when a protocol error occurs due to the other peer
sending an invalid byte sequence. `event` will have a `message` attribute

@@ -284,3 +284,3 @@ describing the error.

Sets the callback to execute when the socket becomes closed. The `event` object
Adds a callback to execute when the socket becomes closed. The `event` object
has `code` and `reason` attributes.

@@ -337,2 +337,11 @@

#### `driver.pong(string = '')`
Sends a pong frame over the socket, queueing it if necessary. `string` is
optional. Returns `false` if frames can no longer be sent, or if the driver does
not support ping/pong.
You don't need to call this when a ping frame is received; pings are replied to
automatically by the driver. This method is for sending unsolicited pongs.
#### `driver.close()`

@@ -339,0 +348,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc