diff --git a/package.json b/package.json index 0c3aaa85..46d7e1fe 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "standard": "^14.3.1", "tap": "^14.10.6", "typescript": "^3.7.5", - "websocket-stream": "^5.5.0" + "ws": "^7.2.1" }, "dependencies": { "aedes-packet": "^2.1.0", diff --git a/test/connect.js b/test/connect.js index d3ac71e5..c1d76ab8 100644 --- a/test/connect.js +++ b/test/connect.js @@ -2,13 +2,12 @@ const { test } = require('tap') const http = require('http') -const ws = require('websocket-stream') const mqtt = require('mqtt') const mqttPacket = require('mqtt-packet') const net = require('net') const proxyProtocol = require('proxy-protocol-js') const { protocolDecoder } = require('aedes-protocol-decoder') -const { setup, connect, delay } = require('./helper') +const { setup, connect, delay, createWebsocketServer } = require('./helper') const aedes = require('../') ;[{ ver: 3, id: 'MQIsdp' }, { ver: 4, id: 'MQTT' }].forEach(function (ele) { @@ -537,9 +536,7 @@ test('websocket clients have access to the request object', function (t) { }) const server = http.createServer() - ws.createServer({ - server: server - }, broker.handle) + createWebsocketServer(server, broker) server.listen(port, function (err) { t.error(err, 'no error') @@ -796,9 +793,7 @@ test('websocket clients have access to the ipAddress from the socket (if no ip h }) const server = http.createServer() - ws.createServer({ - server: server - }, broker.handle) + createWebsocketServer(server, broker) server.listen(port, function (err) { t.error(err, 'no error') @@ -833,9 +828,7 @@ test('websocket proxied clients have access to the ipAddress from x-real-ip head }) const server = http.createServer() - ws.createServer({ - server: server - }, broker.handle) + createWebsocketServer(server, broker) server.listen(port, function (err) { t.error(err, 'no error') @@ -876,9 +869,7 @@ test('websocket proxied clients have access to the ipAddress from x-forwarded-fo }) const server = http.createServer() - ws.createServer({ - server: server - }, broker.handle) + createWebsocketServer(server, broker) server.listen(port, function (err) { t.error(err, 'no error') diff --git a/test/helper.js b/test/helper.js index 70bfc1aa..81212ff5 100644 --- a/test/helper.js +++ b/test/helper.js @@ -3,7 +3,9 @@ const duplexify = require('duplexify') const mqtt = require('mqtt-connection') const through = require('through2') +const { createWebSocketStream, Server } = require('ws') const util = require('util') + const aedes = require('../') const parseStream = mqtt.parseStream @@ -110,11 +112,22 @@ function subscribeMultiple (t, subscriber, subs, expectedGranted, done) { }) } +function createWebsocketServer (server, broker) { + const ws = new Server({ server }) + + ws.on('connection', function (conn, req) { + var stream = createWebSocketStream(conn) + stream._socket = conn._socket + broker.handle(stream, req) + }) +} + module.exports = { setup: setup, connect: connect, noError: noError, subscribe: subscribe, subscribeMultiple: subscribeMultiple, - delay: util.promisify(setTimeout) + delay: util.promisify(setTimeout), + createWebsocketServer: createWebsocketServer }