Skip to content
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

upgrade to ws@7 #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"relative-url": "^1.0.2",
"safe-buffer": "^5.1.1",
"ws": "^1.1.0"
"ws": "^7.0.0"
},
"devDependencies": {
"mapleTree": "^0.5.1",
Expand Down
12 changes: 3 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var ws = require('./')
var WebSocket = require('ws')
var url = require('url')
var http = require('http')
var https = require('https')

Expand All @@ -25,7 +24,7 @@ module.exports = !WebSocket.Server ? null : function (opts, onConnection) {
})
}

var server = opts.server ||
server = opts.server ||
(opts.key && opts.cert ? https.createServer(opts) : http.createServer())

var wsServer = new WebSocket.Server({
Expand All @@ -38,9 +37,9 @@ module.exports = !WebSocket.Server ? null : function (opts, onConnection) {
proxy(server, 'request')
proxy(server, 'close')

wsServer.on('connection', function (socket) {
wsServer.on('connection', function (socket, req) {
var stream = ws(socket)
stream.remoteAddress = socket.upgradeReq.socket.remoteAddress
stream.remoteAddress = req.connection.remoteAddress
emitter.emit('connection', stream)
})

Expand All @@ -60,8 +59,3 @@ module.exports = !WebSocket.Server ? null : function (opts, onConnection) {
emitter.address = server.address.bind(server)
return emitter
}





7 changes: 2 additions & 5 deletions test/error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var test = require('tape');
var WebSocket = require('ws');
var endpoint = require('./helpers/wsurl') + '/read';
var pull = require('pull-stream');
var ws = require('../');

Expand All @@ -14,21 +13,20 @@ test('test error', function (t) {
pull.values(['x', 'y', 'z']),
pull.through(null, function (err) {
if(_err) {
t.strictEqual(err, _err);
t.deepEqual(err, _err);
t.end();
}
_err = err
}),
ws(new WebSocket('ws://localhost:34897/' + Math.random())),
pull.collect(function (err) {
if(_err) {
t.strictEqual(err, _err);
christianbundy marked this conversation as resolved.
Show resolved Hide resolved
t.deepEqual(err, _err);
t.end();
}
_err = err
})
)

})

//connect to a server that does not exist, and check that it errors.
Expand All @@ -44,7 +42,6 @@ test('test error', function (t) {

})


test('close', function (t) {
server.close()
t.end()
Expand Down
8 changes: 4 additions & 4 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var mapleTree = require('mapleTree');
var port = process.env.ZUUL_PORT || process.env.PORT || 3000;

module.exports = function () {
var router = new mapleTree.RouteTree();
var wss = new WebSocketServer({ port: port });
var router = new mapleTree.RouteTree();
var wss = new WebSocketServer({ port: port });

router.define('/read', function(ws) {
var values = ['a', 'b', 'c', 'd'];
Expand All @@ -27,8 +27,8 @@ var wss = new WebSocketServer({ port: port });
});
});

wss.on('connection', function(ws) {
var match = router.match(ws.upgradeReq.url);
wss.on('connection', function(ws, req) {
var match = router.match(req.url);
if (match && typeof match.fn == 'function') {
match.fn(ws);
}
Expand Down