From b35f80fc7ca16cc9abc9149c9e66cd93452126f4 Mon Sep 17 00:00:00 2001 From: Benoit Date: Wed, 27 May 2026 13:14:14 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20configuration=20portable=20-=20URLs=20e?= =?UTF-8?q?t=20devices=20auto-d=C3=A9tect=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changements pour rendre l'installation portable : 1. Config réseau auto-détectée - config.yaml : LIVEKIT_URL = AUTO (au lieu de IP hardcodée) - Devices audio : null par défaut (auto-détection) 2. Client .env dynamique - Ajout client/.env.example avec documentation - VITE_API_URL configurable pour dev/prod 3. Vite config dynamique - Utilisation de loadEnv() pour variables d'environnement - Proxies configurables via VITE_API_URL et VITE_LIVEKIT_URL 4. Install script amélioré - Détection automatique IP réseau au moment install - Génération .env client avec IP détectée - Messages informatifs avec IP du serveur 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- client/.env.example | 16 +++++++++--- client/vite.config.js | 17 ++++++++++--- install/macos.sh | 52 ++++++++++++++++++++++++++++++++++----- server/config/config.yaml | 8 +++--- 4 files changed, 76 insertions(+), 17 deletions(-) diff --git a/client/.env.example b/client/.env.example index 45f7fed..71f68fb 100644 --- a/client/.env.example +++ b/client/.env.example @@ -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 -# Pour production, pointer vers le serveur -# VITE_API_URL=https://your-server.com +# URL LiveKit WebSocket (optionnel, normalement auto-détectée) +# Ne définir que si vous voulez forcer une URL spécifique +# VITE_LIVEKIT_URL=ws://192.168.1.100:7880 diff --git a/client/vite.config.js b/client/vite.config.js index 903a966..83b9d62 100644 --- a/client/vite.config.js +++ b/client/vite.config.js @@ -1,9 +1,17 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; import { VitePWA } from 'vite-plugin-pwa'; 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: [ react(), VitePWA({ @@ -68,12 +76,12 @@ export default defineConfig({ }, proxy: { '/api': { - target: 'http://192.168.0.146:3000', + target: apiUrl.startsWith('/') ? 'http://localhost:3000' : apiUrl, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, '') }, '/livekit': { - target: 'ws://192.168.0.146:7880', + target: livekitUrl, ws: true, changeOrigin: true, rewrite: (path) => path.replace(/^\/livekit/, '') @@ -84,4 +92,5 @@ export default defineConfig({ outDir: 'dist', sourcemap: true } + }; }); diff --git a/install/macos.sh b/install/macos.sh index ab10846..614d789 100755 --- a/install/macos.sh +++ b/install/macos.sh @@ -96,14 +96,30 @@ echo "" cd .. -# Créer fichier .env -echo "🔑 Génération configuration LiveKit..." +# Détecter l'IP réseau locale +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 +# Configuration PTT Live Server +# Généré automatiquement par install/macos.sh + USE_LOCAL_LIVEKIT=true # 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 LIVEKIT_API_KEY=devkey LIVEKIT_API_SECRET=secret @@ -113,7 +129,23 @@ PORT=3000 NODE_ENV=development 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 "" # Message final @@ -128,7 +160,15 @@ echo "" echo " 2. Démarrer le client (nouveau terminal) :" echo " cd client && npm run dev" echo "" -echo " 3. Ouvrir https://localhost:5173 dans votre navigateur" +echo " 3. Accéder à l'application :" +echo " • Développement local : https://localhost:5173" +echo " • Depuis autre appareil (WiFi) : https://${NETWORK_IP}:5173" echo "" -echo "📖 Documentation : README.md" +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 "" diff --git a/server/config/config.yaml b/server/config/config.yaml index 05a651f..30e1a16 100644 --- a/server/config/config.yaml +++ b/server/config/config.yaml @@ -4,8 +4,10 @@ audio: defaultBitrate: 96 jitterBufferMs: 40 device: - inputDeviceId: Microphone MacBook Pro - outputDeviceId: Haut-parleurs MacBook Pro + # Laissez null pour auto-détection du device par défaut + # Ou spécifiez le nom exact via l'interface /admin + inputDeviceId: null + outputDeviceId: null sampleRate: 48000 routing: inputToGroup: @@ -50,7 +52,7 @@ server: host: 0.0.0.0 port: 3000 livekit: - url: ws://192.168.0.146:7880 + url: AUTO # AUTO = détection automatique IP réseau | ou ws://IP:7880 pour manuel logging: level: info # Changez à 'debug' pour voir plus de détails logLatency: false