You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 22:13:53 +01:00
Merge pull request #31 from bkram/Bkram/audio-proxying
Bkram/audio proxying
This commit is contained in:
16
index.js
16
index.js
@@ -7,6 +7,7 @@ const express = require('express');
|
|||||||
const session = require('express-session');
|
const session = require('express-session');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
const httpProxy = require('http-proxy');
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
const app = express();
|
const app = express();
|
||||||
const httpServer = http.createServer(app);
|
const httpServer = http.createServer(app);
|
||||||
@@ -28,9 +29,15 @@ const consoleCmd = require('./console');
|
|||||||
const audioStream = require('./stream/index.js');
|
const audioStream = require('./stream/index.js');
|
||||||
const { parseAudioDevice } = require('./stream/parser.js');
|
const { parseAudioDevice } = require('./stream/parser.js');
|
||||||
const { configName, serverConfig, configUpdate, configSave } = require('./server_config');
|
const { configName, serverConfig, configUpdate, configSave } = require('./server_config');
|
||||||
|
|
||||||
const { logDebug, logError, logInfo, logWarn } = consoleCmd;
|
const { logDebug, logError, logInfo, logWarn } = consoleCmd;
|
||||||
|
|
||||||
|
// Create a WebSocket proxy instance
|
||||||
|
const proxy = httpProxy.createProxyServer({
|
||||||
|
target: 'ws://localhost:'+ serverConfig.webserver.audioPort, // WebSocket httpServer's address
|
||||||
|
ws: true, // Enable WebSocket proxying
|
||||||
|
changeOrigin: true // Change the origin of the host header to the target URL
|
||||||
|
});
|
||||||
|
|
||||||
let currentUsers = 0;
|
let currentUsers = 0;
|
||||||
let streamEnabled = false;
|
let streamEnabled = false;
|
||||||
let incompleteDataBuffer = '';
|
let incompleteDataBuffer = '';
|
||||||
@@ -433,7 +440,7 @@ wss.on('connection', (ws, request) => {
|
|||||||
ws.on('error', console.error);
|
ws.on('error', console.error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle upgrade requests to /text and proxy /audio WebSocket connections
|
||||||
httpServer.on('upgrade', (request, socket, head) => {
|
httpServer.on('upgrade', (request, socket, head) => {
|
||||||
if (request.url === '/text') {
|
if (request.url === '/text') {
|
||||||
sessionMiddleware(request, {}, () => {
|
sessionMiddleware(request, {}, () => {
|
||||||
@@ -441,10 +448,13 @@ httpServer.on('upgrade', (request, socket, head) => {
|
|||||||
wss.emit('connection', ws, request);
|
wss.emit('connection', ws, request);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
} else if (request.url === '/audio') {
|
||||||
|
proxy.ws(request, socket, head);
|
||||||
} else {
|
} else {
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/* Serving of HTML files */
|
/* Serving of HTML files */
|
||||||
app.use(express.static(path.join(__dirname, 'web')));
|
app.use(express.static(path.join(__dirname, 'web')));
|
||||||
|
|||||||
47
package-lock.json
generated
47
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "fm-dx-webserver",
|
"name": "fm-dx-webserver",
|
||||||
"version": "1.0.6",
|
"version": "1.0.8",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "fm-dx-webserver",
|
"name": "fm-dx-webserver",
|
||||||
"version": "1.0.6",
|
"version": "1.0.8",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mapbox/node-pre-gyp": "^1.0.11",
|
"@mapbox/node-pre-gyp": "^1.0.11",
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
"express": "4.18.2",
|
"express": "4.18.2",
|
||||||
"express-session": "^1.18.0",
|
"express-session": "^1.18.0",
|
||||||
"http": "^0.0.1-security",
|
"http": "^0.0.1-security",
|
||||||
|
"http-proxy": "^1.18.1",
|
||||||
"https": "1.0.0",
|
"https": "1.0.0",
|
||||||
"koffi": "2.7.2",
|
"koffi": "2.7.2",
|
||||||
"net": "1.0.2",
|
"net": "1.0.2",
|
||||||
@@ -456,6 +457,11 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/eventemitter3": {
|
||||||
|
"version": "4.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
|
||||||
|
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
|
||||||
|
},
|
||||||
"node_modules/express": {
|
"node_modules/express": {
|
||||||
"version": "4.18.2",
|
"version": "4.18.2",
|
||||||
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
|
||||||
@@ -622,6 +628,25 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.15.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz",
|
||||||
|
"integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/forwarded": {
|
"node_modules/forwarded": {
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
||||||
@@ -813,6 +838,19 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/http-proxy": {
|
||||||
|
"version": "1.18.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz",
|
||||||
|
"integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"eventemitter3": "^4.0.0",
|
||||||
|
"follow-redirects": "^1.0.0",
|
||||||
|
"requires-port": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/https": {
|
"node_modules/https": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
|
||||||
@@ -1267,6 +1305,11 @@
|
|||||||
"node": ">= 6"
|
"node": ">= 6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/requires-port": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ=="
|
||||||
|
},
|
||||||
"node_modules/rimraf": {
|
"node_modules/rimraf": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"express": "4.18.2",
|
"express": "4.18.2",
|
||||||
"express-session": "^1.18.0",
|
"express-session": "^1.18.0",
|
||||||
"http": "^0.0.1-security",
|
"http": "^0.0.1-security",
|
||||||
|
"http-proxy": "^1.18.1",
|
||||||
"https": "1.0.0",
|
"https": "1.0.0",
|
||||||
"koffi": "2.7.2",
|
"koffi": "2.7.2",
|
||||||
"net": "1.0.2",
|
"net": "1.0.2",
|
||||||
|
|||||||
@@ -71,11 +71,11 @@ var _3LAS = /** @class */ (function () {
|
|||||||
if (this.WakeLock)
|
if (this.WakeLock)
|
||||||
this.WakeLock.Begin();
|
this.WakeLock.Begin();
|
||||||
try {
|
try {
|
||||||
if (window.location.protocol === 'https:') {
|
if (window.location.protocol === 'https:') {
|
||||||
this.WebSocket = new WebSocketClient(this.Logger, 'wss://' + this.Settings.SocketHost + ':' + window.location.pathname + 'stream' + this.Settings.SocketPath, this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this));
|
this.WebSocket = new WebSocketClient(this.Logger, 'wss://' + this.Settings.SocketHost + ':' + location.port.toString() + window.location.pathname + 'audio' , this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.WebSocket = new WebSocketClient(this.Logger, 'ws://' + this.Settings.SocketHost + ':' + this.Settings.SocketPort.toString() + this.Settings.SocketPath, this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this));
|
this.WebSocket = new WebSocketClient(this.Logger, 'ws://' + this.Settings.SocketHost + ':' + location.port.toString() + window.location.pathname + 'audio' , this.OnSocketError.bind(this), this.OnSocketConnect.bind(this), this.OnSocketDataReady.bind(this), this.OnSocketDisconnect.bind(this));
|
||||||
}
|
}
|
||||||
this.Logger.Log("Init of WebSocketClient succeeded");
|
this.Logger.Log("Init of WebSocketClient succeeded");
|
||||||
this.Logger.Log("Trying to connect to server.");
|
this.Logger.Log("Trying to connect to server.");
|
||||||
|
|||||||
Reference in New Issue
Block a user