resctructured server thanks to better understanding of what I'm doing
This commit is contained in:
parent
70c0d07cbf
commit
0d47a9c655
37
app.js
37
app.js
|
@ -1,34 +1,29 @@
|
||||||
require('dotenv').config();
|
require("dotenv").config();
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require("ws");
|
||||||
const WebSocketStream = require('websocket-stream');
|
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 {
|
class WebSocketServer {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.io = new WebSocket.Server({
|
const server = http.createServer();
|
||||||
port: process.env.PORT || 1337,
|
this.stream = WebSocketStream.createServer({ server: server },this.handleStream);
|
||||||
});
|
|
||||||
|
|
||||||
this.stream = WebSocketStream.createServer({
|
server.listen(process.env.PORT || 1337)
|
||||||
server: this.io,
|
|
||||||
}, this.handleStream)
|
|
||||||
|
|
||||||
this.createEventListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
handleStream(stream, req) {
|
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();
|
const wss = new WebSocketServer();
|
||||||
|
|
Reference in New Issue