version 0.0.0.3
This commit is contained in:
@@ -2,10 +2,7 @@ services:
|
||||
rvs:
|
||||
build: .
|
||||
ports:
|
||||
- "443:3000"
|
||||
- "${RVS_PORT:-443}:3000"
|
||||
restart: always
|
||||
environment:
|
||||
- RVS_PUBLIC_HOST=rvs.hackersoft.de
|
||||
- RVS_PUBLIC_PORT=443
|
||||
- TOKEN_EXPIRY=3600
|
||||
- MAX_SESSIONS=10
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const crypto = require("crypto");
|
||||
const qrcode = require("qrcode-terminal");
|
||||
|
||||
// ── Token generieren (32 Bytes = 64 Hex-Zeichen) ───────────────────
|
||||
const token = crypto.randomBytes(32).toString("hex");
|
||||
|
||||
// ── Verbindungsinfo aus Umgebungsvariablen ──────────────────────────
|
||||
const host = process.env.RVS_PUBLIC_HOST || "localhost";
|
||||
const port = parseInt(process.env.RVS_PUBLIC_PORT || "3000", 10);
|
||||
|
||||
// QR-Inhalt: alles was die App zum Verbinden braucht
|
||||
const payload = JSON.stringify({ host, port, token });
|
||||
|
||||
// ── Ausgabe ─────────────────────────────────────────────────────────
|
||||
|
||||
console.log("");
|
||||
console.log("═══════════════════════════════════════════════════");
|
||||
console.log(" ARIA — Neues Pairing-Token generiert");
|
||||
console.log("═══════════════════════════════════════════════════");
|
||||
console.log("");
|
||||
console.log(` Host: ${host}`);
|
||||
console.log(` Port: ${port}`);
|
||||
console.log(` Token: ${token}`);
|
||||
console.log("");
|
||||
console.log(" QR-Code scannen mit der ARIA App:");
|
||||
console.log("");
|
||||
|
||||
// QR-Code im Terminal anzeigen (klein für bessere Lesbarkeit)
|
||||
qrcode.generate(payload, { small: true }, (code) => {
|
||||
console.log(code);
|
||||
console.log("");
|
||||
console.log(` Payload: ${payload}`);
|
||||
console.log("");
|
||||
console.log("═══════════════════════════════════════════════════");
|
||||
console.log("");
|
||||
});
|
||||
+2
-4
@@ -4,14 +4,12 @@
|
||||
"description": "ARIA Rendezvous-Server — WebSocket Relay mit Token-Pairing",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"token": "node generate-token.js"
|
||||
"start": "node server.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "^8.18.0",
|
||||
"qrcode-terminal": "^0.12.0"
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
}
|
||||
|
||||
+7
-14
@@ -4,7 +4,6 @@ const { WebSocketServer } = require("ws");
|
||||
|
||||
// ── Konfiguration aus Umgebungsvariablen ────────────────────────────
|
||||
const PORT = parseInt(process.env.PORT || "3000", 10);
|
||||
const TOKEN_EXPIRY = parseInt(process.env.TOKEN_EXPIRY || "3600", 10) * 1000; // in ms
|
||||
const MAX_SESSIONS = parseInt(process.env.MAX_SESSIONS || "10", 10);
|
||||
|
||||
// Erlaubte Nachrichtentypen — alles andere wird verworfen
|
||||
@@ -12,7 +11,7 @@ const ALLOWED_TYPES = new Set([
|
||||
"chat", "audio", "file", "location", "mode", "log", "event",
|
||||
]);
|
||||
|
||||
// Token-Raum: token -> { clients: Set<ws>, createdAt: number }
|
||||
// Token-Raum: token -> { clients: Set<ws> }
|
||||
const rooms = new Map();
|
||||
|
||||
// ── Hilfsfunktionen ─────────────────────────────────────────────────
|
||||
@@ -25,22 +24,17 @@ function log(msg) {
|
||||
console.log(`[${timestamp()}] ${msg}`);
|
||||
}
|
||||
|
||||
// Abgelaufene und leere Räume aufräumen
|
||||
// Leere Räume und tote Clients aufräumen
|
||||
function cleanupRooms() {
|
||||
const now = Date.now();
|
||||
for (const [token, room] of rooms) {
|
||||
// Tote Clients entfernen
|
||||
for (const client of room.clients) {
|
||||
if (client.readyState > 1) room.clients.delete(client);
|
||||
}
|
||||
// Raum löschen wenn leer oder abgelaufen
|
||||
if (room.clients.size === 0 || now - room.createdAt > TOKEN_EXPIRY) {
|
||||
// Verbleibende Clients sauber trennen
|
||||
for (const client of room.clients) {
|
||||
client.close(4001, "Token abgelaufen");
|
||||
}
|
||||
// Raum löschen wenn leer
|
||||
if (room.clients.size === 0) {
|
||||
rooms.delete(token);
|
||||
log(`Raum entfernt: ${token.slice(0, 8)}... (${room.clients.size} Clients)`);
|
||||
log(`Leerer Raum entfernt: ${token.slice(0, 8)}...`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,8 +44,7 @@ function cleanupRooms() {
|
||||
const wss = new WebSocketServer({ port: PORT });
|
||||
|
||||
wss.on("listening", () => {
|
||||
log(`RVS läuft auf Port ${PORT}`);
|
||||
log(`Token-Ablauf: ${TOKEN_EXPIRY / 1000}s | Max Sessions: ${MAX_SESSIONS}`);
|
||||
log(`RVS läuft auf Port ${PORT} | Max Sessions: ${MAX_SESSIONS}`);
|
||||
});
|
||||
|
||||
wss.on("connection", (ws, req) => {
|
||||
@@ -89,7 +82,7 @@ function registerClient(ws, token) {
|
||||
|
||||
// Raum erstellen oder betreten
|
||||
if (!rooms.has(token)) {
|
||||
rooms.set(token, { clients: new Set(), createdAt: Date.now() });
|
||||
rooms.set(token, { clients: new Set() });
|
||||
log(`Neuer Raum: ${token.slice(0, 8)}...`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user