From 0d47a9c655282219b6be793eb5c2e53e7b9565d6 Mon Sep 17 00:00:00 2001 From: Paoda Date: Thu, 30 Aug 2018 15:22:57 +0100 Subject: [PATCH] resctructured server thanks to better understanding of what I'm doing --- app.js | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index f60e85b..a632480 100644 --- a/app.js +++ b/app.js @@ -1,34 +1,29 @@ -require('dotenv').config(); -const WebSocket = require('ws'); -const WebSocketStream = require('websocket-stream'); - +require("dotenv").config(); +const WebSocket = require("ws"); +const WebSocketStream = require("websocket-stream"); +const http = require('http'); +/** + * HTTP Server with Websocket which is responsible for: + * - Recieving User Audio Media + * - Recieving Data relating to which users are in what channel + */ class WebSocketServer { constructor() { - this.io = new WebSocket.Server({ - port: process.env.PORT || 1337, - }); + const server = http.createServer(); + this.stream = WebSocketStream.createServer({ server: server },this.handleStream); - this.stream = WebSocketStream.createServer({ - server: this.io, - }, this.handleStream) - - this.createEventListeners(); + server.listen(process.env.PORT || 1337) } - handleStream(stream, req) { - console.log(stream); + console.log(stream); } - createEventListeners() { - this.io.on('connection', (io) => { - io.on('message', (msg) => { - console.log('Recieved: %s', msg); - }) - }) + + checkIfBuffer(stream) { + } } - const wss = new WebSocketServer();