From 926d6b27d6851ba0e3a7f445c7aff83b5529e9f7 Mon Sep 17 00:00:00 2001 From: Andreas Dzialocha Date: Tue, 28 Nov 2017 01:06:19 +0100 Subject: [PATCH] Pass http server over to websocket server --- server/index.js | 8 +++++--- server/network/index.js | 2 ++ server/network/wsServer.js | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/index.js b/server/index.js index 7e027d2..3d9fae7 100644 --- a/server/index.js +++ b/server/index.js @@ -19,8 +19,10 @@ console.log(`Version ${pkg.version}`) console.log() // initialize -const httpServer = new HTTPServer() -const network = new Network() +const server = new HTTPServer() +const network = new Network({ + server, +}) -httpServer.open() +server.open() network.open() diff --git a/server/network/index.js b/server/network/index.js index 122074e..5a24840 100644 --- a/server/network/index.js +++ b/server/network/index.js @@ -12,6 +12,7 @@ const defaultOptions = { onClose: () => true, onOpen: () => true, port: 52525, + server: null, } class Network { @@ -22,6 +23,7 @@ class Network { this.osc = new OSC({ plugin: new WebsocketServer({ + server: this.options.server, onClientOpen: (client, req) => { this.clientsCount += 1 const ip = req.connection.remoteAddress diff --git a/server/network/wsServer.js b/server/network/wsServer.js index ff9ad72..2c0a04a 100644 --- a/server/network/wsServer.js +++ b/server/network/wsServer.js @@ -14,6 +14,7 @@ const defaultOptions = { onClientClose: () => true, onClientOpen: () => true, port: 52525, + server: null, } class WebsocketServer { @@ -37,7 +38,7 @@ class WebsocketServer { open(customOptions = {}) { const options = Object.assign({}, this.options, customOptions) - const { port, host } = options + const { port, host, server } = options // close socket when already given if (this.socket) { @@ -45,7 +46,7 @@ class WebsocketServer { } // create websocket server - this.socket = new WSServer({ host, port }) + this.socket = new WSServer({ host, port, server }) this.socket.binaryType = 'arraybuffer' this.socketStatus = STATUS.IS_CONNECTING