Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b13981dad | |||
| 244aadcf8b | |||
| d1cbf1fd21 | |||
| 999fbf0412 | |||
| 9b1db5a119 | |||
| 5a4939dac8 | |||
| 7b1770dd40 | |||
| 7aa09e5453 | |||
| 73e141c5db | |||
| 79cda9653b | |||
| 1050369469 | |||
| 01f1faa9aa | |||
| 94e03fcc5d | |||
| ec067329ce | |||
| 324ff11be9 | |||
| b35f80fc7c | |||
| f2e1a50d6d | |||
| a5879a2ea9 |
+12
@@ -8,10 +8,18 @@ pnpm-lock.yaml
|
|||||||
.env
|
.env
|
||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
server/.env
|
||||||
|
client/.env
|
||||||
|
|
||||||
|
# Keep .env.example files (templates)
|
||||||
|
!.env.example
|
||||||
|
!client/.env.example
|
||||||
|
!server/.env.example
|
||||||
|
|
||||||
# Build outputs
|
# Build outputs
|
||||||
dist/
|
dist/
|
||||||
build/
|
build/
|
||||||
|
dev-dist/
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# OS files
|
# OS files
|
||||||
@@ -43,3 +51,7 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
pnpm-debug.log*
|
pnpm-debug.log*
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
|
server.log
|
||||||
|
|
||||||
|
# Runtime files
|
||||||
|
/tmp/ptt-live.pid
|
||||||
|
|||||||
@@ -204,24 +204,48 @@ PTT Live/
|
|||||||
## Commandes de développement
|
## Commandes de développement
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Installation initiale
|
# Installation automatique (recommandé)
|
||||||
./install/macos.sh
|
./install.sh # Détecte OS, configure tout automatiquement
|
||||||
|
|
||||||
# Serveur (dev)
|
# Démarrage rapide
|
||||||
|
./start.sh --dev # Mode développement
|
||||||
|
./start.sh # Mode production
|
||||||
|
|
||||||
|
# OU manuellement (deux terminaux)
|
||||||
|
# Serveur
|
||||||
cd server
|
cd server
|
||||||
npm install
|
npm install
|
||||||
npm run dev
|
npm run dev
|
||||||
|
|
||||||
# Client (dev)
|
# Client
|
||||||
cd client
|
cd client
|
||||||
npm install
|
npm install
|
||||||
npm run dev
|
npm run dev
|
||||||
|
|
||||||
# Production
|
|
||||||
cd server
|
|
||||||
npm start
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Fonctionnalités de portabilité (v0.2.1)
|
||||||
|
|
||||||
|
### Installation zéro-config
|
||||||
|
- **Script multi-OS** : `install.sh` détecte automatiquement macOS/Linux
|
||||||
|
- **Auto-détection IP** : Génère les `.env` avec l'IP réseau du serveur
|
||||||
|
- **Devices audio** : API `/admin/devices/list` pour énumérer devices disponibles
|
||||||
|
- **Templates** : `.env.example` pour serveur et client
|
||||||
|
|
||||||
|
### QR Code terminal
|
||||||
|
- **Affichage automatique** au démarrage du serveur
|
||||||
|
- **Scan rapide** depuis smartphone (connexion en 5s)
|
||||||
|
- **URL adaptative** : dev (5173) ou prod (3000) selon build client
|
||||||
|
|
||||||
|
### HTTPS automatique
|
||||||
|
- **Vite dev server** : HTTPS par défaut (certificat self-signed)
|
||||||
|
- **Redirection HTTP → HTTPS** en mode développement
|
||||||
|
- **Production** : utiliser reverse proxy (nginx/Caddy) pour HTTPS
|
||||||
|
|
||||||
|
### Configuration dynamique
|
||||||
|
- **LIVEKIT_URL: AUTO** dans config.yaml → détection IP runtime
|
||||||
|
- **Vite loadEnv()** pour variables d'environnement dynamiques
|
||||||
|
- **Serveur statique** : Express sert `client/dist/` en production
|
||||||
|
|
||||||
## Tests et validation
|
## Tests et validation
|
||||||
|
|
||||||
### Métriques critiques
|
### Métriques critiques
|
||||||
@@ -307,7 +331,8 @@ test: description
|
|||||||
2. **Après chaque tâche complétée** :
|
2. **Après chaque tâche complétée** :
|
||||||
- ✅ Valider la tâche dans [TODO.md](TODO.md)
|
- ✅ Valider la tâche dans [TODO.md](TODO.md)
|
||||||
- 🔄 Commiter avec message descriptif en français
|
- 🔄 Commiter avec message descriptif en français
|
||||||
- 📝 Mettre à jour CLAUDE.md si nécessaire
|
- 📝 Mettre à jour CLAUDE.md si nécessaire sans écrire "🤖 Generated with Claude Code Co-Authored-By: Claude noreply@anthropic.com"
|
||||||
|
- Ne pas créer de fichiers récapitulatifs markdown.
|
||||||
|
|
||||||
**Exemple workflow** :
|
**Exemple workflow** :
|
||||||
```bash
|
```bash
|
||||||
@@ -326,5 +351,5 @@ Voir [TODO.md](TODO.md) pour le plan détaillé.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Dernière mise à jour** : 2026-05-21
|
**Dernière mise à jour** : 2026-05-27
|
||||||
**Version** : 0.1.0 (Phase 1 en cours)
|
**Version** : 0.2.1 (Portable + QR Code)
|
||||||
|
|||||||
@@ -0,0 +1,408 @@
|
|||||||
|
# PTT Live - Guide de Déploiement Portable
|
||||||
|
|
||||||
|
Ce guide explique comment déployer **PTT Live** sur n'importe quelle machine macOS ou Linux, sans configuration manuelle d'IP ou de devices audio.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Installation Rapide
|
||||||
|
|
||||||
|
### Prérequis
|
||||||
|
|
||||||
|
- **macOS** : Homebrew installé ([brew.sh](https://brew.sh))
|
||||||
|
- **Linux** : Ubuntu 22.04+, Debian 11+, Arch Linux ou Fedora
|
||||||
|
- **Node.js** : Version 20+ (installé automatiquement si absent)
|
||||||
|
- **Connexion Internet** : Pour télécharger les dépendances
|
||||||
|
|
||||||
|
### Commandes
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Cloner ou télécharger le projet
|
||||||
|
cd ptt-live
|
||||||
|
|
||||||
|
# Lancer l'installation (détection automatique OS)
|
||||||
|
./install.sh
|
||||||
|
|
||||||
|
# Ou manuellement selon votre système :
|
||||||
|
./install/macos.sh # macOS
|
||||||
|
./install/linux.sh # Linux
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ce que l'installeur fait automatiquement
|
||||||
|
|
||||||
|
✅ Détecte votre système d'exploitation
|
||||||
|
✅ Installe Node.js 20+ (si absent)
|
||||||
|
✅ Installe LiveKit Server (binaire local)
|
||||||
|
✅ Installe les backends audio (sox/PipeWire/JACK)
|
||||||
|
✅ Détecte votre IP réseau locale
|
||||||
|
✅ Génère les fichiers `.env` avec la bonne configuration
|
||||||
|
✅ Installe toutes les dépendances npm
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🎬 Démarrage
|
||||||
|
|
||||||
|
### Méthode 1 : Script unifié (recommandé)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Mode développement (serveur + client avec hot-reload)
|
||||||
|
./start.sh --dev
|
||||||
|
|
||||||
|
# Mode production (build client + serveur optimisé)
|
||||||
|
./start.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
L'IP réseau est **détectée automatiquement** et affichée au démarrage.
|
||||||
|
|
||||||
|
### Méthode 2 : Manuel (deux terminaux)
|
||||||
|
|
||||||
|
**Terminal 1 : Serveur**
|
||||||
|
```bash
|
||||||
|
cd server
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
**Terminal 2 : Client**
|
||||||
|
```bash
|
||||||
|
cd client
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌐 Accès depuis d'autres appareils
|
||||||
|
|
||||||
|
### Sur le même réseau WiFi
|
||||||
|
|
||||||
|
Après le démarrage, notez l'**IP affichée** (exemple : `192.168.1.100`).
|
||||||
|
|
||||||
|
#### Depuis un smartphone/tablette
|
||||||
|
|
||||||
|
1. **Connectez l'appareil au même WiFi** que le serveur
|
||||||
|
2. Ouvrez le navigateur
|
||||||
|
3. Allez sur : `https://IP_SERVEUR:5173` (dev) ou `http://IP_SERVEUR:3000` (prod)
|
||||||
|
4. **iOS** : Installez la PWA sur l'écran d'accueil pour activer les notifications
|
||||||
|
|
||||||
|
#### Depuis un autre ordinateur
|
||||||
|
|
||||||
|
Même procédure : `https://IP_SERVEUR:5173`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ⚙️ Configuration Avancée
|
||||||
|
|
||||||
|
### Changer l'IP du serveur manuellement
|
||||||
|
|
||||||
|
Si l'auto-détection ne fonctionne pas (VPN, Docker, etc.) :
|
||||||
|
|
||||||
|
**1. Modifier `server/.env`**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Remplacer AUTO par l'IP voulue
|
||||||
|
LIVEKIT_URL=ws://192.168.1.100:7880
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Pour le client (accès réseau)**
|
||||||
|
|
||||||
|
Modifier `client/.env` :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Décommenter et mettre l'IP du serveur
|
||||||
|
VITE_API_URL=http://192.168.1.100:3000
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Redémarrer**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./start.sh --dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lister les devices audio disponibles
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Via API (serveur doit tourner)
|
||||||
|
curl http://localhost:3000/admin/devices/list
|
||||||
|
|
||||||
|
# Retourne JSON :
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{ "id": 0, "name": "Microphone MacBook Pro" },
|
||||||
|
{ "id": 4, "name": "USB Audio Interface" }
|
||||||
|
],
|
||||||
|
"outputs": [...],
|
||||||
|
"platform": "darwin"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Utilisez ensuite l'interface admin (`/admin`) pour sélectionner les devices.
|
||||||
|
|
||||||
|
### Changer les ports
|
||||||
|
|
||||||
|
**API serveur (port 3000 par défaut)**
|
||||||
|
|
||||||
|
Modifier `server/.env` :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
PORT=3001
|
||||||
|
```
|
||||||
|
|
||||||
|
**Client dev (port 5173 par défaut)**
|
||||||
|
|
||||||
|
Modifier `client/vite.config.js` :
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
server: {
|
||||||
|
port: 5174,
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📦 Mode Production (événement en conditions réelles)
|
||||||
|
|
||||||
|
### Build optimisé
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build du client statique
|
||||||
|
cd client
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Le dossier dist/ contient le build optimisé
|
||||||
|
```
|
||||||
|
|
||||||
|
### Servir en production
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Méthode 1 : Script start.sh (recommandé)
|
||||||
|
./start.sh
|
||||||
|
|
||||||
|
# Méthode 2 : npm start direct
|
||||||
|
cd server
|
||||||
|
npm start
|
||||||
|
|
||||||
|
# Le serveur Express sert automatiquement client/dist/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reverse proxy Nginx (optionnel)
|
||||||
|
|
||||||
|
Pour un domaine personnalisé avec HTTPS :
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
server_name ptt.example.com;
|
||||||
|
|
||||||
|
ssl_certificate /path/to/cert.pem;
|
||||||
|
ssl_certificate_key /path/to/key.pem;
|
||||||
|
|
||||||
|
# Client PWA
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
}
|
||||||
|
|
||||||
|
# WebSocket LiveKit
|
||||||
|
location /livekit {
|
||||||
|
proxy_pass http://localhost:7880;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "Upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🐛 Dépannage
|
||||||
|
|
||||||
|
### Erreur "Port déjà utilisé"
|
||||||
|
|
||||||
|
**Port 3000 (API)**
|
||||||
|
```bash
|
||||||
|
# Trouver le processus
|
||||||
|
lsof -i :3000
|
||||||
|
# Tuer ou changer PORT dans .env
|
||||||
|
```
|
||||||
|
|
||||||
|
**Port 7880 (LiveKit)**
|
||||||
|
```bash
|
||||||
|
lsof -i :7880
|
||||||
|
# Arrêter LiveKit ou changer dans config.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
### IP détectée incorrecte
|
||||||
|
|
||||||
|
**Lister toutes les interfaces réseau :**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# macOS
|
||||||
|
ifconfig | grep "inet "
|
||||||
|
|
||||||
|
# Linux
|
||||||
|
ip addr show
|
||||||
|
```
|
||||||
|
|
||||||
|
Puis modifier `server/.env` avec la bonne IP.
|
||||||
|
|
||||||
|
### Clients ne peuvent pas se connecter
|
||||||
|
|
||||||
|
**1. Vérifier le serveur**
|
||||||
|
```bash
|
||||||
|
curl http://IP_SERVEUR:3000/health
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Vérifier LiveKit**
|
||||||
|
```bash
|
||||||
|
curl http://IP_SERVEUR:7880
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Firewall**
|
||||||
|
|
||||||
|
macOS/Linux : autoriser ports 3000, 7880, 7882 (UDP)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# macOS
|
||||||
|
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --add /path/to/node
|
||||||
|
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --unblock /path/to/livekit-server
|
||||||
|
|
||||||
|
# Linux (ufw)
|
||||||
|
sudo ufw allow 3000/tcp
|
||||||
|
sudo ufw allow 7880/tcp
|
||||||
|
sudo ufw allow 7882/udp
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pas d'audio (macOS)
|
||||||
|
|
||||||
|
**Permissions microphone :**
|
||||||
|
|
||||||
|
1. **Navigateur** : Autoriser le micro dans les préférences Safari/Chrome
|
||||||
|
2. **Terminal** : `Réglages Système > Confidentialité > Microphone` → autoriser Terminal
|
||||||
|
|
||||||
|
**Carte son externe :**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Lister devices
|
||||||
|
curl http://localhost:3000/admin/devices/list
|
||||||
|
|
||||||
|
# Sélectionner via interface admin
|
||||||
|
open http://localhost:3000/admin
|
||||||
|
```
|
||||||
|
|
||||||
|
### Pas d'audio (Linux)
|
||||||
|
|
||||||
|
**Vérifier PipeWire :**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl --user status pipewire
|
||||||
|
pw-cli info 0
|
||||||
|
```
|
||||||
|
|
||||||
|
**Démarrer si inactif :**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl --user start pipewire pipewire-pulse
|
||||||
|
```
|
||||||
|
|
||||||
|
**Lister devices PulseAudio :**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pactl list short sources # Inputs
|
||||||
|
pactl list short sinks # Outputs
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📚 Architecture Portable
|
||||||
|
|
||||||
|
### Structure des fichiers de configuration
|
||||||
|
|
||||||
|
```
|
||||||
|
PTT Live/
|
||||||
|
├── server/
|
||||||
|
│ ├── .env # Généré par install (IP auto)
|
||||||
|
│ └── config/
|
||||||
|
│ └── config.yaml # LIVEKIT_URL = AUTO
|
||||||
|
├── client/
|
||||||
|
│ ├── .env # Généré par install
|
||||||
|
│ └── .env.example # Template
|
||||||
|
└── install/
|
||||||
|
├── macos.sh # Détection IP + génération .env
|
||||||
|
└── linux.sh # Idem
|
||||||
|
```
|
||||||
|
|
||||||
|
### Flux de configuration automatique
|
||||||
|
|
||||||
|
```
|
||||||
|
1. install.sh
|
||||||
|
└─> Détecte OS (macOS/Linux)
|
||||||
|
└─> Lance install/{os}.sh
|
||||||
|
└─> Détecte IP réseau (ifconfig/hostname)
|
||||||
|
└─> Génère server/.env avec LIVEKIT_URL=AUTO
|
||||||
|
└─> Génère client/.env avec IP dans commentaires
|
||||||
|
|
||||||
|
2. npm run dev (serveur)
|
||||||
|
└─> Lit server/.env
|
||||||
|
└─> Si LIVEKIT_URL=AUTO → détecte IP au runtime (index.js:75)
|
||||||
|
└─> Lance LiveKit sur 0.0.0.0:7880
|
||||||
|
└─> Retourne ws://IP_DETECTÉE:7880 aux clients via /token
|
||||||
|
|
||||||
|
3. Client se connecte
|
||||||
|
└─> Appelle POST /token avec username + groupId
|
||||||
|
└─> Reçoit { token, url: "ws://192.168.x.x:7880" }
|
||||||
|
└─> Se connecte automatiquement à la bonne URL
|
||||||
|
```
|
||||||
|
|
||||||
|
**Résultat** : **Zéro configuration manuelle** d'IP pour l'utilisateur final.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 Sécurité en Production
|
||||||
|
|
||||||
|
### Bonnes pratiques
|
||||||
|
|
||||||
|
1. **Changer les clés LiveKit** (par défaut : `devkey/secret`)
|
||||||
|
|
||||||
|
Modifier `server/.env` :
|
||||||
|
```bash
|
||||||
|
LIVEKIT_API_KEY=$(openssl rand -hex 32)
|
||||||
|
LIVEKIT_API_SECRET=$(openssl rand -hex 64)
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Activer HTTPS/WSS** (avec certificats Let's Encrypt ou mkcert)
|
||||||
|
|
||||||
|
3. **Firewall strict** : Autoriser seulement les ports nécessaires
|
||||||
|
|
||||||
|
4. **Authentification admin** : Ajouter un mot de passe sur `/admin` (Phase 2.3)
|
||||||
|
|
||||||
|
5. **VLAN dédié** : Isoler le réseau PTT Live du reste du LAN (événements)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✨ Fonctionnalités Portables
|
||||||
|
|
||||||
|
✅ **Auto-détection IP réseau** (macOS/Linux)
|
||||||
|
✅ **Auto-détection devices audio** (API `/admin/devices/list`)
|
||||||
|
✅ **Génération .env automatique** lors de l'installation
|
||||||
|
✅ **Scripts start.sh multi-OS** (dev/prod)
|
||||||
|
✅ **Configuration dynamique Vite** (loadEnv)
|
||||||
|
✅ **Support JACK, PipeWire, CoreAudio**
|
||||||
|
✅ **PWA installable** (iOS/Android)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📖 Documentation Complémentaire
|
||||||
|
|
||||||
|
- [README.md](README.md) — Guide utilisateur complet
|
||||||
|
- [NETWORK_SETUP.md](NETWORK_SETUP.md) — Configuration réseau détaillée
|
||||||
|
- [CLAUDE.md](CLAUDE.md) — Documentation développement
|
||||||
|
- [docs/](docs/) — Guides techniques (JACK, Dante, AES67)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Dernière mise à jour** : 2026-05-27
|
||||||
|
**Version** : 0.2.0 (Portable)
|
||||||
@@ -8,20 +8,43 @@ Communiquez via smartphone (PWA) en WiFi, le serveur fait le pont avec l'install
|
|||||||
|
|
||||||
## 🚀 Démarrage rapide
|
## 🚀 Démarrage rapide
|
||||||
|
|
||||||
### Prérequis
|
### Installation Automatique (Recommandé)
|
||||||
|
|
||||||
- Node.js 20+ ([télécharger](https://nodejs.org))
|
**Un seul script pour tout installer** (détection automatique macOS/Linux) :
|
||||||
- Compte LiveKit Cloud gratuit ([créer ici](https://cloud.livekit.io))
|
|
||||||
|
|
||||||
### Installation (5 minutes)
|
```bash
|
||||||
|
# Lancer l'installation portable
|
||||||
|
./install.sh
|
||||||
|
|
||||||
1. **Installer les dépendances**
|
# Démarrer le système
|
||||||
|
./start.sh --dev
|
||||||
|
```
|
||||||
|
|
||||||
|
✨ **L'installeur configure automatiquement** :
|
||||||
|
- LiveKit Server local (pas besoin de compte cloud)
|
||||||
|
- Détection et configuration IP réseau
|
||||||
|
- Backends audio (sox/PipeWire/JACK selon OS)
|
||||||
|
- Toutes les dépendances
|
||||||
|
|
||||||
|
📖 **Guide portable complet** : [README-PORTABLE.md](README-PORTABLE.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Installation Manuelle (avec LiveKit Cloud)
|
||||||
|
|
||||||
|
**Alternative si vous préférez utiliser LiveKit Cloud**
|
||||||
|
|
||||||
|
1. **Prérequis**
|
||||||
|
- Node.js 20+ ([télécharger](https://nodejs.org))
|
||||||
|
- Compte LiveKit Cloud gratuit ([créer ici](https://cloud.livekit.io))
|
||||||
|
|
||||||
|
2. **Installer les dépendances**
|
||||||
```bash
|
```bash
|
||||||
cd server && npm install
|
cd server && npm install
|
||||||
cd ../client && npm install
|
cd ../client && npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Configurer LiveKit Cloud**
|
3. **Configurer LiveKit Cloud**
|
||||||
|
|
||||||
- Créer compte sur https://cloud.livekit.io
|
- Créer compte sur https://cloud.livekit.io
|
||||||
- Créer un projet
|
- Créer un projet
|
||||||
@@ -35,7 +58,7 @@ Communiquez via smartphone (PWA) en WiFi, le serveur fait le pont avec l'install
|
|||||||
USE_LOCAL_LIVEKIT=false
|
USE_LOCAL_LIVEKIT=false
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **Démarrer**
|
4. **Démarrer**
|
||||||
|
|
||||||
Terminal 1 :
|
Terminal 1 :
|
||||||
```bash
|
```bash
|
||||||
@@ -47,13 +70,13 @@ Communiquez via smartphone (PWA) en WiFi, le serveur fait le pont avec l'install
|
|||||||
cd client && npm run dev
|
cd client && npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
4. **Tester** : http://localhost:5173
|
5. **Tester** : https://localhost:5173
|
||||||
|
|
||||||
- Se connecter avec votre nom
|
- Se connecter avec votre nom
|
||||||
- Ouvrir second onglet avec autre nom
|
- Ouvrir second onglet avec autre nom
|
||||||
- Maintenir bouton PTT pour parler !
|
- Maintenir bouton PTT pour parler !
|
||||||
|
|
||||||
📖 **Guide complet** : [docs/SETUP_LIVEKIT.md](docs/SETUP_LIVEKIT.md)
|
📖 **Guide LiveKit Cloud** : [docs/SETUP_LIVEKIT.md](docs/SETUP_LIVEKIT.md)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -84,6 +107,8 @@ Voir le guide complet : [docs/SETUP_LIVEKIT.md](docs/SETUP_LIVEKIT.md)
|
|||||||
|
|
||||||
## 📚 Documentation
|
## 📚 Documentation
|
||||||
|
|
||||||
|
- **[README-PORTABLE.md](README-PORTABLE.md)** - 🆕 **Guide déploiement portable** (zéro config)
|
||||||
|
- **[NETWORK_SETUP.md](NETWORK_SETUP.md)** - Configuration réseau multi-appareils
|
||||||
- **[docs/SETUP_LIVEKIT.md](docs/SETUP_LIVEKIT.md)** - Configuration LiveKit (Cloud + Local)
|
- **[docs/SETUP_LIVEKIT.md](docs/SETUP_LIVEKIT.md)** - Configuration LiveKit (Cloud + Local)
|
||||||
- **[CLAUDE.md](CLAUDE.md)** - Documentation développement complète
|
- **[CLAUDE.md](CLAUDE.md)** - Documentation développement complète
|
||||||
- **[TODO.md](TODO.md)** - Progression des phases
|
- **[TODO.md](TODO.md)** - Progression des phases
|
||||||
@@ -92,13 +117,12 @@ Voir le guide complet : [docs/SETUP_LIVEKIT.md](docs/SETUP_LIVEKIT.md)
|
|||||||
|
|
||||||
## 🎯 État du projet
|
## 🎯 État du projet
|
||||||
|
|
||||||
- ✅ **Phase 1.1** : Infrastructure
|
- ✅ **Phase 1** : MVP fonctionnel (WebRTC + PTT)
|
||||||
- ✅ **Phase 1.2** : Serveur + API REST
|
- ✅ **Phase 2** : Fonctionnalités avancées (groupes, routing, admin)
|
||||||
- ⏳ **Phase 1.3** : Bridge audio macOS
|
- 🆕 **Portable** : Installation zéro-config macOS/Linux
|
||||||
- ✅ **Phase 1.4** : Client PWA React
|
- ⏳ **Phase 3** : Intégrations audio pro (Dante, AES67)
|
||||||
- ⏳ **Phase 1.5** : Tests validation
|
|
||||||
|
|
||||||
**Version actuelle** : 0.1.0 (Phase 1 MVP en cours)
|
**Version actuelle** : 0.2.0 (Portable - production-ready)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+12
-4
@@ -1,7 +1,15 @@
|
|||||||
# PTT Live Client - Configuration environnement
|
# Configuration Client PTT Live
|
||||||
|
# Copiez ce fichier en .env et adaptez selon votre environnement
|
||||||
|
|
||||||
# URL API serveur (en dev, utilise le proxy Vite)
|
# URL de l'API serveur
|
||||||
|
# En développement : laissez /api pour utiliser le proxy Vite
|
||||||
|
# En production : spécifiez l'URL complète du serveur
|
||||||
|
# Exemples :
|
||||||
|
# VITE_API_URL=/api # Dev local (via proxy Vite)
|
||||||
|
# VITE_API_URL=http://192.168.1.100:3000 # Serveur sur réseau local
|
||||||
|
# VITE_API_URL=https://ptt.example.com # Production avec domaine
|
||||||
VITE_API_URL=/api
|
VITE_API_URL=/api
|
||||||
|
|
||||||
# Pour production, pointer vers le serveur
|
# URL LiveKit WebSocket (optionnel, normalement auto-détectée)
|
||||||
# VITE_API_URL=https://your-server.com
|
# Ne définir que si vous voulez forcer une URL spécifique
|
||||||
|
# VITE_LIVEKIT_URL=ws://192.168.1.100:7880
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ define(['./workbox-290dd570'], (function (workbox) { 'use strict';
|
|||||||
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
"revision": "3ca0b8505b4bec776b69afdba2768812"
|
||||||
}, {
|
}, {
|
||||||
"url": "index.html",
|
"url": "index.html",
|
||||||
"revision": "0.oebo7b1mt4g"
|
"revision": "0.spc2v3301v8"
|
||||||
}], {});
|
}], {});
|
||||||
workbox.cleanupOutdatedCaches();
|
workbox.cleanupOutdatedCaches();
|
||||||
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+42
-108
@@ -15,7 +15,7 @@ function Admin() {
|
|||||||
|
|
||||||
// Audio devices (Phase 2.5)
|
// Audio devices (Phase 2.5)
|
||||||
const [audioDevices, setAudioDevices] = useState([]);
|
const [audioDevices, setAudioDevices] = useState([]);
|
||||||
const [currentDevice, setCurrentDevice] = useState(null);
|
const [currentDevice, setCurrentDevice] = useState({ inputChannels: 8, outputChannels: 8 });
|
||||||
const [selectedInputDevice, setSelectedInputDevice] = useState(null);
|
const [selectedInputDevice, setSelectedInputDevice] = useState(null);
|
||||||
const [selectedOutputDevice, setSelectedOutputDevice] = useState(null);
|
const [selectedOutputDevice, setSelectedOutputDevice] = useState(null);
|
||||||
const [selectedSampleRate, setSelectedSampleRate] = useState(48000);
|
const [selectedSampleRate, setSelectedSampleRate] = useState(48000);
|
||||||
@@ -30,8 +30,7 @@ function Admin() {
|
|||||||
const [editingGroup, setEditingGroup] = useState(null);
|
const [editingGroup, setEditingGroup] = useState(null);
|
||||||
const [groupForm, setGroupForm] = useState({
|
const [groupForm, setGroupForm] = useState({
|
||||||
name: '',
|
name: '',
|
||||||
audioBitrate: 96,
|
audioBitrate: 96
|
||||||
channels: []
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rafraîchissement automatique
|
// Rafraîchissement automatique
|
||||||
@@ -102,14 +101,16 @@ function Admin() {
|
|||||||
const channelNamesData = await channelNamesRes.json();
|
const channelNamesData = await channelNamesRes.json();
|
||||||
|
|
||||||
setAudioDevices(devicesData.devices || []);
|
setAudioDevices(devicesData.devices || []);
|
||||||
setCurrentDevice(currentData.device || {});
|
|
||||||
|
const device = currentData.device || { inputChannels: 8, outputChannels: 8 };
|
||||||
|
setCurrentDevice(device);
|
||||||
setChannelNames(channelNamesData.channelNames || { inputs: {}, outputs: {} });
|
setChannelNames(channelNamesData.channelNames || { inputs: {}, outputs: {} });
|
||||||
|
|
||||||
// Ne réinitialiser les sélections que si l'utilisateur n'est pas en train d'éditer
|
// Ne réinitialiser les sélections que si l'utilisateur n'est pas en train d'éditer
|
||||||
if (!isEditingAudio) {
|
if (!isEditingAudio) {
|
||||||
setSelectedInputDevice(currentData.device?.inputDeviceId ?? null);
|
setSelectedInputDevice(device.inputDeviceId ?? null);
|
||||||
setSelectedOutputDevice(currentData.device?.outputDeviceId ?? null);
|
setSelectedOutputDevice(device.outputDeviceId ?? null);
|
||||||
setSelectedSampleRate(currentData.device?.sampleRate || 48000);
|
setSelectedSampleRate(device.sampleRate || 48000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -189,8 +190,7 @@ function Admin() {
|
|||||||
setEditingGroup(group.id);
|
setEditingGroup(group.id);
|
||||||
setGroupForm({
|
setGroupForm({
|
||||||
name: group.name,
|
name: group.name,
|
||||||
audioBitrate: group.audioBitrate || 96,
|
audioBitrate: group.audioBitrate || 96
|
||||||
channels: group.channels || []
|
|
||||||
});
|
});
|
||||||
setShowGroupForm(true);
|
setShowGroupForm(true);
|
||||||
};
|
};
|
||||||
@@ -198,38 +198,12 @@ function Admin() {
|
|||||||
const resetGroupForm = () => {
|
const resetGroupForm = () => {
|
||||||
setGroupForm({
|
setGroupForm({
|
||||||
name: '',
|
name: '',
|
||||||
audioBitrate: 96,
|
audioBitrate: 96
|
||||||
channels: []
|
|
||||||
});
|
});
|
||||||
setShowGroupForm(false);
|
setShowGroupForm(false);
|
||||||
setEditingGroup(null);
|
setEditingGroup(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addChannel = () => {
|
|
||||||
setGroupForm({
|
|
||||||
...groupForm,
|
|
||||||
channels: [
|
|
||||||
...groupForm.channels,
|
|
||||||
{ name: '', audioInput: 0, audioOutput: 0 }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateChannel = (index, field, value) => {
|
|
||||||
const newChannels = [...groupForm.channels];
|
|
||||||
newChannels[index] = {
|
|
||||||
...newChannels[index],
|
|
||||||
[field]: field === 'audioInput' || field === 'audioOutput' ? parseInt(value) : value
|
|
||||||
};
|
|
||||||
setGroupForm({ ...groupForm, channels: newChannels });
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeChannel = (index) => {
|
|
||||||
const newChannels = [...groupForm.channels];
|
|
||||||
newChannels.splice(index, 1);
|
|
||||||
setGroupForm({ ...groupForm, channels: newChannels });
|
|
||||||
};
|
|
||||||
|
|
||||||
// ========== Gestion audio devices (Phase 2.5) ==========
|
// ========== Gestion audio devices (Phase 2.5) ==========
|
||||||
|
|
||||||
const handleSaveChannelNames = async () => {
|
const handleSaveChannelNames = async () => {
|
||||||
@@ -270,8 +244,8 @@ function Admin() {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
inputDeviceId: selectedInputDevice !== null ? parseInt(selectedInputDevice) : undefined,
|
inputDeviceId: selectedInputDevice || undefined,
|
||||||
outputDeviceId: selectedOutputDevice !== null ? parseInt(selectedOutputDevice) : undefined,
|
outputDeviceId: selectedOutputDevice || undefined,
|
||||||
sampleRate: parseInt(selectedSampleRate)
|
sampleRate: parseInt(selectedSampleRate)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -415,43 +389,9 @@ function Admin() {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="channels-section">
|
<p style={{color: 'var(--color-text-secondary)', fontSize: '0.9rem', marginTop: 'var(--spacing-md)'}}>
|
||||||
<div className="channels-header">
|
Le routing audio se configure dans l'onglet "Audio" via la matrice de routing.
|
||||||
<h4>Canaux audio</h4>
|
</p>
|
||||||
<button type="button" onClick={addChannel} className="btn-small">
|
|
||||||
+ Canal
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{groupForm.channels.map((channel, index) => (
|
|
||||||
<div key={index} className="channel-item">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="Nom canal (ex: Principal, Backup...)"
|
|
||||||
value={channel.name}
|
|
||||||
onChange={(e) => updateChannel(index, 'name', e.target.value)}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
placeholder="Input"
|
|
||||||
value={channel.audioInput}
|
|
||||||
onChange={(e) => updateChannel(index, 'audioInput', e.target.value)}
|
|
||||||
min="0"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
placeholder="Output"
|
|
||||||
value={channel.audioOutput}
|
|
||||||
onChange={(e) => updateChannel(index, 'audioOutput', e.target.value)}
|
|
||||||
min="0"
|
|
||||||
/>
|
|
||||||
<button type="button" onClick={() => removeChannel(index)} className="btn-danger">
|
|
||||||
×
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="form-actions">
|
<div className="form-actions">
|
||||||
<button type="submit" className="btn-primary">
|
<button type="submit" className="btn-primary">
|
||||||
@@ -482,18 +422,7 @@ function Admin() {
|
|||||||
|
|
||||||
<div className="group-info">
|
<div className="group-info">
|
||||||
<span>Bitrate: {group.audioBitrate || 96} kbps</span>
|
<span>Bitrate: {group.audioBitrate || 96} kbps</span>
|
||||||
<span>Canaux: {group.channels?.length || 0}</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{group.channels && group.channels.length > 0 && (
|
|
||||||
<div className="channels-list">
|
|
||||||
{group.channels.map(channel => (
|
|
||||||
<div key={channel.id} className="channel-badge">
|
|
||||||
{channel.name} (I/O: {channel.audioInput}/{channel.audioOutput})
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -514,22 +443,22 @@ function Admin() {
|
|||||||
value={selectedInputDevice ?? ''}
|
value={selectedInputDevice ?? ''}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setIsEditingAudio(true);
|
setIsEditingAudio(true);
|
||||||
setSelectedInputDevice(e.target.value === '' ? null : parseInt(e.target.value));
|
setSelectedInputDevice(e.target.value === '' ? null : e.target.value);
|
||||||
}}
|
}}
|
||||||
className="device-select"
|
className="device-select"
|
||||||
>
|
>
|
||||||
<option value="">-- Sélectionner une carte --</option>
|
<option value="">-- Sélectionner une carte --</option>
|
||||||
{audioDevices
|
{audioDevices
|
||||||
.filter(d => d.maxInputChannels > 0)
|
.filter(d => d.maxInputChannels > 0)
|
||||||
.map(device => (
|
.map((device, index) => (
|
||||||
<option key={device.id} value={device.id}>
|
<option key={`input-${device.id}-${index}`} value={device.id}>
|
||||||
{device.name} - {device.maxInputChannels} canaux - {device.defaultSampleRate}Hz
|
{device.name} - {device.maxInputChannels} canaux - {device.defaultSampleRate}Hz
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{selectedInputDevice !== null && (
|
{selectedInputDevice !== null && selectedInputDevice !== '' && (
|
||||||
<p style={{marginTop: 'var(--spacing-sm)', color: 'var(--color-text-secondary)', fontSize: '0.85rem'}}>
|
<p style={{marginTop: 'var(--spacing-sm)', color: 'var(--color-text-secondary)', fontSize: '0.85rem', wordBreak: 'break-all'}}>
|
||||||
Device ID {selectedInputDevice} sélectionné
|
Device ID: {selectedInputDevice}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -540,22 +469,22 @@ function Admin() {
|
|||||||
value={selectedOutputDevice ?? ''}
|
value={selectedOutputDevice ?? ''}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setIsEditingAudio(true);
|
setIsEditingAudio(true);
|
||||||
setSelectedOutputDevice(e.target.value === '' ? null : parseInt(e.target.value));
|
setSelectedOutputDevice(e.target.value === '' ? null : e.target.value);
|
||||||
}}
|
}}
|
||||||
className="device-select"
|
className="device-select"
|
||||||
>
|
>
|
||||||
<option value="">-- Sélectionner une carte --</option>
|
<option value="">-- Sélectionner une carte --</option>
|
||||||
{audioDevices
|
{audioDevices
|
||||||
.filter(d => d.maxOutputChannels > 0)
|
.filter(d => d.maxOutputChannels > 0)
|
||||||
.map(device => (
|
.map((device, index) => (
|
||||||
<option key={device.id} value={device.id}>
|
<option key={`output-${device.id}-${index}`} value={device.id}>
|
||||||
{device.name} - {device.maxOutputChannels} canaux - {device.defaultSampleRate}Hz
|
{device.name} - {device.maxOutputChannels} canaux - {device.defaultSampleRate}Hz
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{selectedOutputDevice !== null && (
|
{selectedOutputDevice !== null && selectedOutputDevice !== '' && (
|
||||||
<p style={{marginTop: 'var(--spacing-sm)', color: 'var(--color-text-secondary)', fontSize: '0.85rem'}}>
|
<p style={{marginTop: 'var(--spacing-sm)', color: 'var(--color-text-secondary)', fontSize: '0.85rem', wordBreak: 'break-all'}}>
|
||||||
Device ID {selectedOutputDevice} sélectionné
|
Device ID: {selectedOutputDevice}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -603,9 +532,11 @@ function Admin() {
|
|||||||
|
|
||||||
<div style={{display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 'var(--spacing-xl)'}}>
|
<div style={{display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 'var(--spacing-xl)'}}>
|
||||||
<div>
|
<div>
|
||||||
<h4 style={{marginBottom: 'var(--spacing-md)', color: 'var(--color-text-secondary)'}}>Entrées (Inputs)</h4>
|
<h4 style={{marginBottom: 'var(--spacing-md)', color: 'var(--color-text-secondary)'}}>
|
||||||
|
Entrées (Inputs) - {currentDevice.inputChannels || 0} canaux disponibles
|
||||||
|
</h4>
|
||||||
<div style={{display: 'grid', gap: 'var(--spacing-sm)'}}>
|
<div style={{display: 'grid', gap: 'var(--spacing-sm)'}}>
|
||||||
{Array.from({length: 8}, (_, i) => (
|
{Array.from({length: currentDevice.inputChannels || 8}, (_, i) => (
|
||||||
<div key={`input-${i}`} style={{display: 'grid', gridTemplateColumns: '40px 1fr', gap: 'var(--spacing-sm)', alignItems: 'center'}}>
|
<div key={`input-${i}`} style={{display: 'grid', gridTemplateColumns: '40px 1fr', gap: 'var(--spacing-sm)', alignItems: 'center'}}>
|
||||||
<span style={{color: 'var(--color-text-secondary)', fontSize: '0.85rem'}}>{i}</span>
|
<span style={{color: 'var(--color-text-secondary)', fontSize: '0.85rem'}}>{i}</span>
|
||||||
<input
|
<input
|
||||||
@@ -629,9 +560,11 @@ function Admin() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h4 style={{marginBottom: 'var(--spacing-md)', color: 'var(--color-text-secondary)'}}>Sorties (Outputs)</h4>
|
<h4 style={{marginBottom: 'var(--spacing-md)', color: 'var(--color-text-secondary)'}}>
|
||||||
|
Sorties (Outputs) - {currentDevice.outputChannels || 0} canaux disponibles
|
||||||
|
</h4>
|
||||||
<div style={{display: 'grid', gap: 'var(--spacing-sm)'}}>
|
<div style={{display: 'grid', gap: 'var(--spacing-sm)'}}>
|
||||||
{Array.from({length: 8}, (_, i) => (
|
{Array.from({length: currentDevice.outputChannels || 8}, (_, i) => (
|
||||||
<div key={`output-${i}`} style={{display: 'grid', gridTemplateColumns: '40px 1fr', gap: 'var(--spacing-sm)', alignItems: 'center'}}>
|
<div key={`output-${i}`} style={{display: 'grid', gridTemplateColumns: '40px 1fr', gap: 'var(--spacing-sm)', alignItems: 'center'}}>
|
||||||
<span style={{color: 'var(--color-text-secondary)', fontSize: '0.85rem'}}>{i}</span>
|
<span style={{color: 'var(--color-text-secondary)', fontSize: '0.85rem'}}>{i}</span>
|
||||||
<input
|
<input
|
||||||
@@ -658,13 +591,14 @@ function Admin() {
|
|||||||
|
|
||||||
<AudioRoutingMatrix groups={groups} channelNames={channelNames} />
|
<AudioRoutingMatrix groups={groups} channelNames={channelNames} />
|
||||||
|
|
||||||
{currentDevice && Object.keys(currentDevice).length > 0 && (
|
{currentDevice && currentDevice.inputDeviceId && (
|
||||||
<div className="current-config">
|
<div className="current-config">
|
||||||
<h3>Configuration actuelle</h3>
|
<h3>Configuration actuelle</h3>
|
||||||
<div className="config-info">
|
<div className="config-info">
|
||||||
<p><strong>Input Device ID:</strong> {currentDevice.inputDeviceId ?? 'Non configuré'}</p>
|
<p><strong>Input Device:</strong> {currentDevice.inputDeviceName || currentDevice.inputDeviceId}</p>
|
||||||
<p><strong>Output Device ID:</strong> {currentDevice.outputDeviceId ?? 'Non configuré'}</p>
|
<p><strong>Output Device:</strong> {currentDevice.outputDeviceName || currentDevice.outputDeviceId}</p>
|
||||||
<p><strong>Sample Rate:</strong> {currentDevice.sampleRate ?? 48000} Hz</p>
|
<p><strong>Sample Rate:</strong> {currentDevice.sampleRate ?? 48000} Hz</p>
|
||||||
|
<p><strong>Canaux:</strong> {currentDevice.inputChannels} entrées / {currentDevice.outputChannels} sorties</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -683,9 +617,9 @@ function Admin() {
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{audioDevices.map(device => (
|
{audioDevices.map((device, index) => (
|
||||||
<tr key={device.id}>
|
<tr key={`${device.id}-${index}`}>
|
||||||
<td>{device.id}</td>
|
<td style={{fontSize: '0.75rem', wordBreak: 'break-all', maxWidth: '200px'}}>{device.id}</td>
|
||||||
<td>{device.name}</td>
|
<td>{device.name}</td>
|
||||||
<td>{device.maxInputChannels}</td>
|
<td>{device.maxInputChannels}</td>
|
||||||
<td>{device.maxOutputChannels}</td>
|
<td>{device.maxOutputChannels}</td>
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ function AudioRoutingMatrix({ groups, channelNames }) {
|
|||||||
const [routing, setRouting] = useState({ inputToGroup: {}, groupToOutput: {}, gains: {} });
|
const [routing, setRouting] = useState({ inputToGroup: {}, groupToOutput: {}, gains: {} });
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [showOnlyNamedChannels, setShowOnlyNamedChannels] = useState(false);
|
const [showOnlyNamedChannels, setShowOnlyNamedChannels] = useState(false);
|
||||||
|
const [audioDevice, setAudioDevice] = useState({ inputChannels: 8, outputChannels: 8 });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadRouting();
|
loadRouting();
|
||||||
|
loadAudioDevice();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const loadRouting = async () => {
|
const loadRouting = async () => {
|
||||||
@@ -30,6 +32,21 @@ function AudioRoutingMatrix({ groups, channelNames }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadAudioDevice = async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/admin/audio/device`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setAudioDevice({
|
||||||
|
inputChannels: data.device?.inputChannels || 8,
|
||||||
|
outputChannels: data.device?.outputChannels || 8
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur chargement audio device:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const saveRouting = async () => {
|
const saveRouting = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/admin/audio/routing`, {
|
const res = await fetch(`${API_URL}/admin/audio/routing`, {
|
||||||
@@ -146,7 +163,7 @@ function AudioRoutingMatrix({ groups, channelNames }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getVisibleInputChannels = () => {
|
const getVisibleInputChannels = () => {
|
||||||
const allInputs = Array.from({length: 8}, (_, i) => i);
|
const allInputs = Array.from({length: audioDevice.inputChannels}, (_, i) => i);
|
||||||
if (showOnlyNamedChannels) {
|
if (showOnlyNamedChannels) {
|
||||||
return allInputs.filter(i => hasCustomName('inputs', i));
|
return allInputs.filter(i => hasCustomName('inputs', i));
|
||||||
}
|
}
|
||||||
@@ -154,7 +171,7 @@ function AudioRoutingMatrix({ groups, channelNames }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getVisibleOutputChannels = () => {
|
const getVisibleOutputChannels = () => {
|
||||||
const allOutputs = Array.from({length: 8}, (_, i) => i);
|
const allOutputs = Array.from({length: audioDevice.outputChannels}, (_, i) => i);
|
||||||
if (showOnlyNamedChannels) {
|
if (showOnlyNamedChannels) {
|
||||||
return allOutputs.filter(i => hasCustomName('outputs', i));
|
return allOutputs.filter(i => hasCustomName('outputs', i));
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-4
@@ -1,9 +1,17 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import { VitePWA } from 'vite-plugin-pwa';
|
import { VitePWA } from 'vite-plugin-pwa';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
|
// Charger les variables d'environnement
|
||||||
|
const env = loadEnv(mode, process.cwd(), '');
|
||||||
|
|
||||||
|
// Déterminer l'URL de l'API (utilise variable d'environnement ou fallback localhost)
|
||||||
|
const apiUrl = env.VITE_API_URL || 'http://localhost:3000';
|
||||||
|
const livekitUrl = env.VITE_LIVEKIT_URL || 'ws://localhost:7880';
|
||||||
|
|
||||||
|
return {
|
||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
VitePWA({
|
VitePWA({
|
||||||
@@ -68,12 +76,12 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:3000',
|
target: apiUrl.startsWith('/') ? 'http://localhost:3000' : apiUrl,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
},
|
},
|
||||||
'/livekit': {
|
'/livekit': {
|
||||||
target: 'ws://192.168.0.146:7880',
|
target: livekitUrl,
|
||||||
ws: true,
|
ws: true,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/livekit/, '')
|
rewrite: (path) => path.replace(/^\/livekit/, '')
|
||||||
@@ -84,4 +92,5 @@ export default defineConfig({
|
|||||||
outDir: 'dist',
|
outDir: 'dist',
|
||||||
sourcemap: true
|
sourcemap: true
|
||||||
}
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Executable
+47
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# PTT Live - Script d'installation multi-OS
|
||||||
|
# Détecte automatiquement le système et lance l'installeur approprié
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
echo -e "${BLUE}=================================="
|
||||||
|
echo "🚀 PTT Live - Installation"
|
||||||
|
echo "==================================${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Détection du système d'exploitation
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
echo -e "${GREEN}📱 Système détecté : macOS${NC}"
|
||||||
|
echo ""
|
||||||
|
exec ./install/macos.sh
|
||||||
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
echo -e "${GREEN}🐧 Système détecté : Linux${NC}"
|
||||||
|
echo ""
|
||||||
|
exec ./install/linux.sh
|
||||||
|
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "win32" ]]; then
|
||||||
|
echo -e "${YELLOW}🪟 Système détecté : Windows${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${RED}❌ Windows n'est pas encore supporté (Phase 3)${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "Plateformes supportées :"
|
||||||
|
echo " • macOS (via Homebrew)"
|
||||||
|
echo " • Linux (Debian/Ubuntu/Fedora)"
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Système non reconnu : $OSTYPE${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "Plateformes supportées :"
|
||||||
|
echo " • macOS"
|
||||||
|
echo " • Linux"
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
+79
-11
@@ -222,6 +222,61 @@ install_node_deps() {
|
|||||||
echo "Dépendances Node.js installées !"
|
echo "Dépendances Node.js installées !"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Configuration réseau et génération .env
|
||||||
|
configure_network() {
|
||||||
|
echo ""
|
||||||
|
echo "Configuration réseau..."
|
||||||
|
|
||||||
|
# Détection IP réseau
|
||||||
|
NETWORK_IP=$(hostname -I | awk '{print $1}')
|
||||||
|
|
||||||
|
if [ -z "$NETWORK_IP" ]; then
|
||||||
|
echo "⚠️ IP réseau non détectée, utilisation localhost"
|
||||||
|
NETWORK_IP="localhost"
|
||||||
|
else
|
||||||
|
echo "✓ IP réseau détectée : ${NETWORK_IP}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Générer .env serveur
|
||||||
|
echo "Génération configuration serveur..."
|
||||||
|
|
||||||
|
cat > "$PROJECT_ROOT/server/.env" << EOF
|
||||||
|
# Configuration PTT Live Server
|
||||||
|
# Généré automatiquement par install/linux.sh
|
||||||
|
|
||||||
|
USE_LOCAL_LIVEKIT=true
|
||||||
|
|
||||||
|
# LiveKit Configuration
|
||||||
|
# AUTO = détection automatique IP réseau au démarrage
|
||||||
|
LIVEKIT_URL=AUTO
|
||||||
|
# En mode --dev, LiveKit utilise ces clés par défaut
|
||||||
|
LIVEKIT_API_KEY=devkey
|
||||||
|
LIVEKIT_API_SECRET=secret
|
||||||
|
|
||||||
|
# Server Configuration
|
||||||
|
PORT=3000
|
||||||
|
NODE_ENV=development
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "✓ Configuration serveur générée (server/.env)"
|
||||||
|
|
||||||
|
# Générer .env client
|
||||||
|
echo "Génération configuration client..."
|
||||||
|
|
||||||
|
cat > "$PROJECT_ROOT/client/.env" << EOF
|
||||||
|
# Configuration PTT Live Client
|
||||||
|
# Généré automatiquement par install/linux.sh
|
||||||
|
|
||||||
|
# En développement local, utilise le proxy Vite
|
||||||
|
VITE_API_URL=/api
|
||||||
|
|
||||||
|
# Pour accès réseau (autres devices), décommentez et mettez l'IP du serveur :
|
||||||
|
# VITE_API_URL=http://${NETWORK_IP}:3000
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "✓ Configuration client générée (client/.env)"
|
||||||
|
}
|
||||||
|
|
||||||
# Configuration audio
|
# Configuration audio
|
||||||
configure_audio() {
|
configure_audio() {
|
||||||
echo ""
|
echo ""
|
||||||
@@ -259,23 +314,35 @@ configure_audio() {
|
|||||||
print_summary() {
|
print_summary() {
|
||||||
echo ""
|
echo ""
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
echo " Installation terminée !"
|
echo " ✅ Installation terminée !"
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Prochaines étapes :"
|
echo "🚀 Démarrage rapide :"
|
||||||
echo ""
|
echo ""
|
||||||
echo "1. Démarrer le serveur :"
|
echo " # Mode développement (recommandé)"
|
||||||
echo " cd $PROJECT_ROOT/server"
|
echo " ./start.sh --dev"
|
||||||
echo " npm run dev"
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "2. Démarrer le client (autre terminal) :"
|
echo " # Mode production"
|
||||||
echo " cd $PROJECT_ROOT/client"
|
echo " ./start.sh"
|
||||||
echo " npm run dev"
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "3. Accéder à l'interface :"
|
echo "📝 OU manuellement (deux terminaux) :"
|
||||||
echo " http://localhost:5173"
|
echo ""
|
||||||
|
echo " Terminal 1 : cd $PROJECT_ROOT/server && npm run dev"
|
||||||
|
echo " Terminal 2 : cd $PROJECT_ROOT/client && npm run dev"
|
||||||
|
echo ""
|
||||||
|
echo "🌐 Accès après démarrage :"
|
||||||
|
echo " • Développement local : https://localhost:5173"
|
||||||
|
echo " • Depuis smartphone (WiFi) : https://${NETWORK_IP}:5173"
|
||||||
|
echo " • Admin : https://${NETWORK_IP}:5173/admin"
|
||||||
|
echo ""
|
||||||
|
echo "💡 Configuration réseau :"
|
||||||
|
echo " IP serveur détectée : ${NETWORK_IP}"
|
||||||
|
echo " LiveKit URL : AUTO (détection dynamique)"
|
||||||
|
echo ""
|
||||||
|
echo "📖 Documentation :"
|
||||||
|
echo " • README.md - Guide complet"
|
||||||
|
echo " • README-PORTABLE.md - Déploiement portable"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Documentation : $PROJECT_ROOT/README.md"
|
|
||||||
echo "========================================"
|
echo "========================================"
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
@@ -286,6 +353,7 @@ main() {
|
|||||||
install_system_deps
|
install_system_deps
|
||||||
install_livekit_server
|
install_livekit_server
|
||||||
install_node_deps
|
install_node_deps
|
||||||
|
configure_network
|
||||||
configure_audio
|
configure_audio
|
||||||
print_summary
|
print_summary
|
||||||
}
|
}
|
||||||
|
|||||||
+58
-12
@@ -82,7 +82,7 @@ echo ""
|
|||||||
|
|
||||||
# Installer dépendances serveur
|
# Installer dépendances serveur
|
||||||
echo "📦 Installation dépendances serveur..."
|
echo "📦 Installation dépendances serveur..."
|
||||||
cd ../server
|
cd ./server
|
||||||
npm install
|
npm install
|
||||||
echo -e "${GREEN}✅ Dépendances serveur installées${NC}"
|
echo -e "${GREEN}✅ Dépendances serveur installées${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -96,14 +96,30 @@ echo ""
|
|||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Créer fichier .env
|
# Détecter l'IP réseau locale
|
||||||
echo "🔑 Génération configuration LiveKit..."
|
echo "🌐 Détection configuration réseau..."
|
||||||
|
NETWORK_IP=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -n 1)
|
||||||
|
|
||||||
|
if [ -z "$NETWORK_IP" ]; then
|
||||||
|
echo -e "${YELLOW}⚠️ IP réseau non détectée, utilisation localhost${NC}"
|
||||||
|
NETWORK_IP="localhost"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}✅ IP réseau détectée : ${NETWORK_IP}${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Créer fichier .env serveur
|
||||||
|
echo "🔑 Génération configuration serveur..."
|
||||||
|
|
||||||
cat > server/.env << EOF
|
cat > server/.env << EOF
|
||||||
|
# Configuration PTT Live Server
|
||||||
|
# Généré automatiquement par install/macos.sh
|
||||||
|
|
||||||
USE_LOCAL_LIVEKIT=true
|
USE_LOCAL_LIVEKIT=true
|
||||||
|
|
||||||
# LiveKit Configuration
|
# LiveKit Configuration
|
||||||
LIVEKIT_URL=ws://localhost:7880
|
# AUTO = détection automatique IP réseau au démarrage
|
||||||
|
LIVEKIT_URL=AUTO
|
||||||
# En mode --dev, LiveKit utilise ces clés par défaut
|
# En mode --dev, LiveKit utilise ces clés par défaut
|
||||||
LIVEKIT_API_KEY=devkey
|
LIVEKIT_API_KEY=devkey
|
||||||
LIVEKIT_API_SECRET=secret
|
LIVEKIT_API_SECRET=secret
|
||||||
@@ -113,22 +129,52 @@ PORT=3000
|
|||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo -e "${GREEN}✅ Clés API générées (server/.env)${NC}"
|
echo -e "${GREEN}✅ Configuration serveur générée (server/.env)${NC}"
|
||||||
|
|
||||||
|
# Créer fichier .env client
|
||||||
|
echo "🔑 Génération configuration client..."
|
||||||
|
|
||||||
|
cat > client/.env << EOF
|
||||||
|
# Configuration PTT Live Client
|
||||||
|
# Généré automatiquement par install/macos.sh
|
||||||
|
|
||||||
|
# En développement local, utilise le proxy Vite
|
||||||
|
VITE_API_URL=/api
|
||||||
|
|
||||||
|
# Pour accès réseau (autres devices), décommentez et mettez l'IP du serveur :
|
||||||
|
# VITE_API_URL=http://${NETWORK_IP}:3000
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo -e "${GREEN}✅ Configuration client générée (client/.env)${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Message final
|
# Message final
|
||||||
echo "=================================="
|
echo "=================================="
|
||||||
echo -e "${GREEN}✅ Installation terminée !${NC}"
|
echo -e "${GREEN}✅ Installation terminée !${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
echo "📝 Prochaines étapes :"
|
echo "🚀 Démarrage rapide :"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 1. Démarrer le serveur :"
|
echo " # Mode développement (recommandé)"
|
||||||
echo " cd server && npm run dev"
|
echo " ./start.sh --dev"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 2. Démarrer le client (nouveau terminal) :"
|
echo " # Mode production"
|
||||||
echo " cd client && npm run dev"
|
echo " ./start.sh"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 3. Ouvrir https://localhost:5173 dans votre navigateur"
|
echo "📝 OU manuellement (deux terminaux) :"
|
||||||
echo ""
|
echo ""
|
||||||
echo "📖 Documentation : README.md"
|
echo " Terminal 1 : cd server && npm run dev"
|
||||||
|
echo " Terminal 2 : cd client && npm run dev"
|
||||||
|
echo ""
|
||||||
|
echo "🌐 Accès après démarrage :"
|
||||||
|
echo " • Développement local : https://localhost:5173"
|
||||||
|
echo " • Depuis smartphone (WiFi) : https://${NETWORK_IP}:5173"
|
||||||
|
echo " • Admin : https://${NETWORK_IP}:5173/admin"
|
||||||
|
echo ""
|
||||||
|
echo "💡 Configuration réseau :"
|
||||||
|
echo " IP serveur détectée : ${NETWORK_IP}"
|
||||||
|
echo " LiveKit URL : AUTO (détection dynamique)"
|
||||||
|
echo ""
|
||||||
|
echo "📖 Documentation :"
|
||||||
|
echo " • README.md - Guide complet"
|
||||||
|
echo " • README-PORTABLE.md - Déploiement portable"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
+18
-12
@@ -1,17 +1,23 @@
|
|||||||
# PTT Live - Configuration environnement serveur
|
# Configuration PTT Live Server
|
||||||
|
# Copiez ce fichier en .env et adaptez selon votre environnement
|
||||||
|
|
||||||
# LiveKit API Keys
|
# Mode LiveKit
|
||||||
# En dev, utilise les valeurs par défaut si non définies
|
USE_LOCAL_LIVEKIT=true # true = LiveKit local, false = LiveKit Cloud
|
||||||
|
|
||||||
|
# LiveKit Configuration
|
||||||
|
# Mode local : AUTO détecte automatiquement l'IP réseau
|
||||||
|
# Mode cloud : URL complète wss://votre-projet.livekit.cloud
|
||||||
|
LIVEKIT_URL=AUTO
|
||||||
|
|
||||||
|
# Clés API LiveKit
|
||||||
|
# Mode local --dev : devkey/secret (par défaut)
|
||||||
|
# Mode cloud : récupérez vos clés sur https://cloud.livekit.io
|
||||||
LIVEKIT_API_KEY=devkey
|
LIVEKIT_API_KEY=devkey
|
||||||
LIVEKIT_API_SECRET=secret
|
LIVEKIT_API_SECRET=secret
|
||||||
|
|
||||||
# URL LiveKit pour les clients
|
# Configuration serveur
|
||||||
# Pour permettre les connexions réseau, utilisez l'IP locale du serveur
|
PORT=3000
|
||||||
# Exemples :
|
NODE_ENV=development
|
||||||
# - Local uniquement : ws://localhost:7880
|
|
||||||
# - Réseau local : ws://192.168.1.100:7880 (remplacer par votre IP)
|
|
||||||
# - Utiliser AUTO pour détecter automatiquement l'IP réseau
|
|
||||||
LIVEKIT_URL=AUTO
|
|
||||||
|
|
||||||
# Mode LiveKit local (démarre livekit-server automatiquement)
|
# Logging (optionnel)
|
||||||
USE_LOCAL_LIVEKIT=true
|
# LOG_LEVEL=debug
|
||||||
|
|||||||
+143
-3
@@ -179,7 +179,7 @@ router.get('/groups', (req, res) => {
|
|||||||
/**
|
/**
|
||||||
* POST /admin/groups
|
* POST /admin/groups
|
||||||
* Crée un nouveau groupe
|
* Crée un nouveau groupe
|
||||||
* Body: { name, audioBitrate?, channels }
|
* Body: { name, audioBitrate? }
|
||||||
* L'ID est généré automatiquement à partir du nom
|
* L'ID est généré automatiquement à partir du nom
|
||||||
*/
|
*/
|
||||||
router.post('/groups', (req, res) => {
|
router.post('/groups', (req, res) => {
|
||||||
@@ -204,7 +204,7 @@ router.post('/groups', (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Créer le nouveau groupe (sans channels)
|
// Créer le nouveau groupe
|
||||||
const newGroup = {
|
const newGroup = {
|
||||||
name,
|
name,
|
||||||
...(audioBitrate && { audioBitrate })
|
...(audioBitrate && { audioBitrate })
|
||||||
@@ -482,8 +482,28 @@ router.get('/audio/device', (req, res) => {
|
|||||||
const config = configManager.get();
|
const config = configManager.get();
|
||||||
const audioDevice = config.audio?.device || {};
|
const audioDevice = config.audio?.device || {};
|
||||||
|
|
||||||
|
// Enrichir avec les infos réelles de la carte si configurée
|
||||||
|
const devices = CoreAudioBackend.getDevices();
|
||||||
|
let deviceInfo = { ...audioDevice };
|
||||||
|
|
||||||
|
if (audioDevice.inputDeviceId) {
|
||||||
|
const inputDev = devices.find(d => d.id === audioDevice.inputDeviceId);
|
||||||
|
if (inputDev) {
|
||||||
|
deviceInfo.inputChannels = inputDev.maxInputChannels;
|
||||||
|
deviceInfo.inputDeviceName = inputDev.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (audioDevice.outputDeviceId) {
|
||||||
|
const outputDev = devices.find(d => d.id === audioDevice.outputDeviceId);
|
||||||
|
if (outputDev) {
|
||||||
|
deviceInfo.outputChannels = outputDev.maxOutputChannels;
|
||||||
|
deviceInfo.outputDeviceName = outputDev.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
device: audioDevice
|
device: deviceInfo
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur GET /admin/audio/device:', error);
|
console.error('Erreur GET /admin/audio/device:', error);
|
||||||
@@ -644,4 +664,124 @@ router.post('/audio/device', (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /admin/devices/list
|
||||||
|
* Liste tous les devices audio disponibles (auto-détection)
|
||||||
|
* Supporte macOS (CoreAudio), Linux (JACK/PipeWire), Windows (WASAPI)
|
||||||
|
*/
|
||||||
|
router.get('/devices/list', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const devices = {
|
||||||
|
inputs: [],
|
||||||
|
outputs: [],
|
||||||
|
platform: process.platform
|
||||||
|
};
|
||||||
|
|
||||||
|
// Détection selon la plateforme
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
// macOS : utiliser CoreAudio via sox
|
||||||
|
const { exec } = await import('child_process');
|
||||||
|
const { promisify } = await import('util');
|
||||||
|
const execPromise = promisify(exec);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Utiliser sox pour lister les devices audio
|
||||||
|
const { stdout } = await execPromise('sox -V6 2>&1');
|
||||||
|
|
||||||
|
// Parser la sortie sox pour extraire les devices
|
||||||
|
// Format typique : "Input Device [0]: MacBook Pro Microphone"
|
||||||
|
const inputMatches = stdout.matchAll(/Input Device \[(\d+)\]: (.+)/g);
|
||||||
|
const outputMatches = stdout.matchAll(/Output Device \[(\d+)\]: (.+)/g);
|
||||||
|
|
||||||
|
for (const match of inputMatches) {
|
||||||
|
devices.inputs.push({
|
||||||
|
id: parseInt(match[1], 10),
|
||||||
|
name: match[2].trim()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const match of outputMatches) {
|
||||||
|
devices.outputs.push({
|
||||||
|
id: parseInt(match[1], 10),
|
||||||
|
name: match[2].trim()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (soxError) {
|
||||||
|
console.warn('⚠️ sox non disponible, devices limités:', soxError.message);
|
||||||
|
|
||||||
|
// Fallback : devices par défaut macOS
|
||||||
|
devices.inputs.push({ id: 0, name: 'Default Input (Built-in Microphone)', isDefault: true });
|
||||||
|
devices.outputs.push({ id: 0, name: 'Default Output (Built-in Speakers)', isDefault: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (process.platform === 'linux') {
|
||||||
|
// Linux : JACK ou PipeWire
|
||||||
|
const { exec } = await import('child_process');
|
||||||
|
const { promisify } = await import('util');
|
||||||
|
const execPromise = promisify(exec);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Essayer JACK d'abord
|
||||||
|
const { stdout: jackPorts } = await execPromise('jack_lsp 2>/dev/null || echo ""');
|
||||||
|
|
||||||
|
if (jackPorts.trim()) {
|
||||||
|
// Parser les ports JACK
|
||||||
|
const ports = jackPorts.split('\n').filter(Boolean);
|
||||||
|
|
||||||
|
ports.forEach(port => {
|
||||||
|
if (port.includes('capture')) {
|
||||||
|
devices.inputs.push({ id: port, name: port });
|
||||||
|
} else if (port.includes('playback')) {
|
||||||
|
devices.outputs.push({ id: port, name: port });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Fallback : PipeWire via pactl
|
||||||
|
const { stdout: paDevices } = await execPromise('pactl list short sources 2>/dev/null || echo ""');
|
||||||
|
const { stdout: paSinks } = await execPromise('pactl list short sinks 2>/dev/null || echo ""');
|
||||||
|
|
||||||
|
if (paDevices.trim()) {
|
||||||
|
paDevices.split('\n').filter(Boolean).forEach((line, idx) => {
|
||||||
|
const name = line.split('\t')[1] || `Device ${idx}`;
|
||||||
|
devices.inputs.push({ id: idx, name });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paSinks.trim()) {
|
||||||
|
paSinks.split('\n').filter(Boolean).forEach((line, idx) => {
|
||||||
|
const name = line.split('\t')[1] || `Device ${idx}`;
|
||||||
|
devices.outputs.push({ id: idx, name });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (linuxError) {
|
||||||
|
console.warn('⚠️ Détection devices Linux échouée:', linuxError.message);
|
||||||
|
devices.inputs.push({ id: 0, name: 'Default Input', isDefault: true });
|
||||||
|
devices.outputs.push({ id: 0, name: 'Default Output', isDefault: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (process.platform === 'win32') {
|
||||||
|
// Windows : WASAPI (Phase 3)
|
||||||
|
// TODO: implémenter détection WASAPI
|
||||||
|
devices.inputs.push({ id: 0, name: 'Default Input (Windows)', isDefault: true });
|
||||||
|
devices.outputs.push({ id: 0, name: 'Default Output (Windows)', isDefault: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
addLog('info', 'Audio devices listed', {
|
||||||
|
inputsCount: devices.inputs.length,
|
||||||
|
outputsCount: devices.outputs.length
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(devices);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur GET /admin/devices/list:', error);
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Failed to list audio devices',
|
||||||
|
message: error.message,
|
||||||
|
platform: process.platform
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
+120
-22
@@ -65,6 +65,13 @@ export class AudioBridge extends EventEmitter {
|
|||||||
this.inputChannelBuffers = new Map(); // Map<channelId, Float32Array>
|
this.inputChannelBuffers = new Map(); // Map<channelId, Float32Array>
|
||||||
this.groupBuffersFromLiveKit = new Map(); // Map<groupName, Float32Array>
|
this.groupBuffersFromLiveKit = new Map(); // Map<groupName, Float32Array>
|
||||||
|
|
||||||
|
// Pool de buffers pré-alloués pour éviter allocations répétées
|
||||||
|
this.bufferPool = {
|
||||||
|
float32: [], // Pool de Float32Array réutilisables
|
||||||
|
pcm: [] // Pool de Buffer PCM réutilisables
|
||||||
|
};
|
||||||
|
this.maxPoolSize = 50; // Limite du pool (adapté pour 30+ clients)
|
||||||
|
|
||||||
// Statistiques
|
// Statistiques
|
||||||
this.stats = {
|
this.stats = {
|
||||||
startTime: null,
|
startTime: null,
|
||||||
@@ -189,13 +196,31 @@ export class AudioBridge extends EventEmitter {
|
|||||||
throw new Error(`Plateforme non supportée : ${os}`);
|
throw new Error(`Plateforme non supportée : ${os}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Résoudre les device IDs vers les noms pour CoreAudio/sox
|
||||||
|
let inputDeviceName = null;
|
||||||
|
let outputDeviceName = null;
|
||||||
|
|
||||||
|
if (this.options.inputDeviceId) {
|
||||||
|
const inputDevice = BackendClass.getDevices().find(d => d.id === this.options.inputDeviceId);
|
||||||
|
inputDeviceName = inputDevice ? inputDevice.name : this.options.inputDeviceId;
|
||||||
|
console.log(`📥 Input device: "${inputDeviceName}" (ID: ${this.options.inputDeviceId})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.outputDeviceId) {
|
||||||
|
const outputDevice = BackendClass.getDevices().find(d => d.id === this.options.outputDeviceId);
|
||||||
|
outputDeviceName = outputDevice ? outputDevice.name : this.options.outputDeviceId;
|
||||||
|
console.log(`📤 Output device: "${outputDeviceName}" (ID: ${this.options.outputDeviceId})`);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialisation du backend sélectionné
|
// Initialisation du backend sélectionné
|
||||||
this.audioBackend = new BackendClass({
|
this.audioBackend = new BackendClass({
|
||||||
sampleRate: this.options.sampleRate,
|
sampleRate: this.options.sampleRate,
|
||||||
channels: this.options.channels,
|
channels: this.options.channels,
|
||||||
framesPerBuffer: this.options.frameSize,
|
framesPerBuffer: this.options.frameSize,
|
||||||
inputDeviceId: this.options.inputDeviceId,
|
inputDeviceId: this.options.inputDeviceId,
|
||||||
|
inputDeviceName: inputDeviceName,
|
||||||
outputDeviceId: this.options.outputDeviceId,
|
outputDeviceId: this.options.outputDeviceId,
|
||||||
|
outputDeviceName: outputDeviceName,
|
||||||
// Options spécifiques PipeWire
|
// Options spécifiques PipeWire
|
||||||
latency: this.options.latency || 20
|
latency: this.options.latency || 20
|
||||||
});
|
});
|
||||||
@@ -323,7 +348,14 @@ export class AudioBridge extends EventEmitter {
|
|||||||
|
|
||||||
this.liveKitClient.on('audioTrackSubscribed', ({ track, participant }) => {
|
this.liveKitClient.on('audioTrackSubscribed', ({ track, participant }) => {
|
||||||
console.log(`🎵 Nouveau track audio : ${participant.identity}`);
|
console.log(`🎵 Nouveau track audio : ${participant.identity}`);
|
||||||
this._handleRemoteAudioTrack(track);
|
});
|
||||||
|
|
||||||
|
// Réception audio depuis les clients LiveKit
|
||||||
|
this.liveKitClient.on('audioData', ({ participantName, pcmData, sampleRate, channels }) => {
|
||||||
|
// Pour l'instant, on route vers le groupe principal
|
||||||
|
// TODO: Mapper les participants aux groupes selon la configuration
|
||||||
|
const groupName = 'Equipe'; // Groupe par défaut
|
||||||
|
this.emit('groupAudioIn', { groupName, pcmBuffer: pcmData });
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.liveKitClient.connect();
|
await this.liveKitClient.connect();
|
||||||
@@ -352,6 +384,10 @@ export class AudioBridge extends EventEmitter {
|
|||||||
this.inputChannelBuffers
|
this.inputChannelBuffers
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.stats.framesCapture % 100 === 0) {
|
||||||
|
console.log(`[AudioBridge] Frame ${this.stats.framesCapture}: ${this.inputChannelBuffers.size} inputs → ${groupBuffers.size} groupes`);
|
||||||
|
}
|
||||||
|
|
||||||
// ÉTAPE 2 : Pour chaque groupe, envoyer vers LiveKit
|
// ÉTAPE 2 : Pour chaque groupe, envoyer vers LiveKit
|
||||||
groupBuffers.forEach((groupBuffer, groupName) => {
|
groupBuffers.forEach((groupBuffer, groupName) => {
|
||||||
// Convertir Float32Array → PCM Buffer
|
// Convertir Float32Array → PCM Buffer
|
||||||
@@ -361,18 +397,47 @@ export class AudioBridge extends EventEmitter {
|
|||||||
const opusData = this.opusEncoder.encode(pcmBuffer);
|
const opusData = this.opusEncoder.encode(pcmBuffer);
|
||||||
|
|
||||||
if (opusData) {
|
if (opusData) {
|
||||||
this.stats.framesCapture++;
|
|
||||||
this.stats.bytesEncoded += opusData.length;
|
this.stats.bytesEncoded += opusData.length;
|
||||||
|
|
||||||
// TODO: Envoyer opusData à LiveKit pour ce groupe spécifique
|
// Envoi vers LiveKit via sendAudioData (prend du PCM, pas de l'Opus)
|
||||||
// this.liveKitClient.sendAudioToGroup(groupName, opusData);
|
// Note: LiveKit gère lui-même l'encodage Opus en interne
|
||||||
|
if (this.liveKitClient && this.liveKitClient.isConnected) {
|
||||||
|
this.liveKitClient.sendAudioData(pcmBuffer);
|
||||||
|
if (this.stats.framesCapture % 100 === 0) {
|
||||||
|
console.log(`[AudioBridge] → LiveKit groupe "${groupName}": ${pcmBuffer.length} bytes`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.stats.framesCapture % 100 === 0) {
|
||||||
|
console.log(`[AudioBridge] ⚠️ LiveKit non connecté, audio non envoyé`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pour Phase 3, on émet un événement que le système d'intégration LiveKit écoutera
|
// Émettre aussi pour monitoring/debug
|
||||||
this.emit('groupAudioOut', { groupName, opusData, pcmBuffer });
|
this.emit('groupAudioOut', { groupName, opusData, pcmBuffer });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ÉTAPE 3 : Loopback local - Groupes → Outputs physiques (sans passer par LiveKit)
|
||||||
|
const outputBuffers = this.groupAudioRouter.processGroupsToOutputs(groupBuffers);
|
||||||
|
|
||||||
|
if (this.stats.framesCapture % 100 === 0) {
|
||||||
|
console.log(`[AudioBridge] Loopback local: ${groupBuffers.size} groupes → ${outputBuffers.size} outputs`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ÉTAPE 4 : Envoyer chaque output à la carte son
|
||||||
|
outputBuffers.forEach((outputBuffer, channelId) => {
|
||||||
|
const pcmBuffer = this._float32ToBuffer(outputBuffer);
|
||||||
|
|
||||||
|
// Envoyer à la carte son
|
||||||
|
this.audioBackend.queueAudio(pcmBuffer);
|
||||||
|
|
||||||
|
if (this.stats.framesCapture % 100 === 0) {
|
||||||
|
console.log(`[AudioBridge] → Output ${channelId}: ${pcmBuffer.length} bytes`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.stats.framesCapture++;
|
this.stats.framesCapture++;
|
||||||
|
this.stats.framesPlayback++;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur routing capture:', error);
|
console.error('Erreur routing capture:', error);
|
||||||
this.stats.errors.capture++;
|
this.stats.errors.capture++;
|
||||||
@@ -418,26 +483,55 @@ export class AudioBridge extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gère l'arrivée d'un track audio distant
|
* Acquiert un Float32Array depuis le pool ou en crée un nouveau
|
||||||
* @param {RemoteAudioTrack} track - Track LiveKit
|
* @param {number} size - Taille du buffer
|
||||||
|
* @returns {Float32Array}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_handleRemoteAudioTrack(track) {
|
_acquireFloat32Buffer(size) {
|
||||||
// Récupération du MediaStream du track
|
const pooled = this.bufferPool.float32.find(b => b.length === size);
|
||||||
const mediaStream = new MediaStream([track.mediaStreamTrack]);
|
if (pooled) {
|
||||||
|
this.bufferPool.float32.splice(this.bufferPool.float32.indexOf(pooled), 1);
|
||||||
|
return pooled;
|
||||||
|
}
|
||||||
|
return new Float32Array(size);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: Pour décoder Opus côté serveur, on aurait besoin d'accéder
|
/**
|
||||||
// aux données brutes via DataChannel ou API bas niveau
|
* Retourne un Float32Array au pool pour réutilisation
|
||||||
// LiveKit gère nativement le décodage WebRTC → PCM dans le navigateur
|
* @param {Float32Array} buffer
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_releaseFloat32Buffer(buffer) {
|
||||||
|
if (this.bufferPool.float32.length < this.maxPoolSize) {
|
||||||
|
this.bufferPool.float32.push(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pour un vrai bridge serveur, il faudrait :
|
/**
|
||||||
// 1. Recevoir les paquets Opus via DataChannel ou API custom
|
* Acquiert un Buffer PCM depuis le pool ou en crée un nouveau
|
||||||
// 2. Décoder avec opusDecoder
|
* @param {number} size - Taille du buffer
|
||||||
// 3. Envoyer au jitterBuffer
|
* @returns {Buffer}
|
||||||
// 4. Lire depuis jitterBuffer vers CoreAudio
|
* @private
|
||||||
|
*/
|
||||||
|
_acquirePcmBuffer(size) {
|
||||||
|
const pooled = this.bufferPool.pcm.find(b => b.length === size);
|
||||||
|
if (pooled) {
|
||||||
|
this.bufferPool.pcm.splice(this.bufferPool.pcm.indexOf(pooled), 1);
|
||||||
|
return pooled;
|
||||||
|
}
|
||||||
|
return Buffer.alloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Implémenter réception bas niveau Opus depuis LiveKit
|
/**
|
||||||
console.warn('Réception track distant : implémentation complète en cours');
|
* Retourne un Buffer PCM au pool pour réutilisation
|
||||||
|
* @param {Buffer} buffer
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_releasePcmBuffer(buffer) {
|
||||||
|
if (this.bufferPool.pcm.length < this.maxPoolSize) {
|
||||||
|
this.bufferPool.pcm.push(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -448,7 +542,7 @@ export class AudioBridge extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
_bufferToFloat32(buffer) {
|
_bufferToFloat32(buffer) {
|
||||||
const samples = buffer.length / 2; // 2 bytes per sample (16-bit)
|
const samples = buffer.length / 2; // 2 bytes per sample (16-bit)
|
||||||
const float32 = new Float32Array(samples);
|
const float32 = this._acquireFloat32Buffer(samples);
|
||||||
|
|
||||||
for (let i = 0; i < samples; i++) {
|
for (let i = 0; i < samples; i++) {
|
||||||
// Lire 16-bit signed little-endian
|
// Lire 16-bit signed little-endian
|
||||||
@@ -467,7 +561,7 @@ export class AudioBridge extends EventEmitter {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_float32ToBuffer(float32) {
|
_float32ToBuffer(float32) {
|
||||||
const buffer = Buffer.alloc(float32.length * 2); // 2 bytes per sample
|
const buffer = this._acquirePcmBuffer(float32.length * 2); // 2 bytes per sample
|
||||||
|
|
||||||
for (let i = 0; i < float32.length; i++) {
|
for (let i = 0; i < float32.length; i++) {
|
||||||
// Clamping [-1.0, 1.0]
|
// Clamping [-1.0, 1.0]
|
||||||
@@ -525,6 +619,10 @@ export class AudioBridge extends EventEmitter {
|
|||||||
this.inputChannelBuffers.clear();
|
this.inputChannelBuffers.clear();
|
||||||
this.groupBuffersFromLiveKit.clear();
|
this.groupBuffersFromLiveKit.clear();
|
||||||
|
|
||||||
|
// Nettoyer le pool de buffers
|
||||||
|
this.bufferPool.float32 = [];
|
||||||
|
this.bufferPool.pcm = [];
|
||||||
|
|
||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
|
|
||||||
console.log('✓ AudioBridge arrêté');
|
console.log('✓ AudioBridge arrêté');
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ class AudioBridgeManager extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Démarre le bridge audio avec la configuration actuelle
|
* Démarre le bridge audio avec la configuration actuelle
|
||||||
|
* @param {Object} options - Options de démarrage
|
||||||
|
* @param {string} options.liveKitUrl - URL LiveKit résolue (déjà avec IP si AUTO)
|
||||||
*/
|
*/
|
||||||
async start() {
|
async start(options = {}) {
|
||||||
if (this.isRunning) {
|
if (this.isRunning) {
|
||||||
console.warn('⚠️ AudioBridge déjà démarré');
|
console.warn('⚠️ AudioBridge déjà démarré');
|
||||||
return;
|
return;
|
||||||
@@ -79,18 +81,28 @@ class AudioBridgeManager extends EventEmitter {
|
|||||||
if (audioConfig.defaultBitrate) audioConfig.defaultBitrate = parseInt(audioConfig.defaultBitrate, 10);
|
if (audioConfig.defaultBitrate) audioConfig.defaultBitrate = parseInt(audioConfig.defaultBitrate, 10);
|
||||||
if (audioConfig.customOpusBitrate) audioConfig.customOpusBitrate = parseInt(audioConfig.customOpusBitrate, 10);
|
if (audioConfig.customOpusBitrate) audioConfig.customOpusBitrate = parseInt(audioConfig.customOpusBitrate, 10);
|
||||||
|
|
||||||
|
// Extraire les device IDs depuis le sous-objet device
|
||||||
|
const inputDeviceId = audioConfig.device?.inputDeviceId || null;
|
||||||
|
const outputDeviceId = audioConfig.device?.outputDeviceId || null;
|
||||||
|
|
||||||
|
// Utiliser l'URL résolue passée en option, sinon fallback config
|
||||||
|
const liveKitUrl = options.liveKitUrl || config.server?.livekit?.url || 'ws://localhost:7880';
|
||||||
|
|
||||||
// Créer l'instance avec la config
|
// Créer l'instance avec la config
|
||||||
this.bridge = new AudioBridge({
|
this.bridge = new AudioBridge({
|
||||||
...audioConfig,
|
...audioConfig,
|
||||||
// Options LiveKit
|
// Options LiveKit
|
||||||
liveKitUrl: config.server?.livekit?.url || 'ws://localhost:7880',
|
liveKitUrl,
|
||||||
liveKitToken,
|
liveKitToken,
|
||||||
roomName: 'main',
|
roomName: 'main',
|
||||||
// Options de routing
|
// Options de routing
|
||||||
routing: config.audio?.routing || {},
|
routing: config.audio?.routing || {},
|
||||||
groups: config.groups || [],
|
groups: config.groups || [],
|
||||||
maxInputChannels: 32,
|
maxInputChannels: 32,
|
||||||
maxOutputChannels: 32
|
maxOutputChannels: 32,
|
||||||
|
// Device IDs extraits
|
||||||
|
inputDeviceId,
|
||||||
|
outputDeviceId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Démarrer le bridge
|
// Démarrer le bridge
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
import { getLogger } from '../utils/Logger.js';
|
||||||
|
|
||||||
|
const logger = getLogger('Routing');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Représente une route audio avec gain
|
* Représente une route audio avec gain
|
||||||
@@ -76,7 +79,10 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
* Configure le routing depuis la config YAML
|
* Configure le routing depuis la config YAML
|
||||||
*/
|
*/
|
||||||
configure(routingConfig) {
|
configure(routingConfig) {
|
||||||
console.log('Configuration du routing audio...');
|
logger.info('Configuration du routing audio...');
|
||||||
|
logger.debug(' Groupes disponibles:', this.config.groups.map(g => `${g.name || g} (id: ${g.id || g})`).join(', '));
|
||||||
|
logger.debug(' inputToGroup:', JSON.stringify(routingConfig.inputToGroup || {}));
|
||||||
|
logger.debug(' groupToOutput:', JSON.stringify(routingConfig.groupToOutput || {}));
|
||||||
|
|
||||||
// Réinitialise les routes
|
// Réinitialise les routes
|
||||||
this.inputToGroupRoutes.clear();
|
this.inputToGroupRoutes.clear();
|
||||||
@@ -104,7 +110,7 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._updateStatsActiveRoutes();
|
this._updateStatsActiveRoutes();
|
||||||
console.log(`Routing configuré : ${this.stats.routesActive} routes actives`);
|
logger.success(`Routing configuré : ${this.stats.routesActive} routes actives`);
|
||||||
this.emit('configured', this.stats);
|
this.emit('configured', this.stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +134,7 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
const route = new AudioRoute(inputChannel, groupName, gainDb);
|
const route = new AudioRoute(inputChannel, groupName, gainDb);
|
||||||
this.inputToGroupRoutes.get(key).push(route);
|
this.inputToGroupRoutes.get(key).push(route);
|
||||||
|
|
||||||
console.log(`Route ajoutée : Input ${inputChannel} -> Group "${groupName}" (${gainDb}dB)`);
|
logger.info(`Input ${inputChannel} → Group "${groupName}" (${gainDb}dB)`);
|
||||||
this._updateStatsActiveRoutes();
|
this._updateStatsActiveRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +151,7 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
const route = new AudioRoute(groupName, outputChannel, gainDb);
|
const route = new AudioRoute(groupName, outputChannel, gainDb);
|
||||||
this.groupToOutputRoutes.get(key).push(route);
|
this.groupToOutputRoutes.get(key).push(route);
|
||||||
|
|
||||||
console.log(`Route ajoutée : Group "${groupName}" -> Output ${outputChannel} (${gainDb}dB)`);
|
logger.info(`Group "${groupName}" → Output ${outputChannel} (${gainDb}dB)`);
|
||||||
this._updateStatsActiveRoutes();
|
this._updateStatsActiveRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +211,9 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
// Réinitialise les buffers de groupe
|
// Réinitialise les buffers de groupe
|
||||||
this.groupBuffers.clear();
|
this.groupBuffers.clear();
|
||||||
this.config.groups.forEach(group => {
|
this.config.groups.forEach(group => {
|
||||||
this.groupBuffers.set(group.name, new Float32Array(this.config.frameSize));
|
// Utiliser l'ID (slugifié) plutôt que le nom pour correspondre au routing
|
||||||
|
const groupId = group.id || group.name || group;
|
||||||
|
this.groupBuffers.set(groupId, new Float32Array(this.config.frameSize));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pour chaque canal d'entrée
|
// Pour chaque canal d'entrée
|
||||||
@@ -221,7 +229,10 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
// Applique chaque route (mixage additif vers les groupes)
|
// Applique chaque route (mixage additif vers les groupes)
|
||||||
routes.forEach(route => {
|
routes.forEach(route => {
|
||||||
const groupBuffer = this.groupBuffers.get(route.destination);
|
const groupBuffer = this.groupBuffers.get(route.destination);
|
||||||
if (!groupBuffer) return;
|
if (!groupBuffer) {
|
||||||
|
logger.warn(`Buffer groupe "${route.destination}" introuvable pour routing depuis Input ${channelId}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Mixage avec gain
|
// Mixage avec gain
|
||||||
for (let i = 0; i < pcmData.length && i < groupBuffer.length; i++) {
|
for (let i = 0; i < pcmData.length && i < groupBuffer.length; i++) {
|
||||||
@@ -235,6 +246,9 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
for (let i = 0; i < buffer.length; i++) {
|
for (let i = 0; i < buffer.length; i++) {
|
||||||
if (Math.abs(buffer[i]) > 1.0) {
|
if (Math.abs(buffer[i]) > 1.0) {
|
||||||
this.stats.clippingEvents++;
|
this.stats.clippingEvents++;
|
||||||
|
if (this.stats.clippingEvents % 1000 === 1) {
|
||||||
|
logger.warn(`Clipping détecté sur groupe "${groupName}" (${this.stats.clippingEvents} événements)`);
|
||||||
|
}
|
||||||
buffer[i] = Math.sign(buffer[i]) * 1.0; // Hard clipping
|
buffer[i] = Math.sign(buffer[i]) * 1.0; // Hard clipping
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,7 +390,7 @@ export class GroupAudioRouter extends EventEmitter {
|
|||||||
this.groupBuffers.clear();
|
this.groupBuffers.clear();
|
||||||
this.outputBuffers.clear();
|
this.outputBuffers.clear();
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
console.log('GroupAudioRouter détruit');
|
logger.info('GroupAudioRouter détruit');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,35 +86,21 @@ export class LiveKitClient extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
async _createAudioSource() {
|
async _createAudioSource() {
|
||||||
try {
|
try {
|
||||||
// Debug: afficher les valeurs avant conversion
|
// Conversion explicite en int32 pour l'API LiveKit
|
||||||
const sampleRate = parseInt(this.options.sampleRate, 10);
|
const sampleRate = parseInt(this.options.sampleRate, 10);
|
||||||
const channels = parseInt(this.options.channels, 10);
|
const channels = parseInt(this.options.channels, 10);
|
||||||
|
|
||||||
console.log('🔍 DEBUG AudioSource:', {
|
// Création de l'AudioSource
|
||||||
sampleRateOriginal: this.options.sampleRate,
|
|
||||||
sampleRateType: typeof this.options.sampleRate,
|
|
||||||
sampleRateConverted: sampleRate,
|
|
||||||
sampleRateConvertedType: typeof sampleRate,
|
|
||||||
channelsOriginal: this.options.channels,
|
|
||||||
channelsType: typeof this.options.channels,
|
|
||||||
channelsConverted: channels,
|
|
||||||
channelsConvertedType: typeof channels
|
|
||||||
});
|
|
||||||
|
|
||||||
// Création de l'AudioSource (conversion en int32 explicite)
|
|
||||||
this.audioSource = new AudioSource(sampleRate, channels);
|
this.audioSource = new AudioSource(sampleRate, channels);
|
||||||
console.log('✓ AudioSource créée:', this.audioSource);
|
|
||||||
|
|
||||||
// Création du LocalAudioTrack depuis l'AudioSource
|
// Création du LocalAudioTrack depuis l'AudioSource
|
||||||
const localTrack = LocalAudioTrack.createAudioTrack('bridge-audio', this.audioSource);
|
const localTrack = LocalAudioTrack.createAudioTrack('bridge-audio', this.audioSource);
|
||||||
console.log('✓ LocalAudioTrack créé:', localTrack);
|
|
||||||
|
|
||||||
// Publication du track
|
// Publication du track
|
||||||
const options = {
|
const options = {
|
||||||
source: TrackSource.SOURCE_MICROPHONE // Simule un microphone pour les clients
|
source: TrackSource.SOURCE_MICROPHONE // Simule un microphone pour les clients
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('🔍 DEBUG publishTrack options:', options);
|
|
||||||
this.localAudioTrack = await this.room.localParticipant.publishTrack(
|
this.localAudioTrack = await this.room.localParticipant.publishTrack(
|
||||||
localTrack,
|
localTrack,
|
||||||
options
|
options
|
||||||
@@ -237,6 +223,11 @@ export class LiveKitClient extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.isConnected || !this.localAudioTrack) {
|
||||||
|
// Silently drop frames si pas encore connecté
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Création d'un AudioFrame (conversion en int32 explicite)
|
// Création d'un AudioFrame (conversion en int32 explicite)
|
||||||
const samplesPerChannel = Math.floor(pcmData.length / 2 / this.options.channels);
|
const samplesPerChannel = Math.floor(pcmData.length / 2 / this.options.channels);
|
||||||
@@ -252,9 +243,12 @@ export class LiveKitClient extends EventEmitter {
|
|||||||
await this.audioSource.captureFrame(frame);
|
await this.audioSource.captureFrame(frame);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// Ne logger que les erreurs non-InvalidState pour éviter le spam
|
||||||
|
if (!error.message.includes('InvalidState')) {
|
||||||
console.error('Erreur envoi audio:', error);
|
console.error('Erreur envoi audio:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Récupère tous les tracks audio distants actifs
|
* Récupère tous les tracks audio distants actifs
|
||||||
|
|||||||
@@ -1,237 +0,0 @@
|
|||||||
/**
|
|
||||||
* LiveKitServerBridge.js
|
|
||||||
* Pont entre AudioBridge (cartes son) et LiveKit (clients WebRTC)
|
|
||||||
*
|
|
||||||
* Agit comme un participant virtuel qui :
|
|
||||||
* - Publie l'audio des cartes son vers les clients WebRTC
|
|
||||||
* - Reçoit l'audio des clients et le renvoie vers les cartes son
|
|
||||||
*
|
|
||||||
* Architecture :
|
|
||||||
* [Carte Son] → AudioBridge → LiveKitServerBridge → LiveKit SFU → [Clients WebRTC]
|
|
||||||
* ↑
|
|
||||||
* Gère le routing par groupe
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { RoomServiceClient, AccessToken, TrackSource } from 'livekit-server-sdk';
|
|
||||||
import { EventEmitter } from 'events';
|
|
||||||
|
|
||||||
export class LiveKitServerBridge extends EventEmitter {
|
|
||||||
constructor(audioBridge, options = {}) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.audioBridge = audioBridge;
|
|
||||||
|
|
||||||
this.options = {
|
|
||||||
url: options.url || 'ws://localhost:7880',
|
|
||||||
apiKey: options.apiKey || process.env.LIVEKIT_API_KEY,
|
|
||||||
apiSecret: options.apiSecret || process.env.LIVEKIT_API_SECRET,
|
|
||||||
roomName: options.roomName || 'main',
|
|
||||||
participantName: options.participantName || 'AudioBridge',
|
|
||||||
...options
|
|
||||||
};
|
|
||||||
|
|
||||||
this.roomServiceClient = null;
|
|
||||||
this.activeGroups = new Map(); // Map<groupName, { participants, audioData }>
|
|
||||||
this.isConnected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise la connexion au serveur LiveKit
|
|
||||||
*/
|
|
||||||
async connect() {
|
|
||||||
try {
|
|
||||||
// Créer le client pour l'API LiveKit
|
|
||||||
this.roomServiceClient = new RoomServiceClient(
|
|
||||||
this.options.url.replace('ws://', 'http://').replace('wss://', 'https://'),
|
|
||||||
this.options.apiKey,
|
|
||||||
this.options.apiSecret
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log('✓ LiveKitServerBridge : Connexion API établie');
|
|
||||||
|
|
||||||
// Configurer les événements AudioBridge
|
|
||||||
this._setupAudioBridgeListeners();
|
|
||||||
|
|
||||||
this.isConnected = true;
|
|
||||||
this.emit('connected');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Erreur connexion LiveKitServerBridge:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure les listeners pour l'AudioBridge
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_setupAudioBridgeListeners() {
|
|
||||||
// FLUX SORTANT : Carte son → Groupes → LiveKit
|
|
||||||
this.audioBridge.on('groupAudioOut', ({ groupName, opusData, pcmBuffer }) => {
|
|
||||||
this._handleGroupAudioOut(groupName, opusData, pcmBuffer);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('✓ LiveKitServerBridge : Listeners AudioBridge configurés');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gère l'audio sortant d'un groupe vers LiveKit
|
|
||||||
* @param {string} groupName - Nom du groupe
|
|
||||||
* @param {Buffer} opusData - Données Opus encodées
|
|
||||||
* @param {Buffer} pcmBuffer - Données PCM (pour debug)
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
async _handleGroupAudioOut(groupName, opusData, pcmBuffer) {
|
|
||||||
try {
|
|
||||||
// Pour l'instant, on stocke les données pour les envoyer via DataChannel
|
|
||||||
// ou via un participant virtuel par groupe
|
|
||||||
|
|
||||||
// IMPLÉMENTATION PHASE 3+ :
|
|
||||||
// Option A : Utiliser @livekit/rtc-node pour créer un AudioSource par groupe
|
|
||||||
// Option B : Utiliser DataChannel pour envoyer Opus directement
|
|
||||||
// Option C : Utiliser un participant virtuel par groupe (simple mais plus de ressources)
|
|
||||||
|
|
||||||
// Pour Phase actuelle, on émet un événement pour debug/monitoring
|
|
||||||
this.emit('groupAudioProcessed', {
|
|
||||||
groupName,
|
|
||||||
opusSize: opusData.length,
|
|
||||||
pcmSize: pcmBuffer.length
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: Implémenter l'envoi réel vers LiveKit
|
|
||||||
// Voir docs/LIVEKIT_AUDIO_BRIDGE.md pour les 3 approches possibles
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Erreur envoi audio groupe ${groupName}:`, error);
|
|
||||||
this.emit('error', { groupName, error });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Méthode pour simuler la réception d'audio depuis LiveKit
|
|
||||||
* (À connecter avec le vrai système LiveKit via webhook ou polling)
|
|
||||||
*
|
|
||||||
* @param {string} groupName - Nom du groupe
|
|
||||||
* @param {Buffer} pcmBuffer - Audio PCM depuis un client
|
|
||||||
*/
|
|
||||||
injectGroupAudioIn(groupName, pcmBuffer) {
|
|
||||||
// Envoyer vers AudioBridge pour routing vers la carte son
|
|
||||||
this.audioBridge.emit('groupAudioIn', { groupName, pcmBuffer });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Génère un token d'accès pour un client
|
|
||||||
* @param {string} identity - Identité du participant (ex: "user123")
|
|
||||||
* @param {string} groupName - Groupe à rejoindre
|
|
||||||
* @returns {string} JWT token
|
|
||||||
*/
|
|
||||||
async generateClientToken(identity, groupName) {
|
|
||||||
const at = new AccessToken(
|
|
||||||
this.options.apiKey,
|
|
||||||
this.options.apiSecret,
|
|
||||||
{
|
|
||||||
identity,
|
|
||||||
name: identity,
|
|
||||||
ttl: '24h'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
at.addGrant({
|
|
||||||
room: groupName, // Chaque groupe = une room LiveKit
|
|
||||||
roomJoin: true,
|
|
||||||
canPublish: true,
|
|
||||||
canSubscribe: true,
|
|
||||||
canPublishData: true
|
|
||||||
});
|
|
||||||
|
|
||||||
return at.toJwt();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Liste tous les participants actifs dans une room/groupe
|
|
||||||
* @param {string} groupName - Nom du groupe
|
|
||||||
* @returns {Promise<Array>} Liste des participants
|
|
||||||
*/
|
|
||||||
async listParticipants(groupName) {
|
|
||||||
try {
|
|
||||||
const participants = await this.roomServiceClient.listParticipants(groupName);
|
|
||||||
return participants;
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Erreur listing participants ${groupName}:`, error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Vérifie si une room/groupe existe
|
|
||||||
* @param {string} groupName - Nom du groupe
|
|
||||||
* @returns {Promise<boolean>}
|
|
||||||
*/
|
|
||||||
async roomExists(groupName) {
|
|
||||||
try {
|
|
||||||
const rooms = await this.roomServiceClient.listRooms();
|
|
||||||
return rooms.some(room => room.name === groupName);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Erreur vérification room:', error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Crée une room/groupe si elle n'existe pas
|
|
||||||
* @param {string} groupName - Nom du groupe
|
|
||||||
*/
|
|
||||||
async ensureRoomExists(groupName) {
|
|
||||||
const exists = await this.roomExists(groupName);
|
|
||||||
|
|
||||||
if (!exists) {
|
|
||||||
try {
|
|
||||||
await this.roomServiceClient.createRoom({
|
|
||||||
name: groupName,
|
|
||||||
emptyTimeout: 300, // 5 minutes timeout si vide
|
|
||||||
maxParticipants: 50
|
|
||||||
});
|
|
||||||
console.log(`✓ Room créée : ${groupName}`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Erreur création room ${groupName}:`, error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Obtient les statistiques du bridge
|
|
||||||
*/
|
|
||||||
getStats() {
|
|
||||||
return {
|
|
||||||
connected: this.isConnected,
|
|
||||||
activeGroups: this.activeGroups.size,
|
|
||||||
apiUrl: this.options.url,
|
|
||||||
roomName: this.options.roomName
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Déconnexion
|
|
||||||
*/
|
|
||||||
async disconnect() {
|
|
||||||
if (this.audioBridge) {
|
|
||||||
this.audioBridge.removeAllListeners('groupAudioOut');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.activeGroups.clear();
|
|
||||||
this.isConnected = false;
|
|
||||||
|
|
||||||
console.log('✓ LiveKitServerBridge déconnecté');
|
|
||||||
this.emit('disconnected');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Détruit le bridge et libère les ressources
|
|
||||||
*/
|
|
||||||
async destroy() {
|
|
||||||
await this.disconnect();
|
|
||||||
this.removeAllListeners();
|
|
||||||
console.log('✓ LiveKitServerBridge détruit');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default LiveKitServerBridge;
|
|
||||||
@@ -48,7 +48,6 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
const data = JSON.parse(output);
|
const data = JSON.parse(output);
|
||||||
|
|
||||||
const devices = [];
|
const devices = [];
|
||||||
let id = 0;
|
|
||||||
|
|
||||||
// Parse audio devices
|
// Parse audio devices
|
||||||
if (data.SPAudioDataType) {
|
if (data.SPAudioDataType) {
|
||||||
@@ -62,13 +61,16 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
const outputChannels = parseInt(device.coreaudio_device_output) || 0;
|
const outputChannels = parseInt(device.coreaudio_device_output) || 0;
|
||||||
const sampleRate = parseInt(device.coreaudio_device_srate) || 48000;
|
const sampleRate = parseInt(device.coreaudio_device_srate) || 48000;
|
||||||
|
|
||||||
|
// Utiliser le UID CoreAudio comme ID (unique et stable)
|
||||||
|
const deviceUID = device._uniqueID || device.coreaudio_device_uid || name;
|
||||||
|
|
||||||
// Ignorer les devices sans input ni output
|
// Ignorer les devices sans input ni output
|
||||||
if (inputChannels === 0 && outputChannels === 0) {
|
if (inputChannels === 0 && outputChannels === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.push({
|
devices.push({
|
||||||
id: id++,
|
id: deviceUID,
|
||||||
name: name,
|
name: name,
|
||||||
maxInputChannels: inputChannels,
|
maxInputChannels: inputChannels,
|
||||||
maxOutputChannels: outputChannels,
|
maxOutputChannels: outputChannels,
|
||||||
@@ -90,7 +92,7 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
if (devices.length === 0) {
|
if (devices.length === 0) {
|
||||||
devices.push(
|
devices.push(
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 'builtin-mic',
|
||||||
name: 'Built-in Microphone',
|
name: 'Built-in Microphone',
|
||||||
maxInputChannels: 1,
|
maxInputChannels: 1,
|
||||||
maxOutputChannels: 0,
|
maxOutputChannels: 0,
|
||||||
@@ -98,7 +100,7 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
hostAPIName: 'Core Audio'
|
hostAPIName: 'Core Audio'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 'builtin-output',
|
||||||
name: 'Built-in Output',
|
name: 'Built-in Output',
|
||||||
maxInputChannels: 0,
|
maxInputChannels: 0,
|
||||||
maxOutputChannels: 2,
|
maxOutputChannels: 2,
|
||||||
@@ -116,7 +118,7 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
// Fallback : devices par défaut
|
// Fallback : devices par défaut
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: 0,
|
id: 'builtin-mic',
|
||||||
name: 'Built-in Microphone',
|
name: 'Built-in Microphone',
|
||||||
maxInputChannels: 1,
|
maxInputChannels: 1,
|
||||||
maxOutputChannels: 0,
|
maxOutputChannels: 0,
|
||||||
@@ -124,7 +126,7 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
hostAPIName: 'Core Audio'
|
hostAPIName: 'Core Audio'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 'builtin-output',
|
||||||
name: 'Built-in Output',
|
name: 'Built-in Output',
|
||||||
maxInputChannels: 0,
|
maxInputChannels: 0,
|
||||||
maxOutputChannels: 2,
|
maxOutputChannels: 2,
|
||||||
@@ -203,7 +205,7 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
|
|
||||||
// Si device spécifié
|
// Si device spécifié
|
||||||
if (this.options.inputDeviceName) {
|
if (this.options.inputDeviceName) {
|
||||||
args[1] = this.options.inputDeviceName;
|
args[2] = this.options.inputDeviceName; // Index 2 = device name
|
||||||
}
|
}
|
||||||
|
|
||||||
this.captureProcess = spawn('sox', args);
|
this.captureProcess = spawn('sox', args);
|
||||||
@@ -255,8 +257,10 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
async startPlayback() {
|
async startPlayback() {
|
||||||
|
console.log('🔊 Démarrage playback sox...');
|
||||||
|
|
||||||
if (this.isPlaying) {
|
if (this.isPlaying) {
|
||||||
console.warn('Lecture déjà active');
|
console.warn('⚠️ Lecture déjà active');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +268,9 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
// Commande sox pour lecture audio
|
// Commande sox pour lecture audio
|
||||||
// play : lire vers output par défaut
|
// play : lire vers output par défaut
|
||||||
// -t raw : format raw PCM depuis stdin
|
// -t raw : format raw PCM depuis stdin
|
||||||
|
// --buffer : taille du buffer interne sox (en bytes)
|
||||||
const args = [
|
const args = [
|
||||||
|
'--buffer', '8192', // Buffer interne sox
|
||||||
'-t', 'raw',
|
'-t', 'raw',
|
||||||
'-b', '16',
|
'-b', '16',
|
||||||
'-e', 'signed-integer',
|
'-e', 'signed-integer',
|
||||||
@@ -280,7 +286,9 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
args[args.length - 1] = this.options.outputDeviceName;
|
args[args.length - 1] = this.options.outputDeviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.playbackProcess = spawn('sox', args);
|
this.playbackProcess = spawn('sox', args, {
|
||||||
|
stdio: ['pipe', 'ignore', 'pipe'] // stdin=pipe, stdout=ignore, stderr=pipe
|
||||||
|
});
|
||||||
|
|
||||||
// Gérer l'erreur EPIPE sur stdin (si processus se ferme)
|
// Gérer l'erreur EPIPE sur stdin (si processus se ferme)
|
||||||
this.playbackProcess.stdin.on('error', (error) => {
|
this.playbackProcess.stdin.on('error', (error) => {
|
||||||
@@ -305,13 +313,28 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.playbackProcess.on('close', (code) => {
|
this.playbackProcess.on('close', (code) => {
|
||||||
console.log(`Sox playback fermé (code ${code})`);
|
console.log(`⚠️ Sox playback fermé (code ${code}) après ${((Date.now() - this.playbackStartTime) / 1000).toFixed(1)}s`);
|
||||||
this.isPlaying = false;
|
this.isPlaying = false;
|
||||||
|
|
||||||
|
// Tenter de redémarrer si c'était inattendu
|
||||||
|
if (code !== 0) {
|
||||||
|
console.log('🔄 Tentative de redémarrage du playback...');
|
||||||
|
setTimeout(() => this.startPlayback(), 1000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.playbackStartTime = Date.now();
|
||||||
this.isPlaying = true;
|
this.isPlaying = true;
|
||||||
this._startPlaybackLoop();
|
this._startPlaybackLoop();
|
||||||
|
|
||||||
|
// Envoyer immédiatement du silence pour démarrer sox
|
||||||
|
const silenceBuffer = Buffer.alloc(this.options.framesPerBuffer * 2 * this.options.channels);
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
|
if (this.playbackProcess.stdin.writable) {
|
||||||
|
this.playbackProcess.stdin.write(silenceBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`✓ Lecture audio démarrée : ${this.options.sampleRate}Hz, ${this.options.channels}ch`);
|
console.log(`✓ Lecture audio démarrée : ${this.options.sampleRate}Hz, ${this.options.channels}ch`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur démarrage lecture:', error);
|
console.error('Erreur démarrage lecture:', error);
|
||||||
@@ -323,6 +346,11 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
* Arrête la lecture audio
|
* Arrête la lecture audio
|
||||||
*/
|
*/
|
||||||
stopPlayback() {
|
stopPlayback() {
|
||||||
|
if (this.playbackInterval) {
|
||||||
|
clearInterval(this.playbackInterval);
|
||||||
|
this.playbackInterval = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.playbackProcess && this.isPlaying) {
|
if (this.playbackProcess && this.isPlaying) {
|
||||||
this.playbackProcess.kill('SIGTERM');
|
this.playbackProcess.kill('SIGTERM');
|
||||||
this.playbackProcess = null;
|
this.playbackProcess = null;
|
||||||
@@ -338,10 +366,16 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
queueAudio(audioData) {
|
queueAudio(audioData) {
|
||||||
if (!this.isPlaying) {
|
if (!this.isPlaying) {
|
||||||
console.warn('Tentative ajout audio alors que lecture inactive');
|
// Ne logger qu'une fois pour éviter le spam
|
||||||
|
if (!this.playbackInactiveWarned) {
|
||||||
|
console.warn('⚠️ Tentative ajout audio alors que lecture inactive (message unique)');
|
||||||
|
this.playbackInactiveWarned = true;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.playbackInactiveWarned = false;
|
||||||
|
|
||||||
// Limite la taille du buffer pour éviter la latence excessive
|
// Limite la taille du buffer pour éviter la latence excessive
|
||||||
if (this.playbackBuffer.length < this.maxBufferSize) {
|
if (this.playbackBuffer.length < this.maxBufferSize) {
|
||||||
this.playbackBuffer.push(audioData);
|
this.playbackBuffer.push(audioData);
|
||||||
@@ -356,42 +390,48 @@ export class CoreAudioBackend extends EventEmitter {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_startPlaybackLoop() {
|
_startPlaybackLoop() {
|
||||||
const playNextChunk = () => {
|
// Calculer l'intervalle en ms (ex: 960 frames à 48kHz = 20ms)
|
||||||
|
const intervalMs = (this.options.framesPerBuffer / this.options.sampleRate) * 1000;
|
||||||
|
|
||||||
|
console.log(`🔁 Boucle playback démarrée (intervalle: ${intervalMs}ms)`);
|
||||||
|
|
||||||
|
// Utiliser setInterval pour garantir un flux continu
|
||||||
|
this.playbackInterval = setInterval(() => {
|
||||||
if (!this.isPlaying || !this.playbackProcess || !this.playbackProcess.stdin) {
|
if (!this.isPlaying || !this.playbackProcess || !this.playbackProcess.stdin) {
|
||||||
|
if (this.playbackInterval) {
|
||||||
|
clearInterval(this.playbackInterval);
|
||||||
|
this.playbackInterval = null;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let chunk;
|
||||||
if (this.playbackBuffer.length > 0) {
|
if (this.playbackBuffer.length > 0) {
|
||||||
const chunk = this.playbackBuffer.shift();
|
chunk = this.playbackBuffer.shift();
|
||||||
|
} else {
|
||||||
|
// Buffer vide : underrun (envoyer du silence)
|
||||||
|
chunk = Buffer.alloc(this.options.framesPerBuffer * 2 * this.options.channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toujours écrire quelque chose pour garder sox actif
|
||||||
try {
|
try {
|
||||||
if (this.playbackProcess.stdin.writable) {
|
if (this.playbackProcess.stdin.writable) {
|
||||||
this.playbackProcess.stdin.write(chunk);
|
this.playbackProcess.stdin.write(chunk);
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Erreur écriture stdin sox:', error);
|
|
||||||
this.isPlaying = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Buffer vide : underrun (silence)
|
console.warn('⚠️ Sox stdin non writable, arrêt boucle');
|
||||||
const silenceBuffer = Buffer.alloc(this.options.framesPerBuffer * 2 * this.options.channels);
|
this.isPlaying = false;
|
||||||
try {
|
clearInterval(this.playbackInterval);
|
||||||
if (this.playbackProcess.stdin.writable) {
|
this.playbackInterval = null;
|
||||||
this.playbackProcess.stdin.write(silenceBuffer);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore si process fermé
|
if (error.code !== 'EPIPE') {
|
||||||
|
console.error('Erreur écriture stdin sox:', error);
|
||||||
|
}
|
||||||
this.isPlaying = false;
|
this.isPlaying = false;
|
||||||
return;
|
clearInterval(this.playbackInterval);
|
||||||
|
this.playbackInterval = null;
|
||||||
}
|
}
|
||||||
this.emit('bufferUnderrun');
|
}, intervalMs);
|
||||||
}
|
|
||||||
|
|
||||||
const intervalMs = (this.options.framesPerBuffer / this.options.sampleRate) * 1000;
|
|
||||||
setTimeout(playNextChunk, intervalMs);
|
|
||||||
};
|
|
||||||
|
|
||||||
playNextChunk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+20
-12
@@ -4,24 +4,31 @@ audio:
|
|||||||
defaultBitrate: 96
|
defaultBitrate: 96
|
||||||
jitterBufferMs: 40
|
jitterBufferMs: 40
|
||||||
device:
|
device:
|
||||||
inputDeviceId: 1
|
# Laissez null pour auto-détection du device par défaut
|
||||||
outputDeviceId: 0
|
# Ou spécifiez le nom exact via l'interface /admin
|
||||||
|
inputDeviceId: null
|
||||||
|
outputDeviceId: null
|
||||||
sampleRate: 48000
|
sampleRate: 48000
|
||||||
routing:
|
routing:
|
||||||
inputToGroup:
|
inputToGroup:
|
||||||
"1":
|
"0":
|
||||||
- technique
|
- production
|
||||||
"2":
|
"1": []
|
||||||
- technique
|
"2": []
|
||||||
"4":
|
"4":
|
||||||
- technique
|
- technique
|
||||||
"5":
|
"5":
|
||||||
- technique
|
- technique
|
||||||
groupToOutput: {}
|
groupToOutput:
|
||||||
|
technique:
|
||||||
|
- "1"
|
||||||
|
production:
|
||||||
|
- "0"
|
||||||
|
- "1"
|
||||||
gains: {}
|
gains: {}
|
||||||
channelNames:
|
channelNames:
|
||||||
inputs:
|
inputs:
|
||||||
"0": Micro Régisseur
|
"0": iphone
|
||||||
"1": Talkback FOH
|
"1": Talkback FOH
|
||||||
"2": Retour Console
|
"2": Retour Console
|
||||||
"3": Liaison Scène
|
"3": Liaison Scène
|
||||||
@@ -36,6 +43,7 @@ groups:
|
|||||||
audioBitrate: 96
|
audioBitrate: 96
|
||||||
channels: []
|
channels: []
|
||||||
- name: Technique
|
- name: Technique
|
||||||
|
audioBitrate: 96
|
||||||
channels: []
|
channels: []
|
||||||
- name: Sonorisation
|
- name: Sonorisation
|
||||||
audioBitrate: 128
|
audioBitrate: 128
|
||||||
@@ -44,8 +52,8 @@ server:
|
|||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: 3000
|
port: 3000
|
||||||
livekit:
|
livekit:
|
||||||
url: ws://localhost:7880
|
url: AUTO # AUTO = détection automatique IP réseau | ou ws://IP:7880 pour manuel
|
||||||
logging:
|
logging:
|
||||||
level: debug
|
level: info # Changez à 'debug' pour voir plus de détails
|
||||||
logLatency: true
|
logLatency: false
|
||||||
logAudioStats: true
|
logAudioStats: false
|
||||||
|
|||||||
+94
-9
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
import https from 'https';
|
||||||
|
import http from 'http';
|
||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync, existsSync } from 'fs';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
import { networkInterfaces } from 'os';
|
import { networkInterfaces } from 'os';
|
||||||
@@ -13,12 +15,18 @@ import adminRouter, { registerUser, addLog } from './api/admin.js';
|
|||||||
import configManager from './config/ConfigManager.js';
|
import configManager from './config/ConfigManager.js';
|
||||||
import audioBridgeManager from './bridge/AudioBridgeManager.js';
|
import audioBridgeManager from './bridge/AudioBridgeManager.js';
|
||||||
import AudioLevelsServer from './websocket/AudioLevelsServer.js';
|
import AudioLevelsServer from './websocket/AudioLevelsServer.js';
|
||||||
|
import { setGlobalLogLevel } from './utils/Logger.js';
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
// Chargement configuration via ConfigManager
|
// Chargement configuration via ConfigManager
|
||||||
const config = configManager.get();
|
const config = configManager.get();
|
||||||
|
|
||||||
|
// Configure le niveau de log
|
||||||
|
const logLevel = config.logging?.level?.toUpperCase() || 'INFO';
|
||||||
|
setGlobalLogLevel(logLevel);
|
||||||
|
console.log(`📊 Niveau de log: ${logLevel}`);
|
||||||
|
|
||||||
// Note: Les IDs sont maintenant générés automatiquement par le ConfigManager
|
// Note: Les IDs sont maintenant générés automatiquement par le ConfigManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +69,7 @@ const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET || 'secret';
|
|||||||
const USE_LOCAL_LIVEKIT = process.env.USE_LOCAL_LIVEKIT === 'true';
|
const USE_LOCAL_LIVEKIT = process.env.USE_LOCAL_LIVEKIT === 'true';
|
||||||
const SERVER_PORT = parseInt(process.env.PORT || config.server.port, 10);
|
const SERVER_PORT = parseInt(process.env.PORT || config.server.port, 10);
|
||||||
const SERVER_HOST = config.server.host;
|
const SERVER_HOST = config.server.host;
|
||||||
|
const ENABLE_HTTPS = process.env.ENABLE_HTTPS === 'true';
|
||||||
|
|
||||||
// Configuration URL LiveKit
|
// Configuration URL LiveKit
|
||||||
let LIVEKIT_URL = process.env.LIVEKIT_URL || config.server.livekit.url;
|
let LIVEKIT_URL = process.env.LIVEKIT_URL || config.server.livekit.url;
|
||||||
@@ -175,12 +184,36 @@ app.use((req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Middleware redirection HTTP → HTTPS (si activé)
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
// Si HTTPS activé et requête en HTTP, rediriger
|
||||||
|
if (ENABLE_HTTPS && req.protocol === 'http' && req.hostname !== 'localhost') {
|
||||||
|
const httpsUrl = `https://${req.hostname}:${SERVER_PORT}${req.url}`;
|
||||||
|
log('debug', `↪️ Redirection HTTPS: ${httpsUrl}`);
|
||||||
|
return res.redirect(301, httpsUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Middleware logging
|
// Middleware logging
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
log('debug', `${req.method} ${req.path}`);
|
log('debug', `${req.method} ${req.path}`);
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ========== Servir fichiers statiques client (production) ==========
|
||||||
|
|
||||||
|
// En production, servir le build client depuis ../client/dist
|
||||||
|
const clientDistPath = join(__dirname, '..', 'client', 'dist');
|
||||||
|
|
||||||
|
if (existsSync(clientDistPath)) {
|
||||||
|
log('info', `📦 Serveur statique activé : ${clientDistPath}`);
|
||||||
|
app.use(express.static(clientDistPath));
|
||||||
|
} else {
|
||||||
|
log('debug', '📦 Pas de build client (mode dev)');
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Routes Admin ==========
|
// ========== Routes Admin ==========
|
||||||
|
|
||||||
// Monter les routes admin sous /admin
|
// Monter les routes admin sous /admin
|
||||||
@@ -325,20 +358,28 @@ app.get('/health', (req, res) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /
|
* GET /
|
||||||
* Info serveur
|
* Info serveur OU client PWA (si build existe)
|
||||||
*/
|
*/
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
|
// Si build client existe, servir index.html
|
||||||
|
const indexPath = join(clientDistPath, 'index.html');
|
||||||
|
if (existsSync(indexPath)) {
|
||||||
|
res.sendFile(indexPath);
|
||||||
|
} else {
|
||||||
|
// Sinon, afficher info API
|
||||||
res.json({
|
res.json({
|
||||||
name: 'PTT Live Server',
|
name: 'PTT Live Server',
|
||||||
version: '0.1.0',
|
version: '0.2.0',
|
||||||
phase: 'Phase 1 - MVP',
|
mode: 'development',
|
||||||
endpoints: [
|
endpoints: [
|
||||||
'GET /config - Configuration groupes',
|
'GET /config - Configuration groupes',
|
||||||
'GET /groups - Liste des groupes',
|
'GET /groups - Liste des groupes',
|
||||||
'POST /token - Générer token client',
|
'POST /token - Générer token client',
|
||||||
'GET /health - Health check'
|
'GET /health - Health check',
|
||||||
|
'GET /admin - Interface administration'
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ========== Démarrage ==========
|
// ========== Démarrage ==========
|
||||||
@@ -366,23 +407,67 @@ async function start() {
|
|||||||
log('warn', '⚠️ Pour utiliser LiveKit local, définir USE_LOCAL_LIVEKIT=true dans .env');
|
log('warn', '⚠️ Pour utiliser LiveKit local, définir USE_LOCAL_LIVEKIT=true dans .env');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Démarrer API REST
|
// 2. Démarrer API REST (HTTP ou HTTPS selon config)
|
||||||
const server = app.listen(SERVER_PORT, SERVER_HOST, () => {
|
let server;
|
||||||
|
|
||||||
|
if (ENABLE_HTTPS) {
|
||||||
|
// Charger certificats SSL (mêmes que Vite)
|
||||||
|
const certPath = join(__dirname, '..', 'client');
|
||||||
|
const httpsOptions = {
|
||||||
|
key: readFileSync(join(certPath, 'localhost+3-key.pem')),
|
||||||
|
cert: readFileSync(join(certPath, 'localhost+3.pem'))
|
||||||
|
};
|
||||||
|
|
||||||
|
server = https.createServer(httpsOptions, app);
|
||||||
|
server.listen(SERVER_PORT, SERVER_HOST, () => {
|
||||||
|
log('info', `✓ API REST démarrée sur https://${SERVER_HOST}:${SERVER_PORT}`);
|
||||||
|
log('info', '');
|
||||||
|
log('info', 'Serveur prêt !');
|
||||||
|
log('info', `Groupes configurés: ${config.groups.map(g => g.name).join(', ')}`);
|
||||||
|
log('info', '');
|
||||||
|
|
||||||
|
// Afficher URLs d'accès
|
||||||
|
if (networkIP && networkIP !== 'localhost') {
|
||||||
|
const prodUrl = `https://${networkIP}:${SERVER_PORT}`;
|
||||||
|
log('info', '📱 Accès réseau WiFi :');
|
||||||
|
log('info', '');
|
||||||
|
log('info', ` Prod : ${prodUrl}`);
|
||||||
|
log('info', '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
server = http.createServer(app);
|
||||||
|
server.listen(SERVER_PORT, SERVER_HOST, () => {
|
||||||
log('info', `✓ API REST démarrée sur http://${SERVER_HOST}:${SERVER_PORT}`);
|
log('info', `✓ API REST démarrée sur http://${SERVER_HOST}:${SERVER_PORT}`);
|
||||||
log('info', '');
|
log('info', '');
|
||||||
log('info', 'Serveur prêt !');
|
log('info', 'Serveur prêt !');
|
||||||
log('info', `Groupes configurés: ${config.groups.map(g => g.name).join(', ')}`);
|
log('info', `Groupes configurés: ${config.groups.map(g => g.name).join(', ')}`);
|
||||||
|
log('info', '');
|
||||||
|
|
||||||
|
// Afficher URLs d'accès
|
||||||
|
if (networkIP && networkIP !== 'localhost') {
|
||||||
|
const clientUrl = `https://${networkIP}:5173`; // Dev mode
|
||||||
|
const prodUrl = `http://${networkIP}:${SERVER_PORT}`; // Prod mode HTTP
|
||||||
|
|
||||||
|
log('info', '📱 Accès réseau WiFi :');
|
||||||
|
log('info', '');
|
||||||
|
log('info', ` Dev : ${clientUrl}`);
|
||||||
|
log('info', ` Prod : ${prodUrl}`);
|
||||||
|
log('info', '');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 2.5 Démarrer WebSocket Audio Levels (même port que l'API)
|
// 2.5 Démarrer WebSocket Audio Levels (même port que l'API)
|
||||||
const audioLevelsServer = new AudioLevelsServer({ server });
|
const audioLevelsServer = new AudioLevelsServer({ server });
|
||||||
audioLevelsServer.start();
|
audioLevelsServer.start();
|
||||||
log('info', `✓ WebSocket Audio Levels démarré sur ws://${SERVER_HOST}:${SERVER_PORT}`);
|
const wsProtocol = ENABLE_HTTPS ? 'wss' : 'ws';
|
||||||
|
log('info', `✓ WebSocket Audio Levels démarré sur ${wsProtocol}://${SERVER_HOST}:${SERVER_PORT}`);
|
||||||
|
|
||||||
// 3. Démarrer Audio Bridge Manager (Phase 2.5)
|
// 3. Démarrer Audio Bridge Manager (Phase 2.5)
|
||||||
log('info', '');
|
log('info', '');
|
||||||
log('info', '🎵 Démarrage Audio Bridge Manager...');
|
log('info', '🎵 Démarrage Audio Bridge Manager...');
|
||||||
await audioBridgeManager.start();
|
await audioBridgeManager.start({ liveKitUrl: LIVEKIT_URL });
|
||||||
log('info', '✓ Audio Bridge Manager prêt (mode placeholder)');
|
log('info', '✓ Audio Bridge Manager prêt (mode placeholder)');
|
||||||
|
|
||||||
// Gérer erreur port déjà utilisé
|
// Gérer erreur port déjà utilisé
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"livekit-server-sdk": "^2.6.0",
|
"livekit-server-sdk": "^2.6.0",
|
||||||
"opusscript": "^0.1.1",
|
"opusscript": "^0.1.1",
|
||||||
|
"qrcode-terminal": "^0.12.0",
|
||||||
"ws": "^8.17.0",
|
"ws": "^8.17.0",
|
||||||
"yaml": "^2.4.2"
|
"yaml": "^2.4.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Logger.js
|
||||||
|
* Système de logging centralisé avec niveaux configurables
|
||||||
|
*/
|
||||||
|
|
||||||
|
const LOG_LEVELS = {
|
||||||
|
ERROR: 0,
|
||||||
|
WARN: 1,
|
||||||
|
INFO: 2,
|
||||||
|
DEBUG: 3,
|
||||||
|
TRACE: 4
|
||||||
|
};
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
constructor(category = 'default', level = 'INFO') {
|
||||||
|
this.category = category;
|
||||||
|
this.level = LOG_LEVELS[level] ?? LOG_LEVELS.INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
setLevel(level) {
|
||||||
|
this.level = LOG_LEVELS[level] ?? LOG_LEVELS.INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
error(message, ...args) {
|
||||||
|
if (this.level >= LOG_LEVELS.ERROR) {
|
||||||
|
console.error(`[${this.category}] ❌`, message, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
warn(message, ...args) {
|
||||||
|
if (this.level >= LOG_LEVELS.WARN) {
|
||||||
|
console.warn(`[${this.category}] ⚠️ `, message, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info(message, ...args) {
|
||||||
|
if (this.level >= LOG_LEVELS.INFO) {
|
||||||
|
console.log(`[${this.category}] ℹ️ `, message, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
success(message, ...args) {
|
||||||
|
if (this.level >= LOG_LEVELS.INFO) {
|
||||||
|
console.log(`[${this.category}] ✓`, message, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(message, ...args) {
|
||||||
|
if (this.level >= LOG_LEVELS.DEBUG) {
|
||||||
|
console.log(`[${this.category}] 🔍`, message, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trace(message, ...args) {
|
||||||
|
if (this.level >= LOG_LEVELS.TRACE) {
|
||||||
|
console.log(`[${this.category}] 🔬`, message, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration globale depuis env ou config
|
||||||
|
const globalLevel = process.env.LOG_LEVEL || 'INFO';
|
||||||
|
|
||||||
|
// Loggers par catégorie
|
||||||
|
const loggers = new Map();
|
||||||
|
|
||||||
|
export function getLogger(category) {
|
||||||
|
if (!loggers.has(category)) {
|
||||||
|
loggers.set(category, new Logger(category, globalLevel));
|
||||||
|
}
|
||||||
|
return loggers.get(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setGlobalLogLevel(level) {
|
||||||
|
loggers.forEach(logger => logger.setLevel(level));
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { getLogger, setGlobalLogLevel };
|
||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# PTT Live - Affichage QR Code
|
||||||
|
# Génère et affiche le QR code pour connexion smartphone
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Détection IP réseau
|
||||||
|
get_network_ip() {
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# macOS
|
||||||
|
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -n 1
|
||||||
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
# Linux
|
||||||
|
hostname -I | awk '{print $1}'
|
||||||
|
else
|
||||||
|
echo "localhost"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
NETWORK_IP=$(get_network_ip)
|
||||||
|
|
||||||
|
# Déterminer l'URL selon mode dev ou prod
|
||||||
|
if [ -d "client/dist" ] && [ "$1" != "--dev" ]; then
|
||||||
|
# Mode production
|
||||||
|
URL="http://${NETWORK_IP}:3000"
|
||||||
|
MODE="production"
|
||||||
|
else
|
||||||
|
# Mode dev
|
||||||
|
URL="https://${NETWORK_IP}:5173"
|
||||||
|
MODE="dev"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}=================================="
|
||||||
|
echo "📱 QR Code PTT Live ($MODE)"
|
||||||
|
echo "==================================${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Générer le QR code avec le package installé dans server/
|
||||||
|
(cd server && node -e "
|
||||||
|
const qrcode = require('qrcode-terminal');
|
||||||
|
qrcode.generate('$URL', { small: true });
|
||||||
|
")
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}🔗 URL : $URL${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "📱 Scannez ce QR code depuis votre smartphone"
|
||||||
|
echo " pour vous connecter instantanément"
|
||||||
|
echo ""
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# PTT Live - Script de démarrage unifié
|
||||||
|
# Lance le serveur et le client en mode production
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Couleurs
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Détection IP réseau
|
||||||
|
get_network_ip() {
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# macOS
|
||||||
|
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}' | head -n 1
|
||||||
|
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
# Linux
|
||||||
|
hostname -I | awk '{print $1}'
|
||||||
|
else
|
||||||
|
echo "localhost"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
NETWORK_IP=$(get_network_ip)
|
||||||
|
|
||||||
|
echo -e "${BLUE}=================================="
|
||||||
|
echo "🚀 PTT Live - Démarrage"
|
||||||
|
echo "==================================${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -e "${GREEN}📡 IP réseau détectée : ${NETWORK_IP}${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Vérifier que les dépendances sont installées
|
||||||
|
if [ ! -d "server/node_modules" ]; then
|
||||||
|
echo -e "${RED}❌ Dépendances serveur manquantes${NC}"
|
||||||
|
echo " Exécutez d'abord : ./install/macos.sh (ou linux.sh)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "client/node_modules" ]; then
|
||||||
|
echo -e "${RED}❌ Dépendances client manquantes${NC}"
|
||||||
|
echo " Exécutez d'abord : ./install/macos.sh (ou linux.sh)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Créer fichier PID pour cleanup
|
||||||
|
PID_FILE="/tmp/ptt-live.pid"
|
||||||
|
|
||||||
|
# Fonction cleanup
|
||||||
|
cleanup() {
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}⏹ Arrêt PTT Live...${NC}"
|
||||||
|
|
||||||
|
if [ -f "$PID_FILE" ]; then
|
||||||
|
while read -r pid; do
|
||||||
|
if ps -p "$pid" > /dev/null 2>&1; then
|
||||||
|
kill "$pid" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
done < "$PID_FILE"
|
||||||
|
rm -f "$PID_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ Arrêté${NC}"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup SIGINT SIGTERM EXIT
|
||||||
|
|
||||||
|
# Afficher le QR code AVANT de lancer le serveur
|
||||||
|
if [ "$1" == "--dev" ]; then
|
||||||
|
./show-qr.sh --dev
|
||||||
|
else
|
||||||
|
./show-qr.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Démarrer le serveur (silencieux, logs dans fichier)
|
||||||
|
echo -e "${BLUE}🔧 Démarrage serveur...${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
cd server
|
||||||
|
|
||||||
|
# En mode production (pas --dev), activer HTTPS
|
||||||
|
if [ "$1" != "--dev" ]; then
|
||||||
|
export ENABLE_HTTPS=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Lancer le serveur en background silencieux
|
||||||
|
npm start > ../server.log 2>&1 &
|
||||||
|
SERVER_PID=$!
|
||||||
|
echo "$SERVER_PID" > "$PID_FILE"
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Attendre que le serveur soit prêt
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}⏳ Attente démarrage serveur...${NC}"
|
||||||
|
for i in {1..30}; do
|
||||||
|
if curl -sf http://localhost:3000/health > /dev/null 2>&1; then
|
||||||
|
echo -e "${GREEN}✓ Serveur prêt${NC}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $i -eq 30 ]; then
|
||||||
|
echo -e "${RED}❌ Timeout : le serveur n'a pas démarré${NC}"
|
||||||
|
echo " Consultez server.log pour plus de détails"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Build client si pas déjà fait ou mode dev
|
||||||
|
if [ "$1" == "--dev" ]; then
|
||||||
|
echo -e "${BLUE}🎨 Démarrage client (dev)...${NC}"
|
||||||
|
cd client
|
||||||
|
npm run dev &
|
||||||
|
CLIENT_PID=$!
|
||||||
|
echo "$CLIENT_PID" >> "$PID_FILE"
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ Client dev démarré${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}=================================="
|
||||||
|
echo "✅ PTT Live démarré (mode dev)"
|
||||||
|
echo "==================================${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}🌐 ACCÈS CLIENT (HTTPS) :${NC}"
|
||||||
|
echo -e "${GREEN} 👉 Local : https://localhost:5173${NC}"
|
||||||
|
echo -e "${GREEN} 👉 Réseau : https://${NETWORK_IP}:5173${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}⚠️ Acceptez le certificat auto-signé dans votre navigateur${NC}"
|
||||||
|
echo -e "${YELLOW} (Cliquez sur 'Avancé' puis 'Continuer')${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "📊 API serveur (HTTP uniquement) : http://localhost:3000"
|
||||||
|
echo "🎛️ Interface admin : https://localhost:5173/admin"
|
||||||
|
echo ""
|
||||||
|
echo "📝 Logs serveur : tail -f server.log"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}Appuyez sur Ctrl+C pour arrêter${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Attendre indéfiniment
|
||||||
|
wait
|
||||||
|
|
||||||
|
else
|
||||||
|
# Mode production : build et serve
|
||||||
|
echo -e "${BLUE}🎨 Build client production...${NC}"
|
||||||
|
cd client
|
||||||
|
|
||||||
|
if [ ! -d "dist" ] || [ "$1" == "--rebuild" ]; then
|
||||||
|
npm run build
|
||||||
|
echo -e "${GREEN}✓ Client buildé${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠️ Build existant utilisé (--rebuild pour forcer)${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}=================================="
|
||||||
|
echo "✅ PTT Live démarré (production)"
|
||||||
|
echo "==================================${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}🌐 ACCÈS CLIENT (HTTPS) :${NC}"
|
||||||
|
echo -e "${GREEN} 👉 Local : https://localhost:3000${NC}"
|
||||||
|
echo -e "${GREEN} 👉 Réseau : https://${NETWORK_IP}:3000${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}⚠️ Acceptez le certificat auto-signé dans votre navigateur${NC}"
|
||||||
|
echo -e "${YELLOW} (Cliquez sur 'Avancé' puis 'Continuer')${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "🎛️ Interface admin : https://localhost:3000/admin"
|
||||||
|
echo ""
|
||||||
|
echo "📝 Logs serveur : tail -f server.log"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}Appuyez sur Ctrl+C pour arrêter${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Attendre indéfiniment
|
||||||
|
wait
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user