diff --git a/README.md b/README.md index 341b03f..faa4b76 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,345 @@ -# gaming-hub +# Gaming Hub +Plugin-basierte Discord-Bot-Plattform mit Web-Dashboard. Zwei Bots (Jukebox + Radio) laufen parallel mit eigenem Discord-Token und eigener Voice-Connection pro Guild. - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files -* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: +## Architektur ``` -cd existing_repo -git remote add origin https://git.daddelolymp.de/root/gaming-hub.git -git branch -M main -git push -uf origin main +gaming-hub/ +├── server/ # Backend (Node.js + Express + TypeScript) +│ └── src/ +│ ├── index.ts # Entry Point, SSE, Plugin-Loader +│ ├── core/ +│ │ ├── discord.ts # Discord.js Client Factory +│ │ ├── plugin.ts # Plugin-System + Voice Claims +│ │ ├── sse.ts # Server-Sent Events Broadcasting +│ │ └── persistence.ts # JSON State auf Disk +│ └── plugins/ +│ ├── radio/ # World Radio Plugin +│ │ ├── index.ts # Routes, Voice, Streaming +│ │ └── api.ts # Radio Garden API Client +│ └── soundboard/ # Jukebox / Soundboard Plugin +│ └── index.ts # Sounds, Upload, Normalisierung +│ +├── web/ # Frontend (React 19 + Vite + TypeScript) +│ └── src/ +│ ├── App.tsx # Root, Tab-Navigation, SSE-Handler +│ ├── styles.css # Globale Styles + Radio-Styles +│ └── plugins/ +│ ├── radio/ +│ │ ├── RadioTab.tsx # 3D Globe UI +│ │ └── TileTextureManager.ts # Tile Loader + Mercator-Reprojection +│ └── soundboard/ +│ ├── SoundboardTab.tsx # Sound Grid UI +│ └── soundboard.css # Soundboard Styles +│ +├── Dockerfile # Multi-Stage Production Build (4 Stages) +├── .gitlab-ci.yml # CI/CD Pipeline (Kaniko) +└── .dockerignore ``` -## Integrate with your tools +## Tech Stack -* [Set up project integrations](https://git.daddelolymp.de/root/gaming-hub/-/settings/integrations) +| Komponente | Technologie | Version | +|------------|-------------|---------| +| Runtime | Node.js | 24 (slim) | +| Backend | Express | 5.x | +| Frontend | React + Vite | 19.x / 6.x | +| Discord | discord.js + @discordjs/voice | 14.x / 0.19.x | +| 3D Globe | globe.gl + three.js | 2.35 / 0.172 | +| Audio | FFmpeg (GPL Build) + @discordjs/opus | latest / 0.10.x | +| TypeScript | tsc | 5.9.x | +| CI/CD | GitLab + Kaniko | v1.23.2 | -## Collaborate with your team +## Plugins -* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/) -* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/) -* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically) -* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/) -* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) +### Radio (`radio`) +- 3D-Globus mit 30.000+ Radiosendern weltweit (Radio Garden API) +- Tile-basierte Satellitentextur (Mercator -> Equirectangular Reprojection) +- Server-seitiger Tile-Proxy mit In-Memory Cache (CDN erfordert Referer) +- FFmpeg PCM-Streaming in Discord Voice Channels +- Per-Guild Lautstaerke, Favoriten, Suche +- Voice Stats (Ping, Status, Uptime) via SSE -## Test and Deploy +### Soundboard / Jukebox (`soundboard`) +- Sound-Upload (MP3/WAV) mit Drag & Drop +- Automatische Audio-Normalisierung (LUFS, FFmpeg) +- PCM Memory Cache (Standard 512 MB) fuer sofortige Wiedergabe +- Kategorien, Badges, Statistiken +- Admin-Panel mit Passwortschutz +- Party-Modus (Chaos Mode) -Use the built-in continuous integration in GitLab. +## Environment Variables -* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/) -* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/) -* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/) -* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/) -* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/) +### Erforderlich -*** +| Variable | Beschreibung | +|----------|-------------| +| `DISCORD_TOKEN_JUKEBOX` | Discord Bot Token fuer Soundboard/Jukebox | +| `DISCORD_TOKEN_RADIO` | Discord Bot Token fuer Radio | -# Editing this README +> Beide Bots muessen im Discord Developer Portal separat erstellt werden. +> Jeder braucht die Intents: `GUILDS`, `GUILD_VOICE_STATES`, `GUILD_MEMBERS`. -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. +### Optional -## Suggestions for a good README +| Variable | Default | Beschreibung | +|----------|---------|-------------| +| `PORT` | `8080` | HTTP Server Port | +| `DATA_DIR` | `/data` | Persistenter Speicher (State, Sounds) | +| `ADMIN_PWD` | _(leer)_ | Admin-Passwort fuer Soundboard-Verwaltung | +| `ALLOWED_GUILD_IDS` | _(leer)_ | Komma-separierte Guild-IDs (Whitelist, leer = alle) | +| `DISCORD_TOKEN` | _(leer)_ | Legacy Fallback fuer Jukebox (wenn `DISCORD_TOKEN_JUKEBOX` fehlt) | -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. +### Soundboard-spezifisch -## Name -Choose a self-explaining name for your project. +| Variable | Default | Beschreibung | +|----------|---------|-------------| +| `SOUNDS_DIR` | `/data/sounds` | Verzeichnis fuer Sound-Dateien | +| `NORMALIZE_ENABLE` | `true` | Audio-Normalisierung aktivieren | +| `NORMALIZE_I` | `-16` | LUFS Integrated Loudness | +| `NORMALIZE_LRA` | `11` | LUFS Loudness Range | +| `NORMALIZE_TP` | `-1.5` | LUFS True Peak | +| `NORM_CONCURRENCY` | `2` | Parallele Normalisierungs-Threads | +| `PCM_CACHE_MAX_MB` | `512` | Max. PCM Memory Cache in MB | -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. +### Build-Time (Vite) -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. +| Variable | Default | Beschreibung | +|----------|---------|-------------| +| `VITE_APP_VERSION` | `1.0.0-dev` | Angezeigte Version im Frontend | +| `VITE_BUILD_CHANNEL` | `dev` | Release-Kanal (`stable` / `nightly` / `dev`) | -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. +## Docker -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. +### Image bauen -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +```bash +docker build -t gaming-hub:latest . +``` -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. +### Container starten -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +```bash +docker run -d \ + --name gaming-hub \ + --restart unless-stopped \ + -p 8080:8080 \ + -v gaming-hub-data:/data \ + -e DISCORD_TOKEN_JUKEBOX="dein-jukebox-token" \ + -e DISCORD_TOKEN_RADIO="dein-radio-token" \ + -e ADMIN_PWD="dein-admin-passwort" \ + gaming-hub:latest +``` -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +### Docker Compose -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. +```yaml +version: "3.8" -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. +services: + gaming-hub: + image: gaming-hub:latest + container_name: gaming-hub + restart: unless-stopped + ports: + - "8080:8080" + volumes: + - gaming-hub-data:/data + environment: + # Erforderlich + - DISCORD_TOKEN_JUKEBOX=dein-jukebox-token + - DISCORD_TOKEN_RADIO=dein-radio-token + # Optional + - ADMIN_PWD=dein-admin-passwort + - ALLOWED_GUILD_IDS= + # Soundboard Tuning + - PCM_CACHE_MAX_MB=512 + - NORMALIZE_ENABLE=true -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. +volumes: + gaming-hub-data: +``` -## License -For open source projects, say how it is licensed. +### Unraid Docker Template -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +```xml + + + gaming-hub + 10.10.10.10:9080/root/gaming-hub:latest + http://10.10.10.10:9080/ + bridge + false + + Discord Gaming Hub - Soundboard + World Radio mit Web-Dashboard + MediaApp:Other + http://[IP]:[PORT:8080]/ + --restart unless-stopped + 8080 + /mnt/user/appdata/gaming-hub + + + + + 512 + true + /data/sounds + +``` + +## Lokale Entwicklung + +### Voraussetzungen + +- Node.js 20+ +- FFmpeg im PATH +- Zwei Discord Bot Tokens + +### Setup + +```bash +git clone http://10.10.10.10:9080/root/gaming-hub.git +cd gaming-hub + +# Server Dependencies +cd server && npm install && cd .. + +# Web Dependencies +cd web && npm install && cd .. +``` + +### Dev Server starten + +```bash +# Terminal 1: Backend +cd server +DISCORD_TOKEN_JUKEBOX="..." DISCORD_TOKEN_RADIO="..." ADMIN_PWD="test" DATA_DIR="./data" npm run dev + +# Terminal 2: Frontend (Proxy auf localhost:8080) +cd web +npm run dev +``` + +Backend laeuft auf `http://localhost:8080`, Frontend auf `http://localhost:5173` (mit API-Proxy). + +### Production Build + +```bash +cd server && npm run build # -> server/dist/ +cd ../web && npm run build # -> web/dist/ + +# Starten +cd ../server +NODE_ENV=production node dist/index.js +``` + +## API Endpoints + +### Core + +| Method | Pfad | Beschreibung | +|--------|------|-------------| +| GET | `/api/health` | Server-Status, Plugins, Bots, SSE-Clients | +| GET | `/api/plugins` | Plugin-Liste (Name, Version, Description) | +| GET | `/api/events` | SSE-Stream (Snapshot + Live-Updates) | +| POST | `/api/admin/login` | Admin-Login (Body: `{ password }`) | + +### Radio Plugin + +| Method | Pfad | Beschreibung | +|--------|------|-------------| +| GET | `/api/radio/places` | Alle Orte fuer den Globus | +| GET | `/api/radio/place/:id/channels` | Sender an einem Ort | +| GET | `/api/radio/search?q=...` | Sender/Orte suchen | +| GET | `/api/radio/guilds` | Verfuegbare Guilds + Voice Channels | +| POST | `/api/radio/play` | Stream starten | +| POST | `/api/radio/stop` | Stream stoppen | +| POST | `/api/radio/volume` | Lautstaerke setzen (0-1) | +| GET | `/api/radio/favorites` | Favoriten lesen | +| POST | `/api/radio/favorites` | Favorit togglen | +| GET | `/api/radio/status` | Aktueller Wiedergabestatus | +| GET | `/api/radio/tile/:z/:x/:y` | Tile-Proxy (Satellitenbild) | + +### Soundboard Plugin + +| Method | Pfad | Beschreibung | +|--------|------|-------------| +| GET | `/api/soundboard/channels` | Voice Channels aller Guilds | +| GET | `/api/soundboard/sounds` | Sound-Liste (mit Filter/Suche) | +| POST | `/api/soundboard/play` | Sound abspielen | +| POST | `/api/soundboard/stop` | Wiedergabe stoppen | +| POST | `/api/soundboard/volume` | Lautstaerke setzen | +| POST | `/api/soundboard/upload` | Sound hochladen (Multipart) | + +## CI/CD Pipeline + +GitLab CI mit Kaniko (`.gitlab-ci.yml`): + +| Branch | Tag | Version | Channel | +|--------|-----|---------|---------| +| `main` | `latest`, `main` | `1.0.0` | `stable` | +| `nightly` | `nightly` | `1.0.0-nightly` | `nightly` | +| andere | `branch-name` | `1.0.0-dev` | `dev` | + +Registry: `10.10.10.10:9080/root/gaming-hub` + +## SSE Event Types + +Alle Clients empfangen Events ueber `GET /api/events`: + +| Event Type | Plugin | Beschreibung | +|-----------|--------|-------------| +| `snapshot` | - | Initialer Gesamtstatus beim Connect | +| `radio` | radio | Wiedergabestatus (playing/stopped) | +| `radio_volume` | radio | Lautstaerkeaenderung | +| `radio_voicestats` | radio | Voice-Ping, Gateway-Ping, Status, Uptime | +| `radio_favorites` | radio | Favoriten-Update | +| `soundboard_voicestats` | soundboard | Voice-Verbindungsdetails | +| `soundboard_nowplaying` | soundboard | Aktuell gespielter Sound | +| `soundboard_volume` | soundboard | Lautstaerkeaenderung | +| `soundboard_channel` | soundboard | Channel-Wechsel | +| `soundboard_party` | soundboard | Party-Modus Status | + +## Discord Bot Setup + +1. [Discord Developer Portal](https://discord.com/developers/applications) oeffnen +2. **Zwei** Applications erstellen (z.B. "Jukebox Bot" und "Radio Bot") +3. Fuer jede Application: + - Bot erstellen unter "Bot" + - Token kopieren + - **Privileged Gateway Intents** aktivieren: + - Server Members Intent + - Message Content Intent (optional) + - Unter "OAuth2 > URL Generator": + - Scopes: `bot` + - Bot Permissions: `Connect`, `Speak`, `Use Voice Activity` + - Generierte URL im Browser oeffnen, Bot zum Server einladen +4. Tokens als `DISCORD_TOKEN_JUKEBOX` und `DISCORD_TOKEN_RADIO` setzen + +## Persistenz + +Alle Daten werden im `DATA_DIR` (`/data`) gespeichert: + +``` +/data/ +├── state.json # Plugin-State (Volumes, Favorites, Channels, ...) +└── sounds/ # Soundboard Audio-Dateien + ├── sound1.mp3 + ├── subfolder/ + │ └── sound2.wav + └── ... +``` + +State wird automatisch bei Aenderungen geschrieben und beim Start geladen. + +## Dockerfile (Multi-Stage) + +4 Build-Stages: + +1. **web-build** - React/Vite Frontend kompilieren +2. **server-build** - TypeScript Backend kompilieren + native Dependencies (python3, make, g++) +3. **ffmpeg-fetch** - FFmpeg Binary von yt-dlp/FFmpeg-Builds herunterladen +4. **runtime** - Finales Image (node:24-slim) mit yt-dlp, ffmpeg, kompiliertem Code + +Finales Image enthaelt nur Production Dependencies, kein TypeScript/Dev-Tooling.