-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bumped ws to v2.0.0. #106
Bumped ws to v2.0.0. #106
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict' | ||
|
||
var http = require('http') | ||
var websocket = require('./') | ||
var server = null | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
var Server = require('./server.js') | ||
var server = require('./server.js') | ||
|
||
module.exports = require('./stream.js') | ||
module.exports.Server = Server | ||
module.exports.createServer = Server | ||
module.exports.Server = server.Server | ||
module.exports.createServer = server.createServer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
'use strict' | ||
|
||
var inherits = require('inherits') | ||
var WebSocketServer = require('ws').Server | ||
var stream = require('./stream') | ||
|
||
module.exports = Server | ||
|
||
function Server(opts, cb) { | ||
if (!(this instanceof Server)) { | ||
return new Server(opts, cb) | ||
} | ||
|
||
WebSocketServer.call(this, opts) | ||
|
||
var proxied = false | ||
this.on('newListener', function(event) { | ||
if (!proxied && event === 'stream') { | ||
proxied = true | ||
this.on('connection', function(conn) { | ||
this.emit('stream', stream(conn, opts)) | ||
}) | ||
class Server extends WebSocketServer{ | ||
constructor(opts, cb) { | ||
super(opts) | ||
|
||
var proxied = false | ||
this.on('newListener', function(event) { | ||
if (!proxied && event === 'stream') { | ||
proxied = true | ||
this.on('connection', function(conn) { | ||
this.emit('stream', stream(conn, opts)) | ||
}) | ||
} | ||
}) | ||
|
||
if (cb) { | ||
this.on('stream', cb) | ||
} | ||
}) | ||
|
||
if (cb) { | ||
this.on('stream', cb) | ||
} | ||
} | ||
|
||
inherits(Server, WebSocketServer) | ||
|
||
module.exports.Server = Server | ||
module.exports.createServer = function(opts, cb) { | ||
return new Server(opts, cb) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,13 @@ function WebSocketStream(target, protocols, options) { | |
var coerceToBuffer = options.binary || options.binary === undefined | ||
|
||
function socketWriteNode(chunk, enc, next) { | ||
// avoid errors, this never happens unless | ||
// destroy() is called | ||
if (socket.readyState !== WS.OPEN) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I thought this has nothing to do diff --git a/test.js b/test.js
index 18caa28..a0b10af 100644
--- a/test.js
+++ b/test.js
@@ -99,7 +99,9 @@ test('drain', function(t) {
t.plan(1)
echo.start(function() {
- var client = websocket(echo.url, echo.options)
+ var client = websocket(echo.url, {
+ perMessageDeflate: false
+ })
client.on('drain', function() {
client.destroy() In The problem with the "drain" test is that a single data chunk arrives on the server with many binary frames and a close frame. All frames are parsed on the same tick and when the close frame is processed, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. |
||
next() | ||
return | ||
} | ||
|
||
if (coerceToBuffer && typeof chunk === 'string') { | ||
chunk = new Buffer(chunk, 'utf8') | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might makes sense to show how to disable it on the client (it's the same) as
websocket-stream
could be used only as a client.