Update: changes in 3DInput mit WSS

This commit is contained in:
ChK
2026-02-01 14:38:11 +01:00
parent fc7d40ac64
commit 6c034f2838
3 changed files with 155 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ const fs = require('fs');
const https = require('https');
const WebSocket = require('ws');
const url = require('url');
const driverWS = require("./programs/driver");
const httpsOptions = {
"enable": true,
@@ -34,6 +35,27 @@ server = https.createServer(httpsOptions, (req, res) => {
})
});
// vvvvvvvvvvvvvvvvvvvvv Forward WebSocket: Eigener WSS auf Driver vvvvvvvvvvvvvvvvvvvvvvvv
const wssInput = new WebSocket.Server({ noServer: true });
const targetServer = process.env.TARGET_SERVER || 'wss://localhost:2095';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
driverWS.setupCommandForwarding(wssInput, targetServer);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Upgrade handler: accept all WebSocket upgrades and forward to the forwarding server (wssInput)
server.on('upgrade', (req, socket, head) => {
const pathname = url.parse(req.url).pathname;
console.log('Upgrade request for', pathname);
try {
// Forward the upgrade to the forwarding server
wssInput.handleUpgrade(req, socket, head, (ws) => {
wssInput.emit('connection', ws, req);
});
} catch (err) {
console.error('Upgrade handling error:', err && err.message || err);
socket.destroy();
}
});
server.listen(10010);
console.log("Connect to: https://localhost:10010")