Skip to content

Commit

Permalink
Pass http server over to websocket server
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Dzialocha committed Nov 28, 2017
1 parent d83d5d2 commit 926d6b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions server/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const defaultOptions = {
onClose: () => true,
onOpen: () => true,
port: 52525,
server: null,
}

class Network {
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions server/network/wsServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const defaultOptions = {
onClientClose: () => true,
onClientOpen: () => true,
port: 52525,
server: null,
}

class WebsocketServer {
Expand All @@ -37,15 +38,15 @@ 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) {
this.close()
}

// 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

Expand Down

0 comments on commit 926d6b2

Please sign in to comment.